]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/asn-len.h
Security-54.1.7.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-lib / inc / asn-len.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 * asn_len.h
21 *
22 * Warning: many of these routines are MACROs for performance reasons
23 * - be carful where you use them. Don't use more than one per
24 * assignment statement -
25 * (eg itemLen += BEncEoc (b) + BEncFoo (b) ..; this
26 * will break the code)
27 *
28 * MS 92
29 * Copyright (C) 1992 Michael Sample and the University of British Columbia
30 *
31 * This library is free software; you can redistribute it and/or
32 * modify it provided that this copyright/license information is retained
33 * in original form.
34 *
35 * If you modify this file, you must clearly indicate your changes.
36 *
37 * This source code is distributed in the hope that it will be
38 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
39 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
40 *
41 * $Header: /cvs/root/Security/SecuritySNACCRuntime/c-lib/inc/Attic/asn-len.h,v 1.1.1.1 2001/05/18 23:14:08 mb Exp $
42 * $Log: asn-len.h,v $
43 * Revision 1.1.1.1 2001/05/18 23:14:08 mb
44 * Move from private repository to open source repository
45 *
46 * Revision 1.2 2001/05/05 00:59:22 rmurphy
47 * Adding darwin license headers
48 *
49 * Revision 1.1.1.1 1999/03/16 18:06:20 aram
50 * Originals from SMIME Free Library.
51 *
52 * Revision 1.2 1995/07/27 08:42:40 rj
53 * cpp macro TBL changed to TTBL since some type table code uses TBL as a type name.
54 *
55 * changed `_' to `-' in file names.
56 *
57 * Revision 1.1 1994/08/28 09:21:29 rj
58 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
59 *
60 */
61
62 #ifndef _asn_len_h_
63 #define _asn_len_h_
64
65 typedef unsigned long int AsnLen;
66
67 /* max unsigned value - used for internal rep of indef len */
68 #define INDEFINITE_LEN ~0L
69
70
71 #ifdef USE_INDEF_LEN
72
73 #define BEncEocIfNec( b) BEncEoc (b)
74
75 /*
76 * include len for EOC (2 must be first due to BEncIndefLen
77 * - ack! ugly macros!)
78 */
79 #define BEncConsLen( b, len) 2 + BEncIndefLen(b)
80
81
82 #else /* use definite length - faster?/smaller encodings */
83
84
85 /* do nothing since only using definite lens */
86 #define BEncEocIfNec( b)
87
88 #define BEncConsLen( b, len) BEncDefLen(b, len)
89
90
91 #endif
92
93
94
95 /*
96 * writes indefinite length byte to buffer. 'returns' encoded len (1)
97 */
98 #define BEncIndefLen( b)\
99 1;\
100 BufPutByteRvs (b, 0x80);
101
102
103 #define BEncEoc( b)\
104 2;\
105 BufPutByteRvs (b, 0);\
106 BufPutByteRvs (b, 0);
107
108
109 /*
110 * use if you know the encoded length will be 0 >= len <= 127
111 * Eg for booleans, nulls, any resonable integers and reals
112 *
113 * NOTE: this particular Encode Routine does NOT return the length
114 * encoded (1).
115 */
116 #define BEncDefLenTo127( b, len)\
117 BufPutByteRvs (b, (unsigned char) len)
118
119 #define BDEC_2ND_EOC_OCTET( b, bytesDecoded, env)\
120 {\
121 if ((BufGetByte (b) != 0) || BufReadError (b)) {\
122 Asn1Error ("ERROR - second octet of EOC not zero\n");\
123 longjmp (env, -28);}\
124 (*bytesDecoded)++;\
125 }
126
127
128 AsnLen BEncDefLen PROTO ((BUF_TYPE b, AsnLen len));
129
130 AsnLen BDecLen PROTO ((BUF_TYPE b, AsnLen *bytesDecoded, ENV_TYPE env));
131
132 /*
133 AsnLen BEncEoc PROTO ((BUF_TYPE b));
134 */
135 void BDecEoc PROTO ((BUF_TYPE b, AsnLen *bytesDecoded, ENV_TYPE env));
136
137 #if TTBL
138 int PeekEoc PROTO ((BUF_TYPE b));
139 #endif
140
141 #endif /* conditional include */