]> git.saurik.com Git - apple/security.git/blob - SecurityASN1/c++/pkcs7.cpp
925396fc376e84a67aeb06c75ca5ea8fbdfdebe0
[apple/security.git] / SecurityASN1 / c++ / pkcs7.cpp
1 // NOTE: this is a machine generated file--editing not recommended
2 //
3 // pkcs7.cpp - class member functions for ASN.1 module PKCS7
4 //
5 // This file was generated by snacc on Mon Apr 22 22:34:19 2002
6 // UBC snacc written by Mike Sample
7 // A couple of enhancements made by IBM European Networking Center
8
9
10 #include "asn-incl.h"
11 #include "sm_vdatypes.h"
12 #include "sm_x501ud.h"
13 #include "sm_x411ub.h"
14 #include "sm_x411mtsas.h"
15 #include "sm_x501if.h"
16 #include "sm_x520sa.h"
17 #include "sm_x509cmn.h"
18 #include "sm_x509af.h"
19 #include "sm_x509ce.h"
20 #include "pkcs1oids.h"
21 #include "pkcs9oids.h"
22 #include "sm_cms.h"
23 #include "sm_ess.h"
24 #include "pkcs7.h"
25 #include "pkcs8.h"
26 #include "appleoids.h"
27 #include "pkcs10.h"
28
29 //------------------------------------------------------------------------------
30 // value defs
31
32
33 //------------------------------------------------------------------------------
34 // class member definitions:
35
36 EncryptedContentInfo1::EncryptedContentInfo1()
37 {
38 #if TCL
39 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier1;
40 #else
41 contentEncryptionAlgorithm = NULL; // incomplete initialization of mandatory element!
42 #endif // TCL
43 encryptedContent = NULL;
44 }
45
46 EncryptedContentInfo1::EncryptedContentInfo1 (const EncryptedContentInfo1 &)
47 {
48 Asn1Error << "use of incompletely defined EncryptedContentInfo1::EncryptedContentInfo1 (const EncryptedContentInfo1 &)" << endl;
49 abort();
50 }
51
52 EncryptedContentInfo1::~EncryptedContentInfo1()
53 {
54 delete contentEncryptionAlgorithm;
55 delete encryptedContent;
56 }
57
58 AsnType *EncryptedContentInfo1::Clone() const
59 {
60 return new EncryptedContentInfo1;
61 }
62
63 AsnType *EncryptedContentInfo1::Copy() const
64 {
65 return new EncryptedContentInfo1 (*this);
66 }
67
68 #if SNACC_DEEP_COPY
69 EncryptedContentInfo1 &EncryptedContentInfo1::operator = (const EncryptedContentInfo1 &that)
70 #else // SNACC_DEEP_COPY
71 EncryptedContentInfo1 &EncryptedContentInfo1::operator = (const EncryptedContentInfo1 &)
72 #endif // SNACC_DEEP_COPY
73 {
74 #if SNACC_DEEP_COPY
75 if (this != &that)
76 {
77 contentType = that.contentType;
78 if (that.contentEncryptionAlgorithm)
79 {
80 if (!contentEncryptionAlgorithm)
81 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier1;
82 *contentEncryptionAlgorithm = *that.contentEncryptionAlgorithm;
83 }
84 else
85 {
86 delete contentEncryptionAlgorithm;
87 contentEncryptionAlgorithm = NULL;
88 }
89 if (that.encryptedContent)
90 {
91 if (!encryptedContent)
92 encryptedContent = new EncryptedContent1;
93 *encryptedContent = *that.encryptedContent;
94 }
95 else
96 {
97 delete encryptedContent;
98 encryptedContent = NULL;
99 }
100 }
101
102 return *this;
103 #else // SNACC_DEEP_COPY
104 Asn1Error << "use of incompletely defined EncryptedContentInfo1 &EncryptedContentInfo1::operator = (const EncryptedContentInfo1 &)" << endl;
105 abort();
106 // if your compiler complains here, check the -novolat option
107 #endif // SNACC_DEEP_COPY
108 }
109
110 AsnLen
111 EncryptedContentInfo1::BEncContent (BUF_TYPE b)
112 {
113 AsnLen totalLen = 0;
114 AsnLen l;
115
116 if (NOT_NULL (encryptedContent))
117 {
118 l = encryptedContent->BEncContent (b);
119 l += BEncDefLen (b, l);
120
121 l += BEncTag1 (b, CNTX, PRIM, 0);
122 totalLen += l;
123 }
124
125 BEncEocIfNec (b);
126 l = contentEncryptionAlgorithm->BEncContent (b);
127 l += BEncConsLen (b, l);
128
129 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
130 totalLen += l;
131
132 l = contentType.BEncContent (b);
133 l += BEncDefLen (b, l);
134
135 l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
136 totalLen += l;
137
138 return totalLen;
139 } // EncryptedContentInfo1::BEncContent
140
141
142 void EncryptedContentInfo1::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
143 {
144 AsnTag tag1;
145 AsnLen seqBytesDecoded = 0;
146 AsnLen elmtLen1;
147 tag1 = BDecTag (b, seqBytesDecoded, env);
148
149 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
150 {
151 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
152 contentType.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
153 tag1 = BDecTag (b, seqBytesDecoded, env);
154 }
155 else
156 {
157 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
158 SnaccExcep::throwMe(-100);
159 }
160
161 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
162 {
163 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
164 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier1;
165 contentEncryptionAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
166 if (seqBytesDecoded == elmtLen0)
167 {
168 bytesDecoded += seqBytesDecoded;
169 return;
170 }
171 else
172 {
173 tag1 = BDecTag (b, seqBytesDecoded, env);
174
175 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
176 {
177 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
178 bytesDecoded += seqBytesDecoded;
179 return;
180 }
181 }
182 }
183 else
184 {
185 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
186 SnaccExcep::throwMe(-101);
187 }
188
189 if ((tag1 == MAKE_TAG_ID (CNTX, PRIM, 0))
190 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
191 {
192 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
193 encryptedContent = new EncryptedContent1;
194 encryptedContent->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
195 }
196
197 bytesDecoded += seqBytesDecoded;
198 if (elmtLen0 == INDEFINITE_LEN)
199 {
200 BDecEoc (b, bytesDecoded, env);
201 return;
202 }
203 else if (seqBytesDecoded != elmtLen0)
204 {
205 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
206 SnaccExcep::throwMe(-102);
207 }
208 else
209 return;
210 } // EncryptedContentInfo1::BDecContent
211
212 AsnLen EncryptedContentInfo1::BEnc (BUF_TYPE b)
213 {
214 AsnLen l;
215 l = BEncContent (b);
216 l += BEncConsLen (b, l);
217 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
218 return l;
219 }
220
221 void EncryptedContentInfo1::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
222 {
223 AsnTag tag;
224 AsnLen elmtLen1;
225
226 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
227 {
228 Asn1Error << "EncryptedContentInfo1::BDec: ERROR - wrong tag" << endl;
229 SnaccExcep::throwMe(-103);
230 }
231 elmtLen1 = BDecLen (b, bytesDecoded, env);
232 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
233 }
234
235 void EncryptedContentInfo1::Print (ostream &os) const
236 {
237 #ifndef NDEBUG
238 os << "{ -- SEQUENCE --" << endl;
239 indentG += stdIndentG;
240
241 {
242 Indent (os, indentG);
243 os << "contentType ";
244 os << contentType;
245 os << "," << endl;
246 }
247
248 if (NOT_NULL (contentEncryptionAlgorithm))
249 {
250 Indent (os, indentG);
251 os << "contentEncryptionAlgorithm ";
252 os << *contentEncryptionAlgorithm;
253 }
254 else
255 {
256 Indent (os, indentG);
257 os << "contentEncryptionAlgorithm ";
258 os << "-- void --";
259 os << "," << endl;
260 }
261
262 if (NOT_NULL (encryptedContent))
263 {
264 os << ","<< endl;
265 Indent (os, indentG);
266 os << "encryptedContent ";
267 os << *encryptedContent;
268 }
269 else
270 {
271 Indent (os, indentG);
272 os << "encryptedContent ";
273 os << "-- void --";
274 os << endl;
275 }
276
277 os << endl;
278 indentG -= stdIndentG;
279 Indent (os, indentG);
280 os << "}";
281 #endif /* NDEBUG */
282 } // EncryptedContentInfo1::Print
283
284
285 EncryptedData1::EncryptedData1()
286 {
287 #if TCL
288 encryptedContentInfo = new EncryptedContentInfo1;
289 #else
290 encryptedContentInfo = NULL; // incomplete initialization of mandatory element!
291 #endif // TCL
292 }
293
294 EncryptedData1::EncryptedData1 (const EncryptedData1 &)
295 {
296 Asn1Error << "use of incompletely defined EncryptedData1::EncryptedData1 (const EncryptedData1 &)" << endl;
297 abort();
298 }
299
300 EncryptedData1::~EncryptedData1()
301 {
302 delete encryptedContentInfo;
303 }
304
305 AsnType *EncryptedData1::Clone() const
306 {
307 return new EncryptedData1;
308 }
309
310 AsnType *EncryptedData1::Copy() const
311 {
312 return new EncryptedData1 (*this);
313 }
314
315 #if SNACC_DEEP_COPY
316 EncryptedData1 &EncryptedData1::operator = (const EncryptedData1 &that)
317 #else // SNACC_DEEP_COPY
318 EncryptedData1 &EncryptedData1::operator = (const EncryptedData1 &)
319 #endif // SNACC_DEEP_COPY
320 {
321 #if SNACC_DEEP_COPY
322 if (this != &that)
323 {
324 version = that.version;
325 if (that.encryptedContentInfo)
326 {
327 if (!encryptedContentInfo)
328 encryptedContentInfo = new EncryptedContentInfo1;
329 *encryptedContentInfo = *that.encryptedContentInfo;
330 }
331 else
332 {
333 delete encryptedContentInfo;
334 encryptedContentInfo = NULL;
335 }
336 }
337
338 return *this;
339 #else // SNACC_DEEP_COPY
340 Asn1Error << "use of incompletely defined EncryptedData1 &EncryptedData1::operator = (const EncryptedData1 &)" << endl;
341 abort();
342 // if your compiler complains here, check the -novolat option
343 #endif // SNACC_DEEP_COPY
344 }
345
346 AsnLen
347 EncryptedData1::BEncContent (BUF_TYPE b)
348 {
349 AsnLen totalLen = 0;
350 AsnLen l;
351
352 BEncEocIfNec (b);
353 l = encryptedContentInfo->BEncContent (b);
354 l += BEncConsLen (b, l);
355
356 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
357 totalLen += l;
358
359 l = version.BEncContent (b);
360 BEncDefLenTo127 (b, l);
361 l++;
362
363 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
364 totalLen += l;
365
366 return totalLen;
367 } // EncryptedData1::BEncContent
368
369
370 void EncryptedData1::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
371 {
372 AsnTag tag1;
373 AsnLen seqBytesDecoded = 0;
374 AsnLen elmtLen1;
375 tag1 = BDecTag (b, seqBytesDecoded, env);
376
377 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
378 {
379 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
380 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
381 tag1 = BDecTag (b, seqBytesDecoded, env);
382 }
383 else
384 {
385 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
386 SnaccExcep::throwMe(-104);
387 }
388
389 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
390 {
391 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
392 encryptedContentInfo = new EncryptedContentInfo1;
393 encryptedContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
394 }
395 else
396 {
397 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
398 SnaccExcep::throwMe(-105);
399 }
400
401 bytesDecoded += seqBytesDecoded;
402 if (elmtLen0 == INDEFINITE_LEN)
403 {
404 BDecEoc (b, bytesDecoded, env);
405 return;
406 }
407 else if (seqBytesDecoded != elmtLen0)
408 {
409 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
410 SnaccExcep::throwMe(-106);
411 }
412 else
413 return;
414 } // EncryptedData1::BDecContent
415
416 AsnLen EncryptedData1::BEnc (BUF_TYPE b)
417 {
418 AsnLen l;
419 l = BEncContent (b);
420 l += BEncConsLen (b, l);
421 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
422 return l;
423 }
424
425 void EncryptedData1::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
426 {
427 AsnTag tag;
428 AsnLen elmtLen1;
429
430 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
431 {
432 Asn1Error << "EncryptedData1::BDec: ERROR - wrong tag" << endl;
433 SnaccExcep::throwMe(-107);
434 }
435 elmtLen1 = BDecLen (b, bytesDecoded, env);
436 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
437 }
438
439 void EncryptedData1::Print (ostream &os) const
440 {
441 #ifndef NDEBUG
442 os << "{ -- SEQUENCE --" << endl;
443 indentG += stdIndentG;
444
445 {
446 Indent (os, indentG);
447 os << "version ";
448 os << version;
449 os << "," << endl;
450 }
451
452 if (NOT_NULL (encryptedContentInfo))
453 {
454 Indent (os, indentG);
455 os << "encryptedContentInfo ";
456 os << *encryptedContentInfo;
457 }
458 else
459 {
460 Indent (os, indentG);
461 os << "encryptedContentInfo ";
462 os << "-- void --";
463 os << endl;
464 }
465
466 os << endl;
467 indentG -= stdIndentG;
468 Indent (os, indentG);
469 os << "}";
470 #endif /* NDEBUG */
471 } // EncryptedData1::Print
472
473