]> 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 // file: .../c++-lib/inc/asn-len.h - handle ASN.1 length encoding/decoding etc.
20 //
21 // MS 92/06/18
22 // Copyright (C) 1992 Michael Sample and the University of British Columbia
23 //
24 // This library is free software; you can redistribute it and/or
25 // modify it provided that this copyright/license information is retained
26 // in original form.
27 //
28 // If you modify this file, you must clearly indicate your changes.
29 //
30 // This source code is distributed in the hope that it will be
31 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
32 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33 //
34 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/inc/Attic/asn-len.h,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
35 // $Log: asn-len.h,v $
36 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
37 // Move from private repository to open source repository
38 //
39 // Revision 1.3 2001/05/05 00:59:18 rmurphy
40 // Adding darwin license headers
41 //
42 // Revision 1.2 2000/06/15 18:48:23 dmitch
43 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
44 //
45 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
46 // Base Fortissimo Tree
47 //
48 // Revision 1.1 1999/02/25 05:21:43 mb
49 // Added snacc c++ library
50 //
51 // Revision 1.6 1997/02/16 10:07:43 rj
52 // make the unsigned value unsigned :-)
53 //
54 // Revision 1.5 1995/07/25 20:19:01 rj
55 // changed `_' to `-' in file names.
56 //
57 // Revision 1.4 1994/10/08 04:18:04 rj
58 // code for meta structures added (provides information about the generated code itself).
59 //
60 // code for Tcl interface added (makes use of the above mentioned meta code).
61 //
62 // virtual inline functions (the destructor, the Clone() function, BEnc(), BDec() and Print()) moved from inc/*.h to src/*.C because g++ turns every one of them into a static non-inline function in every file where the .h file gets included.
63 //
64 // made Print() const (and some other, mainly comparison functions).
65 //
66 // several `unsigned long int' turned into `size_t'.
67 //
68 // Revision 1.3 1994/08/31 23:35:00 rj
69 // semicolon removed from end of macro text
70 //
71 // Revision 1.2 1994/08/28 10:00:50 rj
72 // comment leader fixed.
73 //
74 // Revision 1.1 1994/08/28 09:20:36 rj
75 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
76
77 #ifndef _asn_len_h_
78 #define _asn_len_h_
79
80 typedef size_t AsnLen;
81
82 #define INDEFINITE_LEN ~0UL // max unsigned value used for indef rep
83
84 #ifdef USE_INDEF_LEN
85
86 #define BEncEocIfNec(b)\
87 BEncEoc (b)
88
89 #define BEncConsLen(b, len)\
90 2 + BEncIndefLen (b) /* include len for EOC */
91
92 #else // default -- use definite length -- usually faster (for snacc encoders) and smaller encodings
93
94 #define BEncEocIfNec(b) /* do nothing */
95
96 #define BEncConsLen(b, len)\
97 BEncDefLen (b, len)
98
99 #endif
100
101 #define BEncIndefLen( b)\
102 1;\
103 b.PutByteRvs (0x80)
104
105 /*
106 * use if you know the encoded length will be 0 >= len <= 127
107 * Eg for booleans, nulls, any resonable integers and reals
108 *
109 * NOTE: this particular Encode Routine does NOT return the length
110 * encoded (1). The length counter must be explicity incremented
111 */
112 #define BEncDefLenTo127( b, len)\
113 b.PutByteRvs ((unsigned char) len)
114
115 #define BDEC_2ND_EOC_OCTET( b, bytesDecoded, env)\
116 {\
117 if ((b.GetByte() != 0) || b.ReadError())\
118 Asn1Warning << "Warning - second octet of EOC not zero" << endl;\
119 (bytesDecoded)++;\
120 }
121
122 AsnLen BDecLen (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env);
123
124 AsnLen BEncDefLen ( BUF_TYPE b, AsnLen len);
125
126 AsnLen BEncEoc (BUF_TYPE b);
127
128 void BDecEoc (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env);
129
130 #endif /* conditional include */