]> git.saurik.com Git - apple/security.git/blame - SecuritySNACCRuntime/c++-lib/c++/asn-null.cpp
Security-54.1.3.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / c++ / asn-null.cpp
CommitLineData
bac41a7b
A
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-null.C
20//
21// MS 92
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//
5a719ac8 34// $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/c++-lib/c++/asn-null.cpp,v 1.3 2002/03/21 05:38:44 dmitch Exp $
bac41a7b 35// $Log: asn-null.cpp,v $
29654253
A
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//
bac41a7b
A
42// Revision 1.2 2001/06/27 23:09:14 dmitch
43// Pusuant to Radar 2664258, avoid all cerr-based output in NDEBUG configuration.
44//
45// Revision 1.1.1.1 2001/05/18 23:14:06 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:36 mb
61// Added Copy to every AsnType.
62//
63// Revision 1.1 1999/02/25 05:21:52 mb
64// Added snacc c++ library
65//
66// Revision 1.5 1995/08/17 15:38:19 rj
67// set Tcl's errorCode variable
68//
69// Revision 1.4 1995/07/24 20:18:27 rj
70// #if TCL ... #endif wrapped into #if META ... #endif
71//
72// call constructor with additional pdu and create arguments.
73//
74// changed `_' to `-' in file names.
75//
76// Revision 1.3 1994/10/08 04:18:26 rj
77// code for meta structures added (provides information about the generated code itself).
78//
79// code for Tcl interface added (makes use of the above mentioned meta code).
80//
81// 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.
82//
83// made Print() const (and some other, mainly comparison functions).
84//
85// several `unsigned long int' turned into `size_t'.
86//
87// Revision 1.2 1994/08/28 10:01:15 rj
88// comment leader fixed.
89//
90// Revision 1.1 1994/08/28 09:21:04 rj
91// first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
92
93#include "asn-config.h"
94#include "asn-len.h"
95#include "asn-tag.h"
96#include "asn-type.h"
97#include "asn-null.h"
98
99AsnType *AsnNull::Clone() const
100{
101 return new AsnNull;
102}
103
104AsnType *AsnNull::Copy() const
105{
106 return new AsnNull (*this);
107}
108
109void AsnNull::BDecContent (BUF_TYPE b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded, ENV_TYPE env)
110{
111 if (elmtLen != 0)
112 {
113 Asn1Error << "AsnNull::BDecContent: ERROR - NULL values len is non-zero" << endl;
29654253
A
114 #if SNACC_EXCEPTION_ENABLE
115 SnaccExcep::throwMe(-13);
116 #else
bac41a7b 117 longjmp (env, -13);
29654253 118 #endif
bac41a7b
A
119 }
120} /* AsnNull::BDecContent */
121
122AsnLen AsnNull::BEnc (BUF_TYPE b)
123{
124 AsnLen l;
125 l = BEncContent (b);
126 BEncDefLenTo127 (b, l);
127 l++;
128 l += BEncTag1 (b, UNIV, PRIM, NULLTYPE_TAG_CODE);
129 return l;
130}
131
132void AsnNull::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
133{
134 AsnLen elmtLen;
135 if (BDecTag (b, bytesDecoded, env) != MAKE_TAG_ID (UNIV, PRIM, NULLTYPE_TAG_CODE))
136 {
137 Asn1Error << "AsnNull::BDec: ERROR tag on NULL is wrong." << endl;
29654253
A
138 #if SNACC_EXCEPTION_ENABLE
139 SnaccExcep::throwMe(-55);
140 #else
bac41a7b 141 longjmp (env, -55);
29654253 142 #endif
bac41a7b
A
143 }
144
145 elmtLen = BDecLen (b, bytesDecoded, env);
146 BDecContent (b, MAKE_TAG_ID (UNIV, PRIM, NULLTYPE_TAG_CODE), elmtLen, bytesDecoded, env);
147}
148
149void AsnNull::Print (ostream &os) const
150{
151#ifndef NDEBUG
152 os << "NULL";
153#endif
154}
155
156#if META
157
158const AsnNullTypeDesc AsnNull::_desc (NULL, NULL, false, AsnTypeDesc::NUL_, NULL);
159
160const AsnTypeDesc *AsnNull::_getdesc() const
161{
162 return &_desc;
163}
164
165#if TCL
166
167int AsnNull::TclGetVal (Tcl_Interp *interp) const
168{
169 return TCL_OK;
170}
171
172int AsnNull::TclSetVal (Tcl_Interp *interp, const char *valstr)
173{
174 if (*valstr)
175 {
176 Tcl_AppendResult (interp, "illegal non-null value `", valstr, "' for type ", _getdesc()->getmodule()->name, ".", _getdesc()->getname(), NULL);
177 Tcl_SetErrorCode (interp, "SNACC", "ILLNULL", NULL);
178 return TCL_ERROR;
179 }
180
181 return TCL_OK;
182}
183
184#endif /* TCL */
185#endif /* META */