]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/asn-len.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
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)
29 * Copyright (C) 1992 Michael Sample and the University of British Columbia
31 * This library is free software; you can redistribute it and/or
32 * modify it provided that this copyright/license information is retained
35 * If you modify this file, you must clearly indicate your changes.
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.
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 $
43 * Revision 1.1.1.1 2001/05/18 23:14:08 mb
44 * Move from private repository to open source repository
46 * Revision 1.2 2001/05/05 00:59:22 rmurphy
47 * Adding darwin license headers
49 * Revision 1.1.1.1 1999/03/16 18:06:20 aram
50 * Originals from SMIME Free Library.
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.
55 * changed `_' to `-' in file names.
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.
65 typedef unsigned long int AsnLen
;
67 /* max unsigned value - used for internal rep of indef len */
68 #define INDEFINITE_LEN ~0L
73 #define BEncEocIfNec( b) BEncEoc (b)
76 * include len for EOC (2 must be first due to BEncIndefLen
77 * - ack! ugly macros!)
79 #define BEncConsLen( b, len) 2 + BEncIndefLen(b)
82 #else /* use definite length - faster?/smaller encodings */
85 /* do nothing since only using definite lens */
86 #define BEncEocIfNec( b)
88 #define BEncConsLen( b, len) BEncDefLen(b, len)
96 * writes indefinite length byte to buffer. 'returns' encoded len (1)
98 #define BEncIndefLen( b)\
100 BufPutByteRvs (b, 0x80);
105 BufPutByteRvs (b, 0);\
106 BufPutByteRvs (b, 0);
110 * use if you know the encoded length will be 0 >= len <= 127
111 * Eg for booleans, nulls, any resonable integers and reals
113 * NOTE: this particular Encode Routine does NOT return the length
116 #define BEncDefLenTo127( b, len)\
117 BufPutByteRvs (b, (unsigned char) len)
119 #define BDEC_2ND_EOC_OCTET( b, bytesDecoded, env)\
121 if ((BufGetByte (b) != 0) || BufReadError (b)) {\
122 Asn1Error ("ERROR - second octet of EOC not zero\n");\
123 longjmp (env, -28);}\
128 AsnLen BEncDefLen
PROTO ((BUF_TYPE b
, AsnLen len
));
130 AsnLen BDecLen
PROTO ((BUF_TYPE b
, AsnLen
*bytesDecoded
, ENV_TYPE env
));
133 AsnLen BEncEoc PROTO ((BUF_TYPE b));
135 void BDecEoc
PROTO ((BUF_TYPE b
, AsnLen
*bytesDecoded
, ENV_TYPE env
));
138 int PeekEoc
PROTO ((BUF_TYPE b
));
141 #endif /* conditional include */