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