]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/asn-enum.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-enum.C - methods for AsnEnum (ASN.1 ENUMERATED) class
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.
34 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/c++/Attic/asn-enum.cpp,v 1.3 2002/03/21 05:38:44 dmitch Exp $
35 // $Log: asn-enum.cpp,v $
36 // Revision 1.3 2002/03/21 05:38:44 dmitch
37 // Radar 2868524: no more setjmp/longjmp in SNACC-generated code.
39 // Revision 1.2.44.1 2002/03/20 00:36:49 dmitch
40 // Radar 2868524: SNACC-generated code now uses throw/catch instead of setjmp/longjmp.
42 // Revision 1.2 2001/06/26 23:49:52 dmitch
43 // Was cerr, is Asn1Error.
45 // Revision 1.1.1.1 2001/05/18 23:14:05 mb
46 // Move from private repository to open source repository
48 // Revision 1.2 2001/05/05 00:59:17 rmurphy
49 // Adding darwin license headers
51 // Revision 1.1 2000/06/15 18:44:57 dmitch
52 // These snacc-generated source files are now checked in to allow cross-platform build.
54 // Revision 1.2 2000/06/08 20:05:35 dmitch
55 // Mods for X port. These files are actually machine generated and probably don't need to be in CVS....
57 // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy
58 // Base Fortissimo Tree
60 // Revision 1.2 1999/03/21 02:07:35 mb
61 // Added Copy to every AsnType.
63 // Revision 1.1 1999/02/25 05:21:51 mb
64 // Added snacc c++ library
66 // Revision 1.5 1997/02/28 13:39:44 wan
67 // Modifications collected for new version 1.3: Bug fixes, tk4.2.
69 // Revision 1.4 1995/08/17 15:19:52 rj
70 // AsnEnumTypeDesc gets its own TclGetVal and TclSetVal functions.
72 // Revision 1.3 1995/07/24 20:14:49 rj
73 // Clone() added, or else the _desc would be wrong (and the wrong BEnc etc... would get called) for Clone-d objects.
75 // call constructor with additional pdu and create arguments.
77 // changed `_' to `-' in file names.
79 // Revision 1.2 1994/10/08 05:26:37 rj
80 // comment leader fixed.
82 // Revision 1.1 1994/10/08 05:24:03 rj
83 // functions extracted from ../inc/asn_enum.h
85 #include "asn-config.h"
92 AsnType
*AsnEnum::Clone() const
94 Asn1Error
<< "AsnEnum::Clone() called" << endl
;
99 AsnType
*AsnEnum::Copy() const
101 Asn1Error
<< "AsnEnum::Copy() called" << endl
;
106 AsnLen
AsnEnum::BEnc (BUF_TYPE b
)
110 BEncDefLenTo127 (b
, l
);
112 l
+= BEncTag1 (b
, UNIV
, PRIM
, ENUM_TAG_CODE
);
116 void AsnEnum::BDec (BUF_TYPE b
, AsnLen
&bytesDecoded
, ENV_TYPE env
)
119 if (BDecTag (b
, bytesDecoded
, env
) != MAKE_TAG_ID (UNIV
, PRIM
, ENUM_TAG_CODE
))
121 Asn1Error
<< "AsnEnum::BDec: ERROR tag on ENUMERATED is wrong." << endl
;
122 #if SNACC_EXCEPTION_ENABLE
123 SnaccExcep::throwMe(-52);
129 elmtLen
= BDecLen (b
, bytesDecoded
, env
);
130 BDecContent (b
, MAKE_TAG_ID (UNIV
, PRIM
, ENUM_TAG_CODE
), elmtLen
, bytesDecoded
, env
);
135 const AsnEnumTypeDesc
AsnEnum::_desc (NULL
, NULL
, false, AsnTypeDesc::ENUMERATED
, NULL
, NULL
);
137 const AsnTypeDesc
*AsnEnum::_getdesc() const
144 int AsnEnum::TclGetVal (Tcl_Interp
*interp
) const
146 const AsnNameDesc
*n
= _getdesc()->getnames();
150 if (n
->value
== value
)
152 Tcl_SetResult (interp
, (char*)n
->name
, TCL_STATIC
);
157 sprintf (valstr
, "%d", value
);
158 Tcl_AppendResult (interp
, "illegal numeric enumeration value ", valstr
, " for type ", _getdesc()->getmodule()->name
, ".", _getdesc()->getname(), NULL
);
159 Tcl_SetErrorCode (interp
, "SNACC", "ILLENUM", NULL
);
163 int AsnEnum::TclSetVal (Tcl_Interp
*interp
, const char *valstr
)
165 const AsnNameDesc
*n
= _getdesc()->getnames();
169 if (!strcmp (n
->name
, valstr
))
175 Tcl_SetErrorCode (interp
, "SNACC", "ILLENUM", NULL
);
176 Tcl_AppendResult (interp
, "illegal symbolic enumeration value \"", valstr
, "\" for type ", _getdesc()->getmodule()->name
, ".", _getdesc()->getname(), NULL
);