]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/asn-list.cpp
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-list.C
24 // *** NOTE - this is not tested and not used ****
25 // snacc generates a new class for each list type,
27 // (gcc choked on templates)
28 // Copyright (C) 1992 Michael Sample and the University of British Columbia
30 // This library is free software; you can redistribute it and/or
31 // modify it provided that this copyright/license information is retained
34 // If you modify this file, you must clearly indicate your changes.
36 // This source code is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
40 // $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c++-lib/c++/asn-list.cpp,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
41 // $Log: asn-list.cpp,v $
42 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
43 // Move from private repository to open source repository
45 // Revision 1.2 2001/05/05 00:59:17 rmurphy
46 // Adding darwin license headers
48 // Revision 1.1 2000/06/15 18:44:57 dmitch
49 // These snacc-generated source files are now checked in to allow cross-platform build.
51 // Revision 1.2 2000/06/08 20:05:35 dmitch
52 // Mods for X port. These files are actually machine generated and probably don't need to be in CVS....
54 // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy
55 // Base Fortissimo Tree
57 // Revision 1.3 1999/07/14 23:53:56 aram
58 // Made const correct so things build with CW 5.0
60 // Revision 1.2 1999/03/21 02:07:36 mb
61 // Added Copy to every AsnType.
63 // Revision 1.1 1999/02/25 05:21:52 mb
64 // Added snacc c++ library
66 // Revision 1.8 1997/09/04 13:54:09 wan
67 // A little more portability
69 // Revision 1.7 1997/01/02 08:42:39 rj
70 // names of Tcl*-functions fixed (obviously they weren't needed :-)
72 // Revision 1.6 1995/07/24 20:18:15 rj
73 // #if TCL ... #endif wrapped into #if META ... #endif
75 // call constructor with additional pdu and create arguments.
77 // changed `_' to `-' in file names.
79 // Revision 1.5 1995/02/18 14:06:02 rj
80 // #pragma interface/implementation are GNU specific and need to be wrapped.
82 // Revision 1.4 1994/10/08 04:18:25 rj
83 // code for meta structures added (provides information about the generated code itself).
85 // code for Tcl interface added (makes use of the above mentioned meta code).
87 // 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.
89 // made Print() const (and some other, mainly comparison functions).
91 // several `unsigned long int' turned into `size_t'.
93 // Revision 1.3 1994/08/31 23:38:24 rj
94 // FALSE/TRUE turned into false/true
96 // Revision 1.2 1994/08/28 10:01:14 rj
97 // comment leader fixed.
99 // Revision 1.1 1994/08/28 09:21:02 rj
100 // first check-in. for a list of changes to 1.1 please refer to the ChangeLog.
102 #include "asn-config.h"
105 #include "asn-type.h"
108 #pragma implementation
111 #include "asn-list.h"
114 void AsnList
< T
>:: SetCurrElmt ( unsigned long int index
)
118 for ( i
= 0 ; ( i
< ( count
- 1 )) && ( i
< index
); i
++)
123 // print routine for lists
125 ostream
& operator << ( ostream
& os
, AsnList
< T
> & l
)
127 os
<< "SEQUENCE OF { " ;
130 for (; l
. Curr () != NULL
; l
. GoNext ())
133 if ( l
. Curr () != l
. Last ())
143 // alloc new list elmt, put at end of list
144 // and return the component type
146 T
& AsnList
< T
>:: Append ()
148 AsnListElmt
* newElmt
;
150 newElmt
= new AsnListElmt
;
152 newElmt
-> next
= NULL
;
156 newElmt
-> prev
= NULL
;
157 first
= last
= newElmt
;
161 newElmt
-> prev
= last
;
162 last
-> next
= newElmt
;
168 return newElmt
-> elmt
;
170 } /* AsnList::Append */
173 // alloc new list elmt, put at beggining of list
174 // and return the component type
176 T
& AsnList
< T
>:: Prepend ()
178 AsnListElmt
* newElmt
;
180 newElmt
= new AsnListElmt
;
182 newElmt
-> prev
= NULL
;
186 newElmt
-> next
= NULL
;
187 first
= last
= newElmt
;
191 newElmt
-> next
= first
;
192 first
-> prev
= newElmt
;
198 return newElmt
-> elmt
;
200 } /* AsnList::Prepend */
203 AsnList
< T
>& AsnList
< T
>:: AppendAndCopy ( T
& elmt
)
205 AsnListElmt
* newElmt
;
207 newElmt
= new AsnListElmt
;
209 newElmt
-> elmt
= elmt
;
211 newElmt
-> next
= NULL
;
215 newElmt
-> prev
= NULL
;
216 first
= last
= newElmt
;
220 newElmt
-> prev
= last
;
221 last
-> next
= newElmt
;
229 } /* AppendAndCopy */
232 AsnList
< T
>& AsnList
< T
>:: PrependAndCopy ( T
& elmt
)
234 AsnListElmt
* newElmt
;
236 newElmt
= new AsnListElmt
;
238 newElmt
-> elmt
= elmt
;
240 newElmt
-> prev
= NULL
;
244 newElmt
-> next
= NULL
;
245 first
= last
= newElmt
;
249 newElmt
-> next
= first
;
250 first
-> prev
= newElmt
;
258 } /* PrependAndCopy */
261 AsnType
* AsnList
< T
>:: Clone () const
267 AsnType
* AsnList
< T
>:: Copy () const
269 return new T (* this );
273 AsnLen AsnList
< T
>:: BEncContent ( BUF_TYPE b
)
275 AsnListElmt
* currElmt
;
278 for ( currElmt
= last
; currElmt
!= NULL
; currElmt
= currElmt
-> prev
)
279 sum
+= currElmt
-> elmt
. BEnc ( b
);
285 void AsnList
< T
>:: BDecContent ( BUF_TYPE b
, AsnTag tagId
, AsnLen elmtLen
, AsnLen
& bytesDecoded
, ENV_TYPE env
)
288 AsnTag listElmtTagId
;
289 AsnLen localBytesDecoded
= 0 ;
290 AsnLen listElmtLen
= 0 ;
293 while (( localBytesDecoded
< elmtLen
) || ( elmtLen
== INDEFINITE_LEN
))
295 listElmtTagId
= BDecTag ( b
, bytesDecoded
, env
);
297 if (( listElmtTagId
== EOC
) && ( elmtLen
== INDEFINITE_LEN
))
302 listElmtLen
= BDecLen ( b
, bytesDecoded
, env
);
303 listElmt
. BDecContent ( b
, listElmtTagId
, listElmtLen
, localBytesDecoded
, env
);
305 bytesDecoded
+= localBytesDecoded
;
307 } /* AsnList<T>::BDecContent */
310 AsnLen AsnList
< T
>:: BEnc ( BUF_TYPE b
)
314 l
+= BEncDefLen ( b
, l
);
315 l
+= BEncTag1 ( b
, UNIV
, CONS
, SEQ_TAG_CODE
);
320 void AsnList
< T
>:: BDec ( BUF_TYPE b
, AsnLen
& bytesDecoded
, ENV_TYPE env
)
323 if ( BDecTag ( b
, bytesDecoded
, env
) != MAKE_TAG_ID ( UNIV
, CONS
, SEQ_TAG_CODE
))
325 Asn1Error
<< "AsnList::BDec: ERROR tag on SEQUENCE OF is wrong." << endl
;
328 elmtLen
= BDecLen ( b
, bytesDecoded
, env
);
330 BDecContent ( b
, MAKE_TAG_ID ( UNIV
, CONS
, SEQ_TAG_CODE
), elmtLen
, bytesDecoded
, env
);
333 template < class T
, class U
>
334 int ListsEquiv ( AsnList
< T
>& l1
, AsnList
< U
>& l2
)
336 if ( l1
. Count () != l2
. Count ())
342 for (; l1
. Curr () != NULL
; l1
. GoNext (), l2
. GoNext ())
344 if (* l1
. Curr () != * l2
. Curr ())
355 const AsnTypeDesc
AsnList :: _desc ( NULL
, NULL
, false , AsnTypeDesc :: SET_or_SEQUENCE_OF
, NULL
);
357 const AsnTypeDesc
* AsnList :: _getdesc () const
364 int AsnList :: TclGetVal ( Tcl_Interp
* interp
) const
369 int AsnList :: TclSetVal ( Tcl_Interp
* interp
, const char * valstr
)