]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/asn-bits.h
Security-54.1.7.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / inc / asn-bits.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-bits.h - ASN.1 BIT STRING type
20 //
21 // Mike Sample
22 // 92/07/02
23 // Copyright (C) 1992 Michael Sample and the University of British Columbia
24 //
25 // This library is free software; you can redistribute it and/or
26 // modify it provided that this copyright/license information is retained
27 // in original form.
28 //
29 // If you modify this file, you must clearly indicate your changes.
30 //
31 // This source code is distributed in the hope that it will be
32 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
33 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 //
35 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/inc/Attic/asn-bits.h,v 1.2 2001/06/28 23:36:11 dmitch Exp $
36 // $Log: asn-bits.h,v $
37 // Revision 1.2 2001/06/28 23:36:11 dmitch
38 // Removed SccsId statics. numToHexCharTblG table now const. Radar 2705410.
39 //
40 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
41 // Move from private repository to open source repository
42 //
43 // Revision 1.5 2001/05/05 00:59:17 rmurphy
44 // Adding darwin license headers
45 //
46 // Revision 1.4 2000/12/07 22:29:50 dmitch
47 // Thread-safe mods: added strStkG, strStkUnusedBitsG arguments to FillBitStringStk .
48 //
49 // Revision 1.3 2000/08/24 20:00:25 dmitch
50 // Added BitOcts() accessor.
51 //
52 // Revision 1.2 2000/06/15 18:48:22 dmitch
53 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
54 //
55 // 2000/8/24 dmitch at Apple
56 // Added BitOcts() accessor.
57 //
58 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
59 // Base Fortissimo Tree
60 //
61 // Revision 1.3 1999/03/21 02:07:31 mb
62 // Added Copy to every AsnType.
63 //
64 // Revision 1.2 1999/03/18 22:35:27 mb
65 // Made all destructors virtual.
66 //
67 // Revision 1.1 1999/02/25 05:21:40 mb
68 // Added snacc c++ library
69 //
70 // Revision 1.6 1997/02/16 20:25:33 rj
71 // check-in of a few cosmetic changes
72 //
73 // Revision 1.5 1995/07/24 17:53:51 rj
74 // #if TCL ... #endif wrapped into #if META ... #endif
75 //
76 // changed `_' to `-' in file names.
77 //
78 // Revision 1.4 1995/02/18 19:26:18 rj
79 // remove const from arguments that are passed by value.
80 //
81 // Revision 1.3 1994/10/08 04:17:57 rj
82 // code for meta structures added (provides information about the generated code itself).
83 //
84 // code for Tcl interface added (makes use of the above mentioned meta code).
85 //
86 // 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.
87 //
88 // made Print() const (and some other, mainly comparison functions).
89 //
90 // several `unsigned long int' turned into `size_t'.
91 //
92 // Revision 1.2 1994/08/28 10:00:44 rj
93 // comment leader fixed.
94 //
95 // Revision 1.1 1994/08/28 09:20:25 rj
96 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
97
98 #ifndef _asn_bits_h_
99 #define _asn_bits_h_
100
101 #ifdef __APPLE__
102 #include "str-stk.h"
103 #endif
104
105 extern const char numToHexCharTblG[];
106
107 #define TO_HEX( fourBits) (numToHexCharTblG[(fourBits) & 0x0F])
108
109 class AsnBits: public AsnType
110 {
111 private:
112 bool BitsEquiv (const AsnBits &ab) const;
113 void BDecConsBits (BUF_TYPE b, AsnLen elmtLen, AsnLen &bytesDecoded, ENV_TYPE env);
114 #ifdef __APPLE__
115 void FillBitStringStk (BUF_TYPE b, AsnLen elmtLen0,
116 AsnLen &bytesDecoded, ENV_TYPE env,
117 StrStk &strStkG, unsigned short int &strStkUnusedBitsG);
118 #else
119 void FillBitStringStk (BUF_TYPE b, AsnLen elmtLen0,
120 AsnLen &bytesDecoded, ENV_TYPE env);
121 #endif
122
123 protected:
124 size_t bitLen;
125 char *bits;
126
127 public:
128
129 AsnBits() { bits = NULL; bitLen = 0; }
130 AsnBits (size_t numBits) { Set (numBits); }
131 AsnBits (const char *bitOcts, size_t numBits)
132 { Set (bitOcts, numBits); }
133 AsnBits (const AsnBits &b) { Set (b); }
134 #ifndef _IBM_ENC_
135 virtual ~AsnBits();
136 #else
137 virtual ~AsnBits() { mem_mgr_ptr->Put ((void *) bits); } // Guido Grassel, 11.8.93
138 #endif /* _IBM_ENC_ */
139
140 virtual AsnType *Clone() const;
141 virtual AsnType *Copy() const;
142
143 AsnBits &operator = (const AsnBits &b) { ReSet (b); return *this; }
144
145 // overwrite existing bits and bitLen values
146 void Set (size_t numBits);
147 void Set (const char *bitOcts, size_t numBits);
148 void Set (const AsnBits &b);
149
150 // free old bits value, the reset bits and bitLen values
151 void ReSet (size_t numBits);
152 void ReSet (const char *bitOcts, size_t numBits);
153 void ReSet (const AsnBits &b);
154
155 bool operator == (const AsnBits &ab) const { return BitsEquiv (ab); }
156 bool operator != (const AsnBits &ab) const { return !BitsEquiv (ab); }
157
158 void SetBit (size_t);
159 void ClrBit (size_t);
160 bool GetBit (size_t) const;
161
162 // Apple addenda: this is just too useful to exclude.
163 const char *BitOcts() const { return bits; }
164
165 size_t BitLen() const { return bitLen; }
166
167 AsnLen BEncContent (BUF_TYPE b);
168 void BDecContent (BUF_TYPE b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded, ENV_TYPE env);
169 AsnLen BEnc (BUF_TYPE b);
170 void BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env);
171
172 PDU_MEMBER_MACROS
173
174 void Print (ostream &) const;
175
176 #if META
177 static const AsnBitsTypeDesc _desc;
178
179 const AsnTypeDesc *_getdesc() const;
180
181 #if TCL
182 int TclGetVal (Tcl_Interp *) const;
183 int TclSetVal (Tcl_Interp *, const char *val);
184 #endif /* TCL */
185 #endif /* META */
186 };
187
188 #endif /* conditional include */