⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icinputstream.h

📁 IBE是一种非对称密码技术
💻 H
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "stringutil.h"

#ifndef _ICINPUTSTREAM_H_
#define _ICINPUTSTREAM_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct icInputStreamDef *icInputStreamPtr;

/* Place count bytes from in into buf. If there are fewer than count
 * bytes in the stream, place all the bytes in the stream into the
 * buffer. Set bytesRead to the number of bytes read.
 * <p>If bytesRead < count, we reached the end of stream.
 * <p>This function will move the stream along by the number of bytes
 * read.
 */
typedef int (*ICRead) (
   icInputStreamPtr in, unsigned char *buf, int count, int *bytesRead,
   VoltLibCtx *libCtx);

/* Place count bytes from in into buf. If there are fewer than count
 * bytes in the stream, place all the bytes in the stream into the
 * buffer. Set bytesRead to the number of bytes read.
 * <p>If bytesRead < count, we reached the end of stream.
 * <p>This function will NOT move the stream along.
 */
typedef int (*ICPeek) (
   icInputStreamPtr in, unsigned char *buf, int count, int *bytesRead,
   VoltLibCtx *libCtx);

/* Move the stream along count bytes. If there are fewer than count
 * bytes in the stream, move to the end of the stream. Set bytesRead to
 * the number of bytes we moved ahead.
 * <p>If bytesRead < count, we reached the end of stream.
 * <p>This function is equivalent to the read function, except it does
 * not copy the stream bytes into a caller-supplied buffer.
 */
typedef int (*ICSkip) (
   icInputStreamPtr in, int count, int *bytesRead, VoltLibCtx *libCtx);

/* Free all memory associated with the stream.
 */
typedef void (*ICFree) (
   icInputStreamPtr in, VoltLibCtx *libCtx);

typedef struct icInputStreamDef
{
  ICRead           read;
  ICPeek           peek;
  ICSkip           skip;
  ICFree           free;
	Pointer          localStream;
} icInputStream;

typedef int (*ICInputStreamImpl) (
   unsigned char *str, int len, int copyFlag, icInputStream *in,
   VoltLibCtx *libCtx);
   
/* Create a new stream that deals with the kind of streams specified in
 * the StreamImpl.
 * <p>This function sets the contents of the stream to the data in str.
 * <p>The copyFlag is either VOLT_IC_STREAM_COPY_DATA or
 * VOLT_IC_STREAM_COPY_REFERENCE.
 * <p>If copying DATA, the implementation must make its own copy of the
 * input data. If the caller passes in REFERENCE, the implementation
 * can simply copy a reference to the data. However, an implementation
 * can decide to copy the data itself. That is, after calling the
 * create with REFERENCE, there is no guarantee that any manipulations
 * to the buffer outside the stream will be reflected inside the stream.
 */
int icInputStreamCreate (
   ICInputStreamImpl StreamImpl,
   unsigned char *str,
   int len,
   int copyFlag,
   icInputStream **in,
   VoltLibCtx *libCtx
   );

#define VOLT_IC_STREAM_COPY_REFERENCE  0
#define VOLT_IC_STREAM_COPY_DATA       1

/* This is currently the only input stream impl supported.
 * It deals with streams that are byte arrays in memory.
 */
int ICInputStreamImplString (
   unsigned char *str, int len, int copyFlag, icInputStream *in,
   VoltLibCtx *libCtx);

/* Reads count or maximum number of bytes from input stream, and stored
 * read bytes into buf.
 * Pointer is advanced to the end of the read sector.
 * If the return is 0 and bytesRead < count, we reached the end.
 *
 * @param in - input stream;
 * @param buf - pointer to the storage buffer for the read bytes;
 * @param count - number of bytes to be read;
 * @param bytesRead - address where actual number of bytes read will be
 * returned.
 * @param libCtx - memory context;
 * @return int - zero if success, or nonzero error code
 */
int icInputStreamRead (
   icInputStream *in,
   unsigned char *buf,
   int count,
   int *bytesRead,
   VoltLibCtx *libCtx
   );

/* Reads count or maximum number of bytes from input stream, and stored
 * read bytes into buf;
 * Pointer is NOT being advanced to the end of the read sector.
 * If the return is 0 and bytesRead < count, we reached the end.
 *
 * @param in - input stream;
 * @param buf - pointer to the storage buffer for the read bytes;
 * @param count - number of bytes to be read;
 * @param bytesRead - address where actual number of bytes read will be
 * returned.
 * @param libCtx - memory context;
 * @return int - 0 for success or nonzero error code.
 */
int icInputStreamPeek (
   icInputStream *in,
   unsigned char *buf,
   int count,
   int *bytesRead,
   VoltLibCtx *libCtx
   );

/* This moves the stream position to the first character in the stream
 * that is not whitespace.
 * <p>Upon return, the bytesRead variable will have been set to how
 * many bytes of whitespace were read and skipped.
 * <p>If this function reaches the end of the stream finding only
 * whitespace, it will still return 0. In other words, there's no way
 * to know, using this routine, whether there is non-whitespace data in
 * the stream, the caller must simply call Peek or Read.
 */
int icInputStreamSkipWhitespace (
   icInputStream *in,
   int *bytesRead,
   VoltLibCtx *libCtx
   );

/* Frees input stream;
	@param in - input stream;
	@param libCtx - memory context;
 */
void icInputStreamFree (
   icInputStream **in,
   VoltLibCtx *libCtx
   );

/* Structure for the localStream of a StringInputStream.
   str - pinter to the stream itself
   position - position of pointer in the stream
   length - length of the stream 
   freeStr - indicates whether the str pointer should be freed or not,
   the str pointer was originally either a reference copy or a data
   copy.
 */
typedef struct
{
  unsigned char   *str;
  int              position;
  int              length;
  int              copyFlag;
} icStringInputStreamData;

int icStringInputStreamRead (
   icInputStreamPtr in,
   unsigned char *buf,
   int count,
   int *bytesRead,
   VoltLibCtx *libCtx
   );

void icStringInputStreamFree (
   icInputStreamPtr in,
   VoltLibCtx *libCtx
   );

#ifdef __cplusplus
}
#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -