]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/asn-enum.cpp
Security-54.1.7.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / c++ / asn-enum.cpp
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/src/asn-enum.C - methods for AsnEnum (ASN.1 ENUMERATED) class
20 //
21 // MS 92/06/16
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/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.
38 //
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.
41 //
42 // Revision 1.2 2001/06/26 23:49:52 dmitch
43 // Was cerr, is Asn1Error.
44 //
45 // Revision 1.1.1.1 2001/05/18 23:14:05 mb
46 // Move from private repository to open source repository
47 //
48 // Revision 1.2 2001/05/05 00:59:17 rmurphy
49 // Adding darwin license headers
50 //
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.
53 //
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....
56 //
57 // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy
58 // Base Fortissimo Tree
59 //
60 // Revision 1.2 1999/03/21 02:07:35 mb
61 // Added Copy to every AsnType.
62 //
63 // Revision 1.1 1999/02/25 05:21:51 mb
64 // Added snacc c++ library
65 //
66 // Revision 1.5 1997/02/28 13:39:44 wan
67 // Modifications collected for new version 1.3: Bug fixes, tk4.2.
68 //
69 // Revision 1.4 1995/08/17 15:19:52 rj
70 // AsnEnumTypeDesc gets its own TclGetVal and TclSetVal functions.
71 //
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.
74 //
75 // call constructor with additional pdu and create arguments.
76 //
77 // changed `_' to `-' in file names.
78 //
79 // Revision 1.2 1994/10/08 05:26:37 rj
80 // comment leader fixed.
81 //
82 // Revision 1.1 1994/10/08 05:24:03 rj
83 // functions extracted from ../inc/asn_enum.h
84
85 #include "asn-config.h"
86 #include "asn-len.h"
87 #include "asn-tag.h"
88 #include "asn-type.h"
89 #include "asn-int.h"
90 #include "asn-enum.h"
91
92 AsnType *AsnEnum::Clone() const
93 {
94 Asn1Error << "AsnEnum::Clone() called" << endl;
95 abort();
96 return NULL;
97 }
98
99 AsnType *AsnEnum::Copy() const
100 {
101 Asn1Error << "AsnEnum::Copy() called" << endl;
102 abort();
103 return NULL;
104 }
105
106 AsnLen AsnEnum::BEnc (BUF_TYPE b)
107 {
108 AsnLen l;
109 l = BEncContent (b);
110 BEncDefLenTo127 (b, l);
111 l++;
112 l += BEncTag1 (b, UNIV, PRIM, ENUM_TAG_CODE);
113 return l;
114 }
115
116 void AsnEnum::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
117 {
118 AsnLen elmtLen;
119 if (BDecTag (b, bytesDecoded, env) != MAKE_TAG_ID (UNIV, PRIM, ENUM_TAG_CODE))
120 {
121 Asn1Error << "AsnEnum::BDec: ERROR tag on ENUMERATED is wrong." << endl;
122 #if SNACC_EXCEPTION_ENABLE
123 SnaccExcep::throwMe(-52);
124 #else
125 longjmp (env,-52);
126 #endif
127 }
128
129 elmtLen = BDecLen (b, bytesDecoded, env);
130 BDecContent (b, MAKE_TAG_ID (UNIV, PRIM, ENUM_TAG_CODE), elmtLen, bytesDecoded, env);
131 }
132
133 #if META
134
135 const AsnEnumTypeDesc AsnEnum::_desc (NULL, NULL, false, AsnTypeDesc::ENUMERATED, NULL, NULL);
136
137 const AsnTypeDesc *AsnEnum::_getdesc() const
138 {
139 return &_desc;
140 }
141
142 #if TCL
143
144 int AsnEnum::TclGetVal (Tcl_Interp *interp) const
145 {
146 const AsnNameDesc *n = _getdesc()->getnames();
147 if (n)
148 {
149 for (; n->name; n++)
150 if (n->value == value)
151 {
152 Tcl_SetResult (interp, (char*)n->name, TCL_STATIC);
153 return TCL_OK;
154 }
155 }
156 char valstr[80];
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);
160 return TCL_ERROR;
161 }
162
163 int AsnEnum::TclSetVal (Tcl_Interp *interp, const char *valstr)
164 {
165 const AsnNameDesc *n = _getdesc()->getnames();
166 if (n)
167 {
168 for (; n->name; n++)
169 if (!strcmp (n->name, valstr))
170 {
171 value = n->value;
172 return TCL_OK;
173 }
174 }
175 Tcl_SetErrorCode (interp, "SNACC", "ILLENUM", NULL);
176 Tcl_AppendResult (interp, "illegal symbolic enumeration value \"", valstr, "\" for type ", _getdesc()->getmodule()->name, ".", _getdesc()->getname(), NULL);
177 return TCL_ERROR;
178 }
179
180 #endif /* TCL */
181 #endif /* META */