]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/asn-any.cpp
c629bd5e45556e6ba193f20b3cbfd1d3acbbfafb
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.
19 // file: .../c++-lib/src/asn-any.C
22 // Copyright (C) 1992 Michael Sample and the University of British Columbia
24 // This library is free software; you can redistribute it and/or
25 // modify it provided that this copyright/license information is retained
28 // If you modify this file, you must clearly indicate your changes.
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.
35 // ------------------------------------------------------------------------
36 // - J.G. Van Dyke & Associates, Inc. Modification History of SNACC 1.3 -
37 // ------------------------------------------------------------------------
39 // All modification are relative to the v1.3 of SNACC. We used SunOS 4.1.3's
40 // SCCS. The revision #'s start at 1.1, which is the original version from
44 // ../SCCS/s.asn-any.C:
46 // D 1.2 98/05/01 13:47:09 pleonber 2 1 00046/00007/00164
47 // added destructor and copy for CSM_Buffer handling.
49 // D 1.1 98/05/01 13:19:19 pleonber 1 0 00171/00000/00000
50 // date and time created 98/05/01 13:19:19 by pleonber
52 // ----------------------- End of VDA Modifications ---------------------------
56 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/c++/Attic/asn-any.cpp,v 1.4 2002/03/21 05:38:44 dmitch Exp $
57 // $Log: asn-any.cpp,v $
58 // Revision 1.4 2002/03/21 05:38:44 dmitch
59 // Radar 2868524: no more setjmp/longjmp in SNACC-generated code.
61 // Revision 1.3.44.1 2002/03/20 00:36:48 dmitch
62 // Radar 2868524: SNACC-generated code now uses throw/catch instead of setjmp/longjmp.
64 // Revision 1.3 2001/06/27 23:09:14 dmitch
65 // Pusuant to Radar 2664258, avoid all cerr-based output in NDEBUG configuration.
67 // Revision 1.2 2001/06/25 22:44:17 dmitch
68 // Globalize hashTblLock with a ModuleNexus. Partial fix for Radar 2664258.
70 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
71 // Move from private repository to open source repository
73 // Revision 1.6 2001/05/05 00:59:18 rmurphy
74 // Adding darwin license headers
76 // Revision 1.5 2000/12/20 00:51:37 dmitch
77 // Cosmetic changwe to resync with ../c++/asn-any.cpp.
79 // Revision 1.4 2000/12/20 00:43:14 dmitch
80 // Acquire and release hashTblLock via an StLock.
82 // Revision 1.3 2000/12/07 22:32:03 dmitch
83 // Thread-safe mods: see comments for same file in ../c++/.
85 // Revision 1.2 2000/12/07 22:13:45 dmitch
86 // Thread-safe mods: added hashTblLock.
88 // Revision 1.1 2000/06/15 18:44:59 dmitch
89 // These snacc-generated source files are now checked in to allow cross-platform build.
91 // Revision 1.2 2000/06/08 20:05:37 dmitch
92 // Mods for X port. These files are actually machine generated and probably don't need to be in CVS....
94 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
95 // Base Fortissimo Tree
97 // Revision 1.5 1999/03/21 02:07:35 mb
98 // Added Copy to every AsnType.
100 // Revision 1.4 1999/03/19 23:59:21 mb
101 // Invoke Print on our value since CSM_Buffer::Print now implements print too.
103 // Revision 1.3 1999/03/19 00:55:01 mb
104 // Made CSM_Buffer a subclass of AsnType.
106 // Revision 1.2 1999/03/18 22:35:28 mb
107 // Made all destructors virtual.
109 // Revision 1.1 1999/02/25 05:21:49 mb
110 // Added snacc c++ library
112 // Revision 1.6 1997/02/28 13:39:43 wan
113 // Modifications collected for new version 1.3: Bug fixes, tk4.2.
115 // Revision 1.5 1997/02/16 20:26:01 rj
116 // check-in of a few cosmetic changes
118 // Revision 1.4 1995/07/24 20:12:48 rj
119 // changed `_' to `-' in file names.
121 // Revision 1.3 1994/10/08 04:18:20 rj
122 // code for meta structures added (provides information about the generated code itself).
124 // code for Tcl interface added (makes use of the above mentioned meta code).
126 // 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.
128 // made Print() const (and some other, mainly comparison functions).
130 // several `unsigned long int' turned into `size_t'.
132 // Revision 1.2 1994/08/28 10:01:10 rj
133 // comment leader fixed.
135 // Revision 1.1 1994/08/28 09:20:55 rj
136 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
138 #include "asn-incl.h"
139 #include "sm_vdasnacc.h"
141 //#include "asn-config.h"
142 //#include "asn-len.h"
143 //#include "asn-tag.h"
144 //#include "asn-type.h"
145 //#include "asn-oid.h"
146 //#include "asn-int.h"
147 //#include "asn-any.h"
151 #include <Security/threading.h>
152 #include <Security/globalizer.h>
153 Table
* AsnAny :: oidHashTbl
= NULL
;
154 Table
* AsnAny :: intHashTbl
= NULL
;
155 ModuleNexus
< Mutex
> hashTblLock
;
158 // Define this ANY value's type to the one that the given id hashes
159 // to in the ANY table.
161 AsnAny :: SetTypeByInt ( AsnInt id
)
166 /* use int as hash string */
167 AsnIntType idval
= ( AsnIntType
) id
;
168 hash
= MakeHash (( char *)& idval
, sizeof ( idval
));
170 StLock
< Mutex
> _ ( hashTblLock ());
172 if ( CheckForAndReturnValue ( intHashTbl
, hash
, & anyInfo
))
173 ai
= ( AnyInfo
*) anyInfo
;
175 ai
= NULL
; /* indicates failure */
177 } /* SetAnyTypeByInt */
179 // Define this ANY value's type to the one that the given id hashes
180 // to in the ANY table.
181 void AsnAny :: SetTypeByOid ( AsnOid
& id
)
186 /* use encoded oid as hash string */
187 hash
= MakeHash ( id
. Str (), id
. Len ());
190 StLock
< Mutex
> _ ( hashTblLock ());
193 if ( CheckForAndReturnValue ( oidHashTbl
, hash
, & anyInfo
))
194 ai
= ( AnyInfo
*) anyInfo
;
196 ai
= NULL
; /* indicates failure */
198 } /* SetAnyTypeByOid */
202 // Given an integer, intId, to hash on, the type and it's anyId
203 // are installed in the integer id hash tbl
205 AsnAny :: InstallAnyByInt ( AsnInt intId
, int anyId
, AsnType
* type
)
211 // Oid will be NULL and 0 len by default constructor
214 a
-> typeToClone
= type
;
217 StLock
< Mutex
> _ ( hashTblLock ());
219 if ( AsnAny :: intHashTbl
== NULL
)
220 AsnAny :: intHashTbl
= InitHash ();
222 AsnIntType idval
= ( AsnIntType
) intId
;
223 h
= MakeHash (( char *)& idval
, sizeof ( idval
));
224 Insert ( AsnAny :: intHashTbl
, a
, h
);
226 } /* InstallAnyByInt */
229 // given an OBJECT IDENTIFIER, oid, to hash on, the type and it's anyId
230 // are installed in the OBJECT IDENTIFIER id hash tbl
232 AsnAny :: InstallAnyByOid ( AsnOid
& oid
, int anyId
, AsnType
* type
)
239 a
-> oid
= oid
; // copy given oid
240 a
-> typeToClone
= type
;
242 h
= MakeHash ( oid
. Str (), oid
. Len ());
245 StLock
< Mutex
> _ ( hashTblLock ());
247 if ( AsnAny :: oidHashTbl
== NULL
)
248 AsnAny :: oidHashTbl
= InitHash ();
250 Insert ( AsnAny :: oidHashTbl
, a
, h
);
251 } /* InstallAnyByOid */
254 AsnType
* AsnAny :: Clone () const
259 AsnType
* AsnAny :: Copy () const
261 return new AsnAny (* this );
266 // if you haven't set up the value properly
267 // this will croak (since it's a programming error
268 // - ie, you didn't initialize the data structure properly
271 AsnAny :: BEnc ( BUF_TYPE b
)
273 return value
-> BEnc ( b
);
279 AsnAny :: BDec ( BUF_TYPE b
, AsnLen
& bytesDecoded
, ENV_TYPE env
)
282 #if SNACC_EXCEPTION_ENABLE
283 SnaccExcep :: throwMe (- 81 );
288 // XXX This is wrong.
289 value
= static_cast < CSM_Buffer
*>( ai
-> typeToClone
-> Clone ());
292 #if SNACC_EXCEPTION_ENABLE
293 SnaccExcep :: throwMe (- 82 );
298 value
-> BDec ( b
, bytesDecoded
, env
);
302 void AsnAny :: Print ( ostream
& os
) const
316 AsnAny
& AsnAny :: operator = ( const AsnAny
& o
)
318 if ( this -> ai
) // take care of most copies.
323 this -> ai
= new AnyInfo
;
326 /* __APPLE__ - I don't think this needs a lock since it's
327 * not modifying the hash tables */
330 this -> intHashTbl
= o
. intHashTbl
; // same pointer.
334 this -> oidHashTbl
= o
. oidHashTbl
;
338 this -> value
= static_cast < CSM_Buffer
*>( o
. value
-> Copy ());