]> git.saurik.com Git - apple/security.git/blob - SecurityASN1/c++/pkcs1oids.cpp
12eb16152cb1ab3db1cfdda31a92c54d86994f5c
[apple/security.git] / SecurityASN1 / c++ / pkcs1oids.cpp
1 // NOTE: this is a machine generated file--editing not recommended
2 //
3 // pkcs1oids.cpp - class member functions for ASN.1 module PKCS1-OIDS
4 //
5 // This file was generated by snacc on Wed Jun 27 16:40:55 2001
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
28 //------------------------------------------------------------------------------
29 // value defs
30
31
32 //------------------------------------------------------------------------------
33 // class member definitions:
34
35 RSAPublicKey::RSAPublicKey()
36 {
37 }
38
39 RSAPublicKey::RSAPublicKey (const RSAPublicKey &)
40 {
41 Asn1Error << "use of incompletely defined RSAPublicKey::RSAPublicKey (const RSAPublicKey &)" << endl;
42 abort();
43 }
44
45 RSAPublicKey::~RSAPublicKey()
46 {
47 }
48
49 AsnType *RSAPublicKey::Clone() const
50 {
51 return new RSAPublicKey;
52 }
53
54 AsnType *RSAPublicKey::Copy() const
55 {
56 return new RSAPublicKey (*this);
57 }
58
59 #if SNACC_DEEP_COPY
60 RSAPublicKey &RSAPublicKey::operator = (const RSAPublicKey &that)
61 #else // SNACC_DEEP_COPY
62 RSAPublicKey &RSAPublicKey::operator = (const RSAPublicKey &)
63 #endif // SNACC_DEEP_COPY
64 {
65 #if SNACC_DEEP_COPY
66 if (this != &that)
67 {
68 modulus = that.modulus;
69 publicExponent = that.publicExponent;
70 }
71
72 return *this;
73 #else // SNACC_DEEP_COPY
74 Asn1Error << "use of incompletely defined RSAPublicKey &RSAPublicKey::operator = (const RSAPublicKey &)" << endl;
75 abort();
76 // if your compiler complains here, check the -novolat option
77 #endif // SNACC_DEEP_COPY
78 }
79
80 AsnLen
81 RSAPublicKey::BEncContent (BUF_TYPE b)
82 {
83 AsnLen totalLen = 0;
84 AsnLen l;
85
86 l = publicExponent.BEncContent (b);
87 l += BEncDefLen (b, l);
88
89 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
90 totalLen += l;
91
92 l = modulus.BEncContent (b);
93 l += BEncDefLen (b, l);
94
95 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
96 totalLen += l;
97
98 return totalLen;
99 } // RSAPublicKey::BEncContent
100
101
102 void RSAPublicKey::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
103 {
104 AsnTag tag1;
105 AsnLen seqBytesDecoded = 0;
106 AsnLen elmtLen1;
107 tag1 = BDecTag (b, seqBytesDecoded, env);
108
109 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
110 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
111 {
112 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
113 modulus.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
114 tag1 = BDecTag (b, seqBytesDecoded, env);
115 }
116 else
117 {
118 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
119 longjmp (env, -100);
120 }
121
122 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
123 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
124 {
125 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
126 publicExponent.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
127 }
128 else
129 {
130 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
131 longjmp (env, -101);
132 }
133
134 bytesDecoded += seqBytesDecoded;
135 if (elmtLen0 == INDEFINITE_LEN)
136 {
137 BDecEoc (b, bytesDecoded, env);
138 return;
139 }
140 else if (seqBytesDecoded != elmtLen0)
141 {
142 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
143 longjmp (env, -102);
144 }
145 else
146 return;
147 } // RSAPublicKey::BDecContent
148
149 AsnLen RSAPublicKey::BEnc (BUF_TYPE b)
150 {
151 AsnLen l;
152 l = BEncContent (b);
153 l += BEncConsLen (b, l);
154 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
155 return l;
156 }
157
158 void RSAPublicKey::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
159 {
160 AsnTag tag;
161 AsnLen elmtLen1;
162
163 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
164 {
165 Asn1Error << "RSAPublicKey::BDec: ERROR - wrong tag" << endl;
166 longjmp (env, -103);
167 }
168 elmtLen1 = BDecLen (b, bytesDecoded, env);
169 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
170 }
171
172 int RSAPublicKey::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
173 {
174 bytesEncoded = BEnc (b);
175 return !b.WriteError();
176 }
177
178 int RSAPublicKey::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
179 {
180 ENV_TYPE env;
181 int val;
182
183 bytesDecoded = 0;
184 if ((val = setjmp (env)) == 0)
185 {
186 BDec (b, bytesDecoded, env);
187 return !b.ReadError();
188 }
189 else
190 return false;
191 }
192
193 void RSAPublicKey::Print (ostream &os) const
194 {
195 #ifndef NDEBUG
196 os << "{ -- SEQUENCE --" << endl;
197 indentG += stdIndentG;
198
199 {
200 Indent (os, indentG);
201 os << "modulus ";
202 os << modulus;
203 os << "," << endl;
204 }
205
206 {
207 Indent (os, indentG);
208 os << "publicExponent ";
209 os << publicExponent;
210 }
211
212 os << endl;
213 indentG -= stdIndentG;
214 Indent (os, indentG);
215 os << "}";
216 #endif /* NDEBUG */
217 } // RSAPublicKey::Print
218
219
220 RSAPrivateKey::RSAPrivateKey()
221 {
222 }
223
224 RSAPrivateKey::RSAPrivateKey (const RSAPrivateKey &)
225 {
226 Asn1Error << "use of incompletely defined RSAPrivateKey::RSAPrivateKey (const RSAPrivateKey &)" << endl;
227 abort();
228 }
229
230 RSAPrivateKey::~RSAPrivateKey()
231 {
232 }
233
234 AsnType *RSAPrivateKey::Clone() const
235 {
236 return new RSAPrivateKey;
237 }
238
239 AsnType *RSAPrivateKey::Copy() const
240 {
241 return new RSAPrivateKey (*this);
242 }
243
244 #if SNACC_DEEP_COPY
245 RSAPrivateKey &RSAPrivateKey::operator = (const RSAPrivateKey &that)
246 #else // SNACC_DEEP_COPY
247 RSAPrivateKey &RSAPrivateKey::operator = (const RSAPrivateKey &)
248 #endif // SNACC_DEEP_COPY
249 {
250 #if SNACC_DEEP_COPY
251 if (this != &that)
252 {
253 version = that.version;
254 modulus = that.modulus;
255 publicExponent = that.publicExponent;
256 privateExponent = that.privateExponent;
257 prime1 = that.prime1;
258 prime2 = that.prime2;
259 exponent1 = that.exponent1;
260 exponent2 = that.exponent2;
261 coefficient = that.coefficient;
262 }
263
264 return *this;
265 #else // SNACC_DEEP_COPY
266 Asn1Error << "use of incompletely defined RSAPrivateKey &RSAPrivateKey::operator = (const RSAPrivateKey &)" << endl;
267 abort();
268 // if your compiler complains here, check the -novolat option
269 #endif // SNACC_DEEP_COPY
270 }
271
272 AsnLen
273 RSAPrivateKey::BEncContent (BUF_TYPE b)
274 {
275 AsnLen totalLen = 0;
276 AsnLen l;
277
278 l = coefficient.BEncContent (b);
279 l += BEncDefLen (b, l);
280
281 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
282 totalLen += l;
283
284 l = exponent2.BEncContent (b);
285 l += BEncDefLen (b, l);
286
287 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
288 totalLen += l;
289
290 l = exponent1.BEncContent (b);
291 l += BEncDefLen (b, l);
292
293 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
294 totalLen += l;
295
296 l = prime2.BEncContent (b);
297 l += BEncDefLen (b, l);
298
299 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
300 totalLen += l;
301
302 l = prime1.BEncContent (b);
303 l += BEncDefLen (b, l);
304
305 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
306 totalLen += l;
307
308 l = privateExponent.BEncContent (b);
309 l += BEncDefLen (b, l);
310
311 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
312 totalLen += l;
313
314 l = publicExponent.BEncContent (b);
315 l += BEncDefLen (b, l);
316
317 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
318 totalLen += l;
319
320 l = modulus.BEncContent (b);
321 l += BEncDefLen (b, l);
322
323 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
324 totalLen += l;
325
326 l = version.BEncContent (b);
327 BEncDefLenTo127 (b, l);
328 l++;
329
330 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
331 totalLen += l;
332
333 return totalLen;
334 } // RSAPrivateKey::BEncContent
335
336
337 void RSAPrivateKey::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
338 {
339 AsnTag tag1;
340 AsnLen seqBytesDecoded = 0;
341 AsnLen elmtLen1;
342 tag1 = BDecTag (b, seqBytesDecoded, env);
343
344 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
345 {
346 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
347 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
348 tag1 = BDecTag (b, seqBytesDecoded, env);
349 }
350 else
351 {
352 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
353 longjmp (env, -104);
354 }
355
356 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
357 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
358 {
359 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
360 modulus.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
361 tag1 = BDecTag (b, seqBytesDecoded, env);
362 }
363 else
364 {
365 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
366 longjmp (env, -105);
367 }
368
369 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
370 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
371 {
372 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
373 publicExponent.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
374 tag1 = BDecTag (b, seqBytesDecoded, env);
375 }
376 else
377 {
378 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
379 longjmp (env, -106);
380 }
381
382 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
383 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
384 {
385 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
386 privateExponent.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
387 tag1 = BDecTag (b, seqBytesDecoded, env);
388 }
389 else
390 {
391 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
392 longjmp (env, -107);
393 }
394
395 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
396 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
397 {
398 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
399 prime1.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
400 tag1 = BDecTag (b, seqBytesDecoded, env);
401 }
402 else
403 {
404 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
405 longjmp (env, -108);
406 }
407
408 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
409 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
410 {
411 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
412 prime2.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
413 tag1 = BDecTag (b, seqBytesDecoded, env);
414 }
415 else
416 {
417 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
418 longjmp (env, -109);
419 }
420
421 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
422 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
423 {
424 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
425 exponent1.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
426 tag1 = BDecTag (b, seqBytesDecoded, env);
427 }
428 else
429 {
430 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
431 longjmp (env, -110);
432 }
433
434 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
435 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
436 {
437 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
438 exponent2.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
439 tag1 = BDecTag (b, seqBytesDecoded, env);
440 }
441 else
442 {
443 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
444 longjmp (env, -111);
445 }
446
447 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
448 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
449 {
450 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
451 coefficient.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
452 }
453 else
454 {
455 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
456 longjmp (env, -112);
457 }
458
459 bytesDecoded += seqBytesDecoded;
460 if (elmtLen0 == INDEFINITE_LEN)
461 {
462 BDecEoc (b, bytesDecoded, env);
463 return;
464 }
465 else if (seqBytesDecoded != elmtLen0)
466 {
467 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
468 longjmp (env, -113);
469 }
470 else
471 return;
472 } // RSAPrivateKey::BDecContent
473
474 AsnLen RSAPrivateKey::BEnc (BUF_TYPE b)
475 {
476 AsnLen l;
477 l = BEncContent (b);
478 l += BEncConsLen (b, l);
479 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
480 return l;
481 }
482
483 void RSAPrivateKey::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
484 {
485 AsnTag tag;
486 AsnLen elmtLen1;
487
488 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
489 {
490 Asn1Error << "RSAPrivateKey::BDec: ERROR - wrong tag" << endl;
491 longjmp (env, -114);
492 }
493 elmtLen1 = BDecLen (b, bytesDecoded, env);
494 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
495 }
496
497 int RSAPrivateKey::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
498 {
499 bytesEncoded = BEnc (b);
500 return !b.WriteError();
501 }
502
503 int RSAPrivateKey::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
504 {
505 ENV_TYPE env;
506 int val;
507
508 bytesDecoded = 0;
509 if ((val = setjmp (env)) == 0)
510 {
511 BDec (b, bytesDecoded, env);
512 return !b.ReadError();
513 }
514 else
515 return false;
516 }
517
518 void RSAPrivateKey::Print (ostream &os) const
519 {
520 #ifndef NDEBUG
521 os << "{ -- SEQUENCE --" << endl;
522 indentG += stdIndentG;
523
524 {
525 Indent (os, indentG);
526 os << "version ";
527 os << version;
528 os << "," << endl;
529 }
530
531 {
532 Indent (os, indentG);
533 os << "modulus ";
534 os << modulus;
535 os << "," << endl;
536 }
537
538 {
539 Indent (os, indentG);
540 os << "publicExponent ";
541 os << publicExponent;
542 os << "," << endl;
543 }
544
545 {
546 Indent (os, indentG);
547 os << "privateExponent ";
548 os << privateExponent;
549 os << "," << endl;
550 }
551
552 {
553 Indent (os, indentG);
554 os << "prime1 ";
555 os << prime1;
556 os << "," << endl;
557 }
558
559 {
560 Indent (os, indentG);
561 os << "prime2 ";
562 os << prime2;
563 os << "," << endl;
564 }
565
566 {
567 Indent (os, indentG);
568 os << "exponent1 ";
569 os << exponent1;
570 os << "," << endl;
571 }
572
573 {
574 Indent (os, indentG);
575 os << "exponent2 ";
576 os << exponent2;
577 os << "," << endl;
578 }
579
580 {
581 Indent (os, indentG);
582 os << "coefficient ";
583 os << coefficient;
584 }
585
586 os << endl;
587 indentG -= stdIndentG;
588 Indent (os, indentG);
589 os << "}";
590 #endif /* NDEBUG */
591 } // RSAPrivateKey::Print
592
593