]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/gen-buf.h
Security-54.1.9.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-lib / inc / gen-buf.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 * gen_buf.h - flexible (runtime configurable) buffer mgmt stuff.
21 *
22 * These are somewhat slower than the direct approach used in
23 * the compiled stuff. Since tables are around 4x slower,
24 * the flexibility of the GenBufs can be justified. This
25 * also allows one enc/dec library to support all buffer types.
26 *
27 * MS 93
28 *
29 * Copyright (C) 1993 Michael Sample
30 * and the University of British Columbia
31 *
32 * This library is free software; you can redistribute it and/or
33 * modify it provided that this copyright/license information is retained
34 * in original form.
35 *
36 * If you modify this file, you must clearly indicate your changes.
37 *
38 * This source code is distributed in the hope that it will be
39 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
40 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
41 */
42
43 #if USE_GEN_BUF
44
45 #ifndef _gen_buf_h_
46 #define _gen_buf_h_
47
48 /*
49 * These are the standard buffer routines that the lib
50 * routines need. Note that the Peek routines have be
51 * added to the standard list - they are necessary
52 * to nicely support the table oriented decoder.
53 * The "void *b" param's real type will be the buffer
54 * type that is used inside the GenBuf
55 * (ie SBuf * or ExpBuf ** have been defined).
56 *
57 * Note that macros can not be used for these standard functions
58 * because the GenBuf keeps a pointer to these routines.
59 * Thus the exp_buf.[ch] and sbuf.[ch] files are somewhat
60 * differnt than those in snacc/c_lib and snacc/c_include
61 *
62 */
63
64 typedef unsigned char (*BufGetByteFcn) PROTO ((void *b));
65 typedef unsigned char *(*BufGetSegFcn) PROTO ((void *b, unsigned long int *lenPtr));
66 typedef long int (*BufCopyFcn) PROTO ((char *dst, void *b, unsigned long int len));
67 typedef void (*BufSkipFcn) PROTO ((void *b, unsigned long int len));
68 typedef unsigned char (*BufPeekByteFcn) PROTO ((void *b));
69 typedef unsigned char *(*BufPeekSegFcn) PROTO ((void *b, unsigned long int lenPtr));
70 typedef long int (*BufPeekCopyFcn) PROTO ((char *dst, void *b, unsigned long int len));
71 typedef void (*BufPutByteRvsFcn) PROTO ((void *b, unsigned char byte));
72 typedef void (*BufPutSegRvsFcn) PROTO ((void *b, char *data, unsigned long int len));
73 typedef int (*BufReadErrorFcn) PROTO ((void *b));
74 typedef int (*BufWriteErrorFcn) PROTO ((void *b));
75
76
77 typedef struct GenBuf
78 {
79 BufGetByteFcn getByte;
80 BufGetSegFcn getSeg;
81 BufCopyFcn copy;
82 BufSkipFcn skip;
83 BufPeekByteFcn peekByte;
84 BufPeekSegFcn peekSeg;
85 BufPeekCopyFcn peekCopy;
86 BufPutByteRvsFcn putByteRvs;
87 BufPutSegRvsFcn putSegRvs;
88 BufReadErrorFcn readError;
89 BufWriteErrorFcn writeError;
90 void *bufInfo;
91 void *spare; /* hack to save space for ExpBuf ** type */
92 } GenBuf;
93
94
95 #define GenBufGetByte( b) ((b)->getByte (b->bufInfo))
96 #define GenBufGetSeg( b, lenPtr) ((b)->getSeg (b->bufInfo, lenPtr))
97 #define GenBufCopy( dst, b, len) ((b)->copy (dst, b->bufInfo, len))
98 #define GenBufSkip( b, len) ((b)->skip (b->bufInfo,len))
99 #define GenBufPeekByte( b) ((b)->peekByte (b->bufInfo))
100 #define GenBufPeekSeg( b, lenPtr) ((b)->peekSeg (b->bufInfo, lenPtr))
101 #define GenBufPeekCopy( dst, b, len) ((b)->peekCopy (dst, b->bufInfo, len))
102 #define GenBufPutByteRvs( b, byte) ((b)->putByteRvs (b->bufInfo, byte))
103 #define GenBufPutSegRvs( b, data, len) ((b)->putSegRvs (b->bufInfo, data, len))
104 #define GenBufReadError( b) ((b)->readError (b->bufInfo))
105 #define GenBufWriteError( b) ((b)->writeError (b->bufInfo))
106
107
108 #endif /* _gen_buf_h_ conditional include */
109
110 #endif /* USE_GEN_BUF */