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