]> git.saurik.com Git - apple/security.git/blob - SecurityASN1/c++/sm_cms.cpp
Security-30.1.tar.gz
[apple/security.git] / SecurityASN1 / c++ / sm_cms.cpp
1 // NOTE: this is a machine generated file--editing not recommended
2 //
3 // sm_cms.cpp - class member functions for ASN.1 module CryptographicMessageSyntax
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 OriginatorPublicKey::OriginatorPublicKey()
36 {
37 #if TCL
38 algorithm = new AlgorithmIdentifier;
39 #else
40 algorithm = NULL; // incomplete initialization of mandatory element!
41 #endif // TCL
42 }
43
44 OriginatorPublicKey::OriginatorPublicKey (const OriginatorPublicKey &)
45 {
46 Asn1Error << "use of incompletely defined OriginatorPublicKey::OriginatorPublicKey (const OriginatorPublicKey &)" << endl;
47 abort();
48 }
49
50 OriginatorPublicKey::~OriginatorPublicKey()
51 {
52 delete algorithm;
53 }
54
55 AsnType *OriginatorPublicKey::Clone() const
56 {
57 return new OriginatorPublicKey;
58 }
59
60 AsnType *OriginatorPublicKey::Copy() const
61 {
62 return new OriginatorPublicKey (*this);
63 }
64
65 #if SNACC_DEEP_COPY
66 OriginatorPublicKey &OriginatorPublicKey::operator = (const OriginatorPublicKey &that)
67 #else // SNACC_DEEP_COPY
68 OriginatorPublicKey &OriginatorPublicKey::operator = (const OriginatorPublicKey &)
69 #endif // SNACC_DEEP_COPY
70 {
71 #if SNACC_DEEP_COPY
72 if (this != &that)
73 {
74 if (that.algorithm)
75 {
76 if (!algorithm)
77 algorithm = new AlgorithmIdentifier;
78 *algorithm = *that.algorithm;
79 }
80 else
81 {
82 delete algorithm;
83 algorithm = NULL;
84 }
85 publicKey = that.publicKey;
86 }
87
88 return *this;
89 #else // SNACC_DEEP_COPY
90 Asn1Error << "use of incompletely defined OriginatorPublicKey &OriginatorPublicKey::operator = (const OriginatorPublicKey &)" << endl;
91 abort();
92 // if your compiler complains here, check the -novolat option
93 #endif // SNACC_DEEP_COPY
94 }
95
96 AsnLen
97 OriginatorPublicKey::BEncContent (BUF_TYPE b)
98 {
99 AsnLen totalLen = 0;
100 AsnLen l;
101
102 l = publicKey.BEncContent (b);
103 l += BEncDefLen (b, l);
104
105 l += BEncTag1 (b, UNIV, PRIM, BITSTRING_TAG_CODE);
106 totalLen += l;
107
108 BEncEocIfNec (b);
109 l = algorithm->BEncContent (b);
110 l += BEncConsLen (b, l);
111
112 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
113 totalLen += l;
114
115 return totalLen;
116 } // OriginatorPublicKey::BEncContent
117
118
119 void OriginatorPublicKey::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
120 {
121 AsnTag tag1;
122 AsnLen seqBytesDecoded = 0;
123 AsnLen elmtLen1;
124 tag1 = BDecTag (b, seqBytesDecoded, env);
125
126 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
127 {
128 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
129 algorithm = new AlgorithmIdentifier;
130 algorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
131 tag1 = BDecTag (b, seqBytesDecoded, env);
132 }
133 else
134 {
135 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
136 longjmp (env, -100);
137 }
138
139 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE))
140 || (tag1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))
141 {
142 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
143 publicKey.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
144 }
145 else
146 {
147 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
148 longjmp (env, -101);
149 }
150
151 bytesDecoded += seqBytesDecoded;
152 if (elmtLen0 == INDEFINITE_LEN)
153 {
154 BDecEoc (b, bytesDecoded, env);
155 return;
156 }
157 else if (seqBytesDecoded != elmtLen0)
158 {
159 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
160 longjmp (env, -102);
161 }
162 else
163 return;
164 } // OriginatorPublicKey::BDecContent
165
166 AsnLen OriginatorPublicKey::BEnc (BUF_TYPE b)
167 {
168 AsnLen l;
169 l = BEncContent (b);
170 l += BEncConsLen (b, l);
171 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
172 return l;
173 }
174
175 void OriginatorPublicKey::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
176 {
177 AsnTag tag;
178 AsnLen elmtLen1;
179
180 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
181 {
182 Asn1Error << "OriginatorPublicKey::BDec: ERROR - wrong tag" << endl;
183 longjmp (env, -103);
184 }
185 elmtLen1 = BDecLen (b, bytesDecoded, env);
186 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
187 }
188
189 int OriginatorPublicKey::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
190 {
191 bytesEncoded = BEnc (b);
192 return !b.WriteError();
193 }
194
195 int OriginatorPublicKey::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
196 {
197 ENV_TYPE env;
198 int val;
199
200 bytesDecoded = 0;
201 if ((val = setjmp (env)) == 0)
202 {
203 BDec (b, bytesDecoded, env);
204 return !b.ReadError();
205 }
206 else
207 return false;
208 }
209
210 void OriginatorPublicKey::Print (ostream &os) const
211 {
212 #ifndef NDEBUG
213 os << "{ -- SEQUENCE --" << endl;
214 indentG += stdIndentG;
215
216 if (NOT_NULL (algorithm))
217 {
218 Indent (os, indentG);
219 os << "algorithm ";
220 os << *algorithm;
221 }
222 else
223 {
224 Indent (os, indentG);
225 os << "algorithm ";
226 os << "-- void --";
227 os << "," << endl;
228 }
229
230 {
231 Indent (os, indentG);
232 os << "publicKey ";
233 os << publicKey;
234 }
235
236 os << endl;
237 indentG -= stdIndentG;
238 Indent (os, indentG);
239 os << "}";
240 #endif /* NDEBUG */
241 } // OriginatorPublicKey::Print
242
243
244 AsnType *CertificateRevocationLists::Clone() const
245 {
246 return new CertificateRevocationLists;
247 }
248
249 AsnType *CertificateRevocationLists::Copy() const
250 {
251 return new CertificateRevocationLists (*this);
252 }
253
254 AsnLen CertificateRevocationLists::BEnc (BUF_TYPE b)
255 {
256 AsnLen l;
257 l = BEncContent (b);
258 l += BEncConsLen (b, l);
259 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
260 return l;
261 }
262
263 void CertificateRevocationLists::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
264 {
265 AsnTag tag;
266 AsnLen elmtLen1;
267
268 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
269 {
270 Asn1Error << "CertificateRevocationLists::BDec: ERROR - wrong tag" << endl;
271 longjmp (env, -104);
272 }
273 elmtLen1 = BDecLen (b, bytesDecoded, env);
274 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
275 }
276
277 CertificateRevocationLists::CertificateRevocationLists (const CertificateRevocationLists &)
278 {
279 Asn1Error << "use of incompletely defined CertificateRevocationLists::CertificateRevocationLists (const CertificateRevocationLists &)" << endl;
280 abort();
281 }
282
283 CertificateRevocationLists::~CertificateRevocationLists()
284 {
285 SetCurrToFirst();
286 for (; Curr() != NULL; RemoveCurrFromList())
287 ;
288 } // end of destructor
289
290 #if SNACC_DEEP_COPY
291 CertificateRevocationLists &CertificateRevocationLists::operator = (const CertificateRevocationLists &that)
292 #else // SNACC_DEEP_COPY
293 CertificateRevocationLists &CertificateRevocationLists::operator = (const CertificateRevocationLists &)
294 #endif // SNACC_DEEP_COPY
295 {
296 #if SNACC_DEEP_COPY
297 if (this != &that)
298 {
299 SetCurrToFirst();
300 for (; Curr(); RemoveCurrFromList())
301 ;
302
303 //that.SetCurrToFirst();
304 //for (; that.Curr(); that.GoNext())
305 // AppendCopy (*that.Curr());
306 for (const AsnListElmt *run=that.first; run; run=run->next)
307 AppendCopy (*run->elmt);
308 }
309
310 return *this;
311 #else // SNACC_DEEP_COPY
312 Asn1Error << "use of incompletely defined CertificateRevocationLists &CertificateRevocationLists::operator = (const CertificateRevocationLists &)" << endl;
313 abort();
314 // if your compiler complains here, check the -novolat option
315 #endif // SNACC_DEEP_COPY
316 }
317
318 void CertificateRevocationLists::Print (ostream &os) const
319 {
320 #ifndef NDEBUG
321 os << "{ -- SEQUENCE/SET OF -- " << endl;
322 indentG += stdIndentG;
323 //SetCurrToFirst();
324 //for (; Curr() != NULL; GoNext())
325 for (const AsnListElmt *run=first; run; run=run->next)
326 {
327 Indent (os, indentG);
328 //os << *Curr();
329 os << *run->elmt;
330 //if (Curr() != Last())
331 if (run != last)
332 os << ",";
333 os << endl;
334 }
335 indentG -= stdIndentG;
336 Indent (os, indentG);
337 os << "}\n";
338 #endif /* NDEBUG */
339
340
341 } // Print
342
343
344 void CertificateRevocationLists::SetCurrElmt (unsigned long int index)
345 {
346 unsigned long int i;
347 curr = first;
348 if (count)
349 for (i = 0; (i < (count-1)) && (i < index); i++)
350 curr = curr->next;
351 } // CertificateRevocationLists::SetCurrElmt
352
353
354 unsigned long int CertificateRevocationLists::GetCurrElmtIndex()
355 {
356 unsigned long int i;
357 AsnListElmt *tmp;
358 if (curr != NULL)
359 {
360 for (i = 0, tmp = first; tmp != NULL; i++)
361 {
362 if (tmp == curr)
363 return i;
364 else
365 tmp = tmp->next;
366 }
367 }
368 return count;
369 } // CertificateRevocationLists::GetCurrElmtIndex
370
371
372 // alloc new list elmt, put at end of list
373 // and return the component type
374 CertificateList *CertificateRevocationLists::Append()
375 {
376 AsnListElmt *newElmt;
377 newElmt = new AsnListElmt;
378 newElmt->elmt = new CertificateList;
379 newElmt->next = NULL;
380 if (last == NULL)
381 {
382 newElmt->prev = NULL;
383 first = last = newElmt;
384 }
385 else
386 {
387 newElmt->prev = last;
388 last->next = newElmt;
389 last = newElmt;
390 }
391 count++;
392 return (curr = newElmt)->elmt;
393 } // CertificateRevocationLists::Append
394
395
396 // alloc new list elmt, put at begining of list
397 // and return the component type
398 CertificateList *CertificateRevocationLists::Prepend()
399 {
400 AsnListElmt *newElmt;
401 newElmt = new AsnListElmt;
402 newElmt->elmt = new CertificateList;
403 newElmt->prev = NULL;
404 if (first == NULL)
405 {
406 newElmt->next = NULL;
407 first = last = newElmt;
408 }
409 else
410 {
411 newElmt->next = first;
412 first->prev = newElmt;
413 first = newElmt;
414 }
415 count++;
416 return (curr = newElmt)->elmt;
417 } // CertificateRevocationLists::Prepend
418
419
420 // alloc new list elmt, insert it before the
421 // current element and return the component type
422 // if the current element is null, the new element
423 // is placed at the beginning of the list.
424 CertificateList *CertificateRevocationLists::InsertBefore()
425 {
426 AsnListElmt *newElmt;
427 newElmt = new AsnListElmt;
428 newElmt->elmt = new CertificateList;
429 if (curr == NULL)
430 {
431 newElmt->next = first;
432 newElmt->prev = NULL;
433 first = newElmt;
434 if (last == NULL)
435 last = newElmt;
436 }
437 else
438 {
439 newElmt->next = curr;
440 newElmt->prev = curr->prev;
441 curr->prev = newElmt;
442 if (curr == first)
443 first = newElmt;
444 else
445 newElmt->prev->next = newElmt;
446 }
447 count++;
448 return (curr = newElmt)->elmt;
449 } // CertificateRevocationLists::InsertBefore
450
451
452 // alloc new list elmt, insert it after the
453 // current element and return the component type
454 // if the current element is null, the new element
455 // is placed at the end of the list.
456 CertificateList *CertificateRevocationLists::InsertAfter()
457 {
458 AsnListElmt *newElmt;
459 newElmt = new AsnListElmt;
460 newElmt->elmt = new CertificateList;
461 if (curr == NULL)
462 {
463 newElmt->prev = last;
464 newElmt->next = NULL;
465 last = newElmt;
466 if (first == NULL)
467 first = newElmt;
468 }
469 else
470 {
471 newElmt->prev = curr;
472 newElmt->next = curr->next;
473 curr->next = newElmt;
474 if (curr == last)
475 last = newElmt;
476 else
477 newElmt->next->prev = newElmt;
478 }
479 count++;
480 return (curr = newElmt)->elmt;
481 } // CertificateRevocationLists::InsertAfter
482
483
484 CertificateRevocationLists &CertificateRevocationLists::AppendCopy (CertificateList &elmt)
485 {
486 AsnListElmt *newElmt;
487 newElmt = new AsnListElmt;
488 newElmt->elmt = new CertificateList;
489 *newElmt->elmt = elmt;
490 newElmt->next = NULL;
491 if (last == NULL)
492 {
493 newElmt->prev = NULL;
494 first = last = newElmt;
495 }
496 else
497 {
498 newElmt->prev = last;
499 last->next = newElmt;
500 last = newElmt;
501 }
502 count++;
503 return *this;
504 } // AppendCopy
505
506
507 CertificateRevocationLists &CertificateRevocationLists::PrependCopy (CertificateList &elmt)
508 {
509 AsnListElmt *newElmt;
510 newElmt = new AsnListElmt;
511 newElmt->elmt = new CertificateList;
512 *newElmt->elmt = elmt;
513 newElmt->prev = NULL;
514 if (first == NULL)
515 {
516 newElmt->next = NULL;
517 first = last = newElmt;
518 }
519 else
520 {
521 newElmt->next = first;
522 first->prev = newElmt;
523 first = newElmt;
524 }
525 count++;
526 return *this;
527 } // CertificateRevocationLists::PrependCopy
528
529
530 // alloc new list elmt, insert it before the
531 // current element, copy the given elmt into the new elmt
532 // and return the component type.
533 // if the current element is null, the new element
534 // is placed at the beginning of the list.
535 CertificateRevocationLists &CertificateRevocationLists::InsertBeforeAndCopy (CertificateList &elmt)
536 {
537 AsnListElmt *newElmt;
538
539 newElmt = new AsnListElmt;
540 newElmt->elmt = new CertificateList;
541 *newElmt->elmt = elmt;
542
543 if (curr == NULL)
544 {
545 newElmt->next = first;
546 newElmt->prev = NULL;
547 first = newElmt;
548 if (last == NULL)
549 last = newElmt;
550 }
551 else
552 {
553 newElmt->next = curr;
554 newElmt->prev = curr->prev;
555 curr->prev = newElmt;
556 if (curr == first)
557 first = newElmt;
558 else
559 newElmt->prev->next = newElmt;
560 }
561 count++;
562 return *this;
563 } // CertificateRevocationLists::InsertBeforeAndCopy
564
565
566 // alloc new list elmt, insert it after the
567 // current element, copy given elmt in to new elmt
568 // and return the component type
569 // if the current element is null, the new element
570 // is placed at the end of the list.
571 CertificateRevocationLists &CertificateRevocationLists::InsertAfterAndCopy (CertificateList &elmt)
572 {
573 AsnListElmt *newElmt;
574
575 newElmt = new AsnListElmt;
576 newElmt->elmt = new CertificateList;
577 *newElmt->elmt = elmt;
578 if (curr == NULL)
579 {
580 newElmt->prev = last;
581 newElmt->next = NULL;
582 last = newElmt;
583 if (first == NULL)
584 first = newElmt;
585 }
586 else
587 {
588 newElmt->prev = curr;
589 newElmt->next = curr->next;
590 curr->next = newElmt;
591 if (curr == last)
592 last = newElmt;
593 else
594 newElmt->next->prev = newElmt;
595 }
596 count++;
597 return *this;
598 } // CertificateRevocationLists::InsertAfterAndCopy
599
600
601 // remove current element from list if current element is not NULL
602 // The new current element will be the next element.
603 // If the current element is the last element in the list
604 // the second but last element will become the new current element.
605 void CertificateRevocationLists::RemoveCurrFromList()
606 {
607 AsnListElmt *del_elmt;
608
609 if (curr != NULL)
610 {
611 del_elmt = curr;
612 count--;
613
614 if (count == 0)
615 first = last = curr = NULL;
616 else if (curr == first)
617 {
618 curr = first= first->next;
619 first->prev = NULL;
620 }
621 else if (curr == last)
622 {
623 curr = last = last->prev;
624 last->next = NULL;
625 }
626 else
627 {
628 curr->prev->next = curr->next;
629 curr->next->prev = curr->prev;
630 }
631
632 delete del_elmt->elmt;
633 delete del_elmt;
634 }
635 }
636
637
638 AsnLen CertificateRevocationLists::BEncContent (BUF_TYPE b)
639 {
640 AsnListElmt *currElmt;
641 AsnLen elmtLen;
642 AsnLen totalLen = 0;
643 {
644 int iii,icount;
645 CSM_Buffer **tmpEnc=NULL;
646 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
647 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
648 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
649 {
650 BEncEocIfNec (b);
651 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
652 elmtLen += BEncConsLen (outputBuf, elmtLen);
653
654 elmtLen += BEncTag1 (outputBuf, UNIV, CONS, SEQ_TAG_CODE);
655 ENCODE_BUF2(tmpEnc[iii]);
656 }
657 vdasnacc_sortSetOf(tmpEnc, icount);
658 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
659 SM_WriteToAsnBuf(tmpEnc[iii], b);
660 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
661 free(tmpEnc);
662 }
663 totalLen += elmtLen;
664 return totalLen;
665 } // CertificateRevocationLists::BEncContent
666
667
668 void CertificateRevocationLists::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
669 AsnLen &bytesDecoded, ENV_TYPE env)
670 {
671 CertificateList *listElmt;
672 AsnTag tag1;
673 AsnLen listBytesDecoded = 0;
674 AsnLen elmtLen1;
675
676 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
677 {
678 tag1 = BDecTag (b, listBytesDecoded, env);
679 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
680 {
681 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
682 break;
683 }
684 if ((tag1 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
685 {
686 Asn1Error << "Unexpected Tag" << endl;
687 longjmp (env, -105);
688 }
689
690 elmtLen1 = BDecLen (b, listBytesDecoded, env);
691 listElmt = Append();
692 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
693 }
694
695 bytesDecoded += listBytesDecoded;
696 } // CertificateRevocationLists::BDecContent
697
698
699 IssuerAndSerialNumber::IssuerAndSerialNumber()
700 {
701 #if TCL
702 issuer = new Name;
703 #else
704 issuer = NULL; // incomplete initialization of mandatory element!
705 #endif // TCL
706 }
707
708 IssuerAndSerialNumber::IssuerAndSerialNumber (const IssuerAndSerialNumber &)
709 {
710 Asn1Error << "use of incompletely defined IssuerAndSerialNumber::IssuerAndSerialNumber (const IssuerAndSerialNumber &)" << endl;
711 abort();
712 }
713
714 IssuerAndSerialNumber::~IssuerAndSerialNumber()
715 {
716 delete issuer;
717 }
718
719 AsnType *IssuerAndSerialNumber::Clone() const
720 {
721 return new IssuerAndSerialNumber;
722 }
723
724 AsnType *IssuerAndSerialNumber::Copy() const
725 {
726 return new IssuerAndSerialNumber (*this);
727 }
728
729 #if SNACC_DEEP_COPY
730 IssuerAndSerialNumber &IssuerAndSerialNumber::operator = (const IssuerAndSerialNumber &that)
731 #else // SNACC_DEEP_COPY
732 IssuerAndSerialNumber &IssuerAndSerialNumber::operator = (const IssuerAndSerialNumber &)
733 #endif // SNACC_DEEP_COPY
734 {
735 #if SNACC_DEEP_COPY
736 if (this != &that)
737 {
738 if (that.issuer)
739 {
740 if (!issuer)
741 issuer = new Name;
742 *issuer = *that.issuer;
743 }
744 else
745 {
746 delete issuer;
747 issuer = NULL;
748 }
749 serialNumber = that.serialNumber;
750 }
751
752 return *this;
753 #else // SNACC_DEEP_COPY
754 Asn1Error << "use of incompletely defined IssuerAndSerialNumber &IssuerAndSerialNumber::operator = (const IssuerAndSerialNumber &)" << endl;
755 abort();
756 // if your compiler complains here, check the -novolat option
757 #endif // SNACC_DEEP_COPY
758 }
759
760 AsnLen
761 IssuerAndSerialNumber::BEncContent (BUF_TYPE b)
762 {
763 AsnLen totalLen = 0;
764 AsnLen l;
765
766 l = serialNumber.BEncContent (b);
767 l += BEncDefLen (b, l);
768
769 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
770 totalLen += l;
771
772 l = issuer->BEncContent (b);
773 totalLen += l;
774
775 return totalLen;
776 } // IssuerAndSerialNumber::BEncContent
777
778
779 void IssuerAndSerialNumber::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
780 {
781 AsnTag tag1;
782 AsnLen seqBytesDecoded = 0;
783 AsnLen elmtLen1;
784 tag1 = BDecTag (b, seqBytesDecoded, env);
785
786 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
787 {
788 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
789 issuer = new Name;
790 issuer->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
791 tag1 = BDecTag (b, seqBytesDecoded, env);
792 }
793 else
794 {
795 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
796 longjmp (env, -106);
797 }
798
799 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE))
800 || (tag1 == MAKE_TAG_ID (UNIV, CONS, INTEGER_TAG_CODE)))
801 {
802 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
803 serialNumber.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
804 }
805 else
806 {
807 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
808 longjmp (env, -107);
809 }
810
811 bytesDecoded += seqBytesDecoded;
812 if (elmtLen0 == INDEFINITE_LEN)
813 {
814 BDecEoc (b, bytesDecoded, env);
815 return;
816 }
817 else if (seqBytesDecoded != elmtLen0)
818 {
819 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
820 longjmp (env, -108);
821 }
822 else
823 return;
824 } // IssuerAndSerialNumber::BDecContent
825
826 AsnLen IssuerAndSerialNumber::BEnc (BUF_TYPE b)
827 {
828 AsnLen l;
829 l = BEncContent (b);
830 l += BEncConsLen (b, l);
831 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
832 return l;
833 }
834
835 void IssuerAndSerialNumber::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
836 {
837 AsnTag tag;
838 AsnLen elmtLen1;
839
840 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
841 {
842 Asn1Error << "IssuerAndSerialNumber::BDec: ERROR - wrong tag" << endl;
843 longjmp (env, -109);
844 }
845 elmtLen1 = BDecLen (b, bytesDecoded, env);
846 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
847 }
848
849 int IssuerAndSerialNumber::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
850 {
851 bytesEncoded = BEnc (b);
852 return !b.WriteError();
853 }
854
855 int IssuerAndSerialNumber::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
856 {
857 ENV_TYPE env;
858 int val;
859
860 bytesDecoded = 0;
861 if ((val = setjmp (env)) == 0)
862 {
863 BDec (b, bytesDecoded, env);
864 return !b.ReadError();
865 }
866 else
867 return false;
868 }
869
870 void IssuerAndSerialNumber::Print (ostream &os) const
871 {
872 #ifndef NDEBUG
873 os << "{ -- SEQUENCE --" << endl;
874 indentG += stdIndentG;
875
876 if (NOT_NULL (issuer))
877 {
878 Indent (os, indentG);
879 os << "issuer ";
880 os << *issuer;
881 }
882 else
883 {
884 Indent (os, indentG);
885 os << "issuer ";
886 os << "-- void --";
887 os << "," << endl;
888 }
889
890 {
891 Indent (os, indentG);
892 os << "serialNumber ";
893 os << serialNumber;
894 }
895
896 os << endl;
897 indentG -= stdIndentG;
898 Indent (os, indentG);
899 os << "}";
900 #endif /* NDEBUG */
901 } // IssuerAndSerialNumber::Print
902
903
904 OtherKeyAttribute::OtherKeyAttribute()
905 {
906 keyAttr = NULL;
907 }
908
909 OtherKeyAttribute::OtherKeyAttribute (const OtherKeyAttribute &)
910 {
911 Asn1Error << "use of incompletely defined OtherKeyAttribute::OtherKeyAttribute (const OtherKeyAttribute &)" << endl;
912 abort();
913 }
914
915 OtherKeyAttribute::~OtherKeyAttribute()
916 {
917 delete keyAttr;
918 }
919
920 AsnType *OtherKeyAttribute::Clone() const
921 {
922 return new OtherKeyAttribute;
923 }
924
925 AsnType *OtherKeyAttribute::Copy() const
926 {
927 return new OtherKeyAttribute (*this);
928 }
929
930 #if SNACC_DEEP_COPY
931 OtherKeyAttribute &OtherKeyAttribute::operator = (const OtherKeyAttribute &that)
932 #else // SNACC_DEEP_COPY
933 OtherKeyAttribute &OtherKeyAttribute::operator = (const OtherKeyAttribute &)
934 #endif // SNACC_DEEP_COPY
935 {
936 #if SNACC_DEEP_COPY
937 if (this != &that)
938 {
939 keyAttrId = that.keyAttrId;
940 if (that.keyAttr)
941 {
942 if (!keyAttr)
943 keyAttr = new AsnAny;
944 *keyAttr = *that.keyAttr;
945 }
946 else
947 {
948 delete keyAttr;
949 keyAttr = NULL;
950 }
951 }
952
953 return *this;
954 #else // SNACC_DEEP_COPY
955 Asn1Error << "use of incompletely defined OtherKeyAttribute &OtherKeyAttribute::operator = (const OtherKeyAttribute &)" << endl;
956 abort();
957 // if your compiler complains here, check the -novolat option
958 #endif // SNACC_DEEP_COPY
959 }
960
961 AsnLen
962 OtherKeyAttribute::BEncContent (BUF_TYPE b)
963 {
964 AsnLen totalLen = 0;
965 AsnLen l;
966
967 if (NOT_NULL (keyAttr))
968 {
969 ENC_LOAD_ANYBUF(keyAttr, b, l);
970 totalLen += l;
971 }
972
973 l = keyAttrId.BEncContent (b);
974 l += BEncDefLen (b, l);
975
976 l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
977 totalLen += l;
978
979 return totalLen;
980 } // OtherKeyAttribute::BEncContent
981
982
983 void OtherKeyAttribute::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
984 {
985 AsnTag tag1;
986 AsnLen seqBytesDecoded = 0;
987 AsnLen elmtLen1;
988 tag1 = BDecTag (b, seqBytesDecoded, env);
989
990 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
991 {
992 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
993 keyAttrId.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
994 if (seqBytesDecoded == elmtLen0)
995 {
996 bytesDecoded += seqBytesDecoded;
997 return;
998 }
999 else
1000 {
1001 tag1 = b.PeekByte();
1002
1003 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
1004 {
1005 BDecEoc (b, seqBytesDecoded, env);
1006
1007 bytesDecoded += seqBytesDecoded;
1008 return;
1009 }
1010 }
1011 }
1012 else
1013 {
1014 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
1015 longjmp (env, -110);
1016 }
1017
1018 // ANY type
1019 keyAttr = new AsnAny;
1020 DEC_LOAD_ANYBUF(keyAttr, b, seqBytesDecoded, env);
1021
1022
1023 bytesDecoded += seqBytesDecoded;
1024 if (elmtLen0 == INDEFINITE_LEN)
1025 {
1026 BDecEoc (b, bytesDecoded, env);
1027 return;
1028 }
1029 else if (seqBytesDecoded != elmtLen0)
1030 {
1031 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
1032 longjmp (env, -111);
1033 }
1034 else
1035 return;
1036 } // OtherKeyAttribute::BDecContent
1037
1038 AsnLen OtherKeyAttribute::BEnc (BUF_TYPE b)
1039 {
1040 AsnLen l;
1041 l = BEncContent (b);
1042 l += BEncConsLen (b, l);
1043 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
1044 return l;
1045 }
1046
1047 void OtherKeyAttribute::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
1048 {
1049 AsnTag tag;
1050 AsnLen elmtLen1;
1051
1052 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
1053 {
1054 Asn1Error << "OtherKeyAttribute::BDec: ERROR - wrong tag" << endl;
1055 longjmp (env, -112);
1056 }
1057 elmtLen1 = BDecLen (b, bytesDecoded, env);
1058 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
1059 }
1060
1061 int OtherKeyAttribute::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
1062 {
1063 bytesEncoded = BEnc (b);
1064 return !b.WriteError();
1065 }
1066
1067 int OtherKeyAttribute::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
1068 {
1069 ENV_TYPE env;
1070 int val;
1071
1072 bytesDecoded = 0;
1073 if ((val = setjmp (env)) == 0)
1074 {
1075 BDec (b, bytesDecoded, env);
1076 return !b.ReadError();
1077 }
1078 else
1079 return false;
1080 }
1081
1082 void OtherKeyAttribute::Print (ostream &os) const
1083 {
1084 #ifndef NDEBUG
1085 os << "{ -- SEQUENCE --" << endl;
1086 indentG += stdIndentG;
1087
1088 {
1089 Indent (os, indentG);
1090 os << "keyAttrId ";
1091 os << keyAttrId;
1092 os << "," << endl;
1093 }
1094
1095 if (NOT_NULL (keyAttr))
1096 {
1097 os << ","<< endl;
1098 Indent (os, indentG);
1099 os << "keyAttr ";
1100 os << *keyAttr;
1101 }
1102 else
1103 {
1104 Indent (os, indentG);
1105 os << "keyAttr ";
1106 os << "-- void --";
1107 os << endl;
1108 }
1109
1110 os << endl;
1111 indentG -= stdIndentG;
1112 Indent (os, indentG);
1113 os << "}";
1114 #endif /* NDEBUG */
1115 } // OtherKeyAttribute::Print
1116
1117
1118 AsnType *DigestAlgorithmIdentifiers::Clone() const
1119 {
1120 return new DigestAlgorithmIdentifiers;
1121 }
1122
1123 AsnType *DigestAlgorithmIdentifiers::Copy() const
1124 {
1125 return new DigestAlgorithmIdentifiers (*this);
1126 }
1127
1128 AsnLen DigestAlgorithmIdentifiers::BEnc (BUF_TYPE b)
1129 {
1130 AsnLen l;
1131 l = BEncContent (b);
1132 l += BEncConsLen (b, l);
1133 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
1134 return l;
1135 }
1136
1137 void DigestAlgorithmIdentifiers::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
1138 {
1139 AsnTag tag;
1140 AsnLen elmtLen1;
1141
1142 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
1143 {
1144 Asn1Error << "DigestAlgorithmIdentifiers::BDec: ERROR - wrong tag" << endl;
1145 longjmp (env, -113);
1146 }
1147 elmtLen1 = BDecLen (b, bytesDecoded, env);
1148 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
1149 }
1150
1151 DigestAlgorithmIdentifiers::DigestAlgorithmIdentifiers (const DigestAlgorithmIdentifiers &)
1152 {
1153 Asn1Error << "use of incompletely defined DigestAlgorithmIdentifiers::DigestAlgorithmIdentifiers (const DigestAlgorithmIdentifiers &)" << endl;
1154 abort();
1155 }
1156
1157 DigestAlgorithmIdentifiers::~DigestAlgorithmIdentifiers()
1158 {
1159 SetCurrToFirst();
1160 for (; Curr() != NULL; RemoveCurrFromList())
1161 ;
1162 } // end of destructor
1163
1164 #if SNACC_DEEP_COPY
1165 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::operator = (const DigestAlgorithmIdentifiers &that)
1166 #else // SNACC_DEEP_COPY
1167 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::operator = (const DigestAlgorithmIdentifiers &)
1168 #endif // SNACC_DEEP_COPY
1169 {
1170 #if SNACC_DEEP_COPY
1171 if (this != &that)
1172 {
1173 SetCurrToFirst();
1174 for (; Curr(); RemoveCurrFromList())
1175 ;
1176
1177 //that.SetCurrToFirst();
1178 //for (; that.Curr(); that.GoNext())
1179 // AppendCopy (*that.Curr());
1180 for (const AsnListElmt *run=that.first; run; run=run->next)
1181 AppendCopy (*run->elmt);
1182 }
1183
1184 return *this;
1185 #else // SNACC_DEEP_COPY
1186 Asn1Error << "use of incompletely defined DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::operator = (const DigestAlgorithmIdentifiers &)" << endl;
1187 abort();
1188 // if your compiler complains here, check the -novolat option
1189 #endif // SNACC_DEEP_COPY
1190 }
1191
1192 void DigestAlgorithmIdentifiers::Print (ostream &os) const
1193 {
1194 #ifndef NDEBUG
1195 os << "{ -- SEQUENCE/SET OF -- " << endl;
1196 indentG += stdIndentG;
1197 //SetCurrToFirst();
1198 //for (; Curr() != NULL; GoNext())
1199 for (const AsnListElmt *run=first; run; run=run->next)
1200 {
1201 Indent (os, indentG);
1202 //os << *Curr();
1203 os << *run->elmt;
1204 //if (Curr() != Last())
1205 if (run != last)
1206 os << ",";
1207 os << endl;
1208 }
1209 indentG -= stdIndentG;
1210 Indent (os, indentG);
1211 os << "}\n";
1212 #endif /* NDEBUG */
1213
1214
1215 } // Print
1216
1217
1218 void DigestAlgorithmIdentifiers::SetCurrElmt (unsigned long int index)
1219 {
1220 unsigned long int i;
1221 curr = first;
1222 if (count)
1223 for (i = 0; (i < (count-1)) && (i < index); i++)
1224 curr = curr->next;
1225 } // DigestAlgorithmIdentifiers::SetCurrElmt
1226
1227
1228 unsigned long int DigestAlgorithmIdentifiers::GetCurrElmtIndex()
1229 {
1230 unsigned long int i;
1231 AsnListElmt *tmp;
1232 if (curr != NULL)
1233 {
1234 for (i = 0, tmp = first; tmp != NULL; i++)
1235 {
1236 if (tmp == curr)
1237 return i;
1238 else
1239 tmp = tmp->next;
1240 }
1241 }
1242 return count;
1243 } // DigestAlgorithmIdentifiers::GetCurrElmtIndex
1244
1245
1246 // alloc new list elmt, put at end of list
1247 // and return the component type
1248 DigestAlgorithmIdentifier *DigestAlgorithmIdentifiers::Append()
1249 {
1250 AsnListElmt *newElmt;
1251 newElmt = new AsnListElmt;
1252 newElmt->elmt = new DigestAlgorithmIdentifier;
1253 newElmt->next = NULL;
1254 if (last == NULL)
1255 {
1256 newElmt->prev = NULL;
1257 first = last = newElmt;
1258 }
1259 else
1260 {
1261 newElmt->prev = last;
1262 last->next = newElmt;
1263 last = newElmt;
1264 }
1265 count++;
1266 return (curr = newElmt)->elmt;
1267 } // DigestAlgorithmIdentifiers::Append
1268
1269
1270 // alloc new list elmt, put at begining of list
1271 // and return the component type
1272 DigestAlgorithmIdentifier *DigestAlgorithmIdentifiers::Prepend()
1273 {
1274 AsnListElmt *newElmt;
1275 newElmt = new AsnListElmt;
1276 newElmt->elmt = new DigestAlgorithmIdentifier;
1277 newElmt->prev = NULL;
1278 if (first == NULL)
1279 {
1280 newElmt->next = NULL;
1281 first = last = newElmt;
1282 }
1283 else
1284 {
1285 newElmt->next = first;
1286 first->prev = newElmt;
1287 first = newElmt;
1288 }
1289 count++;
1290 return (curr = newElmt)->elmt;
1291 } // DigestAlgorithmIdentifiers::Prepend
1292
1293
1294 // alloc new list elmt, insert it before the
1295 // current element and return the component type
1296 // if the current element is null, the new element
1297 // is placed at the beginning of the list.
1298 DigestAlgorithmIdentifier *DigestAlgorithmIdentifiers::InsertBefore()
1299 {
1300 AsnListElmt *newElmt;
1301 newElmt = new AsnListElmt;
1302 newElmt->elmt = new DigestAlgorithmIdentifier;
1303 if (curr == NULL)
1304 {
1305 newElmt->next = first;
1306 newElmt->prev = NULL;
1307 first = newElmt;
1308 if (last == NULL)
1309 last = newElmt;
1310 }
1311 else
1312 {
1313 newElmt->next = curr;
1314 newElmt->prev = curr->prev;
1315 curr->prev = newElmt;
1316 if (curr == first)
1317 first = newElmt;
1318 else
1319 newElmt->prev->next = newElmt;
1320 }
1321 count++;
1322 return (curr = newElmt)->elmt;
1323 } // DigestAlgorithmIdentifiers::InsertBefore
1324
1325
1326 // alloc new list elmt, insert it after the
1327 // current element and return the component type
1328 // if the current element is null, the new element
1329 // is placed at the end of the list.
1330 DigestAlgorithmIdentifier *DigestAlgorithmIdentifiers::InsertAfter()
1331 {
1332 AsnListElmt *newElmt;
1333 newElmt = new AsnListElmt;
1334 newElmt->elmt = new DigestAlgorithmIdentifier;
1335 if (curr == NULL)
1336 {
1337 newElmt->prev = last;
1338 newElmt->next = NULL;
1339 last = newElmt;
1340 if (first == NULL)
1341 first = newElmt;
1342 }
1343 else
1344 {
1345 newElmt->prev = curr;
1346 newElmt->next = curr->next;
1347 curr->next = newElmt;
1348 if (curr == last)
1349 last = newElmt;
1350 else
1351 newElmt->next->prev = newElmt;
1352 }
1353 count++;
1354 return (curr = newElmt)->elmt;
1355 } // DigestAlgorithmIdentifiers::InsertAfter
1356
1357
1358 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::AppendCopy (DigestAlgorithmIdentifier &elmt)
1359 {
1360 AsnListElmt *newElmt;
1361 newElmt = new AsnListElmt;
1362 newElmt->elmt = new DigestAlgorithmIdentifier;
1363 *newElmt->elmt = elmt;
1364 newElmt->next = NULL;
1365 if (last == NULL)
1366 {
1367 newElmt->prev = NULL;
1368 first = last = newElmt;
1369 }
1370 else
1371 {
1372 newElmt->prev = last;
1373 last->next = newElmt;
1374 last = newElmt;
1375 }
1376 count++;
1377 return *this;
1378 } // AppendCopy
1379
1380
1381 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::PrependCopy (DigestAlgorithmIdentifier &elmt)
1382 {
1383 AsnListElmt *newElmt;
1384 newElmt = new AsnListElmt;
1385 newElmt->elmt = new DigestAlgorithmIdentifier;
1386 *newElmt->elmt = elmt;
1387 newElmt->prev = NULL;
1388 if (first == NULL)
1389 {
1390 newElmt->next = NULL;
1391 first = last = newElmt;
1392 }
1393 else
1394 {
1395 newElmt->next = first;
1396 first->prev = newElmt;
1397 first = newElmt;
1398 }
1399 count++;
1400 return *this;
1401 } // DigestAlgorithmIdentifiers::PrependCopy
1402
1403
1404 // alloc new list elmt, insert it before the
1405 // current element, copy the given elmt into the new elmt
1406 // and return the component type.
1407 // if the current element is null, the new element
1408 // is placed at the beginning of the list.
1409 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::InsertBeforeAndCopy (DigestAlgorithmIdentifier &elmt)
1410 {
1411 AsnListElmt *newElmt;
1412
1413 newElmt = new AsnListElmt;
1414 newElmt->elmt = new DigestAlgorithmIdentifier;
1415 *newElmt->elmt = elmt;
1416
1417 if (curr == NULL)
1418 {
1419 newElmt->next = first;
1420 newElmt->prev = NULL;
1421 first = newElmt;
1422 if (last == NULL)
1423 last = newElmt;
1424 }
1425 else
1426 {
1427 newElmt->next = curr;
1428 newElmt->prev = curr->prev;
1429 curr->prev = newElmt;
1430 if (curr == first)
1431 first = newElmt;
1432 else
1433 newElmt->prev->next = newElmt;
1434 }
1435 count++;
1436 return *this;
1437 } // DigestAlgorithmIdentifiers::InsertBeforeAndCopy
1438
1439
1440 // alloc new list elmt, insert it after the
1441 // current element, copy given elmt in to new elmt
1442 // and return the component type
1443 // if the current element is null, the new element
1444 // is placed at the end of the list.
1445 DigestAlgorithmIdentifiers &DigestAlgorithmIdentifiers::InsertAfterAndCopy (DigestAlgorithmIdentifier &elmt)
1446 {
1447 AsnListElmt *newElmt;
1448
1449 newElmt = new AsnListElmt;
1450 newElmt->elmt = new DigestAlgorithmIdentifier;
1451 *newElmt->elmt = elmt;
1452 if (curr == NULL)
1453 {
1454 newElmt->prev = last;
1455 newElmt->next = NULL;
1456 last = newElmt;
1457 if (first == NULL)
1458 first = newElmt;
1459 }
1460 else
1461 {
1462 newElmt->prev = curr;
1463 newElmt->next = curr->next;
1464 curr->next = newElmt;
1465 if (curr == last)
1466 last = newElmt;
1467 else
1468 newElmt->next->prev = newElmt;
1469 }
1470 count++;
1471 return *this;
1472 } // DigestAlgorithmIdentifiers::InsertAfterAndCopy
1473
1474
1475 // remove current element from list if current element is not NULL
1476 // The new current element will be the next element.
1477 // If the current element is the last element in the list
1478 // the second but last element will become the new current element.
1479 void DigestAlgorithmIdentifiers::RemoveCurrFromList()
1480 {
1481 AsnListElmt *del_elmt;
1482
1483 if (curr != NULL)
1484 {
1485 del_elmt = curr;
1486 count--;
1487
1488 if (count == 0)
1489 first = last = curr = NULL;
1490 else if (curr == first)
1491 {
1492 curr = first= first->next;
1493 first->prev = NULL;
1494 }
1495 else if (curr == last)
1496 {
1497 curr = last = last->prev;
1498 last->next = NULL;
1499 }
1500 else
1501 {
1502 curr->prev->next = curr->next;
1503 curr->next->prev = curr->prev;
1504 }
1505
1506 delete del_elmt->elmt;
1507 delete del_elmt;
1508 }
1509 }
1510
1511
1512 AsnLen DigestAlgorithmIdentifiers::BEncContent (BUF_TYPE b)
1513 {
1514 AsnListElmt *currElmt;
1515 AsnLen elmtLen;
1516 AsnLen totalLen = 0;
1517 {
1518 int iii,icount;
1519 CSM_Buffer **tmpEnc=NULL;
1520 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
1521 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
1522 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
1523 {
1524 BEncEocIfNec (b);
1525 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
1526 elmtLen += BEncConsLen (outputBuf, elmtLen);
1527
1528 elmtLen += BEncTag1 (outputBuf, UNIV, CONS, SEQ_TAG_CODE);
1529 ENCODE_BUF2(tmpEnc[iii]);
1530 }
1531 vdasnacc_sortSetOf(tmpEnc, icount);
1532 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
1533 SM_WriteToAsnBuf(tmpEnc[iii], b);
1534 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
1535 free(tmpEnc);
1536 }
1537 totalLen += elmtLen;
1538 return totalLen;
1539 } // DigestAlgorithmIdentifiers::BEncContent
1540
1541
1542 void DigestAlgorithmIdentifiers::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
1543 AsnLen &bytesDecoded, ENV_TYPE env)
1544 {
1545 DigestAlgorithmIdentifier *listElmt;
1546 AsnTag tag1;
1547 AsnLen listBytesDecoded = 0;
1548 AsnLen elmtLen1;
1549
1550 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
1551 {
1552 tag1 = BDecTag (b, listBytesDecoded, env);
1553 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
1554 {
1555 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
1556 break;
1557 }
1558 if ((tag1 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
1559 {
1560 Asn1Error << "Unexpected Tag" << endl;
1561 longjmp (env, -114);
1562 }
1563
1564 elmtLen1 = BDecLen (b, listBytesDecoded, env);
1565 listElmt = Append();
1566 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
1567 }
1568
1569 bytesDecoded += listBytesDecoded;
1570 } // DigestAlgorithmIdentifiers::BDecContent
1571
1572
1573 EncapsulatedContentInfo::EncapsulatedContentInfo()
1574 {
1575 eContent = NULL;
1576 }
1577
1578 EncapsulatedContentInfo::EncapsulatedContentInfo (const EncapsulatedContentInfo &)
1579 {
1580 Asn1Error << "use of incompletely defined EncapsulatedContentInfo::EncapsulatedContentInfo (const EncapsulatedContentInfo &)" << endl;
1581 abort();
1582 }
1583
1584 EncapsulatedContentInfo::~EncapsulatedContentInfo()
1585 {
1586 delete eContent;
1587 }
1588
1589 AsnType *EncapsulatedContentInfo::Clone() const
1590 {
1591 return new EncapsulatedContentInfo;
1592 }
1593
1594 AsnType *EncapsulatedContentInfo::Copy() const
1595 {
1596 return new EncapsulatedContentInfo (*this);
1597 }
1598
1599 #if SNACC_DEEP_COPY
1600 EncapsulatedContentInfo &EncapsulatedContentInfo::operator = (const EncapsulatedContentInfo &that)
1601 #else // SNACC_DEEP_COPY
1602 EncapsulatedContentInfo &EncapsulatedContentInfo::operator = (const EncapsulatedContentInfo &)
1603 #endif // SNACC_DEEP_COPY
1604 {
1605 #if SNACC_DEEP_COPY
1606 if (this != &that)
1607 {
1608 eContentType = that.eContentType;
1609 if (that.eContent)
1610 {
1611 if (!eContent)
1612 eContent = new AsnOcts;
1613 *eContent = *that.eContent;
1614 }
1615 else
1616 {
1617 delete eContent;
1618 eContent = NULL;
1619 }
1620 }
1621
1622 return *this;
1623 #else // SNACC_DEEP_COPY
1624 Asn1Error << "use of incompletely defined EncapsulatedContentInfo &EncapsulatedContentInfo::operator = (const EncapsulatedContentInfo &)" << endl;
1625 abort();
1626 // if your compiler complains here, check the -novolat option
1627 #endif // SNACC_DEEP_COPY
1628 }
1629
1630 AsnLen
1631 EncapsulatedContentInfo::BEncContent (BUF_TYPE b)
1632 {
1633 AsnLen totalLen = 0;
1634 AsnLen l;
1635
1636 if (NOT_NULL (eContent))
1637 {
1638 BEncEocIfNec (b);
1639 l = eContent->BEncContent (b);
1640 l += BEncDefLen (b, l);
1641
1642 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
1643 l += BEncConsLen (b, l);
1644
1645 l += BEncTag1 (b, CNTX, CONS, 0);
1646 totalLen += l;
1647 }
1648
1649 l = eContentType.BEncContent (b);
1650 l += BEncDefLen (b, l);
1651
1652 l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
1653 totalLen += l;
1654
1655 return totalLen;
1656 } // EncapsulatedContentInfo::BEncContent
1657
1658
1659 void EncapsulatedContentInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
1660 {
1661 AsnTag tag1;
1662 AsnLen seqBytesDecoded = 0;
1663 AsnLen elmtLen1;
1664 AsnLen elmtLen2;
1665 tag1 = BDecTag (b, seqBytesDecoded, env);
1666
1667 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
1668 {
1669 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
1670 eContentType.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
1671 if (seqBytesDecoded == elmtLen0)
1672 {
1673 bytesDecoded += seqBytesDecoded;
1674 return;
1675 }
1676 else
1677 {
1678 tag1 = BDecTag (b, seqBytesDecoded, env);
1679
1680 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
1681 {
1682 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
1683 bytesDecoded += seqBytesDecoded;
1684 return;
1685 }
1686 }
1687 }
1688 else
1689 {
1690 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
1691 longjmp (env, -115);
1692 }
1693
1694 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
1695 {
1696 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
1697 tag1 = BDecTag (b, seqBytesDecoded, env);
1698
1699 if ((tag1 != MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
1700 && (tag1 != MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
1701 {
1702 Asn1Error << "Unexpected Tag" << endl;
1703 longjmp (env, -116);
1704 }
1705
1706 elmtLen2 = BDecLen (b, seqBytesDecoded, env);
1707 eContent = new AsnOcts;
1708 eContent->BDecContent (b, tag1, elmtLen2, seqBytesDecoded, env);
1709 if (elmtLen1 == INDEFINITE_LEN)
1710 BDecEoc (b, seqBytesDecoded, env);
1711
1712 }
1713
1714 bytesDecoded += seqBytesDecoded;
1715 if (elmtLen0 == INDEFINITE_LEN)
1716 {
1717 BDecEoc (b, bytesDecoded, env);
1718 return;
1719 }
1720 else if (seqBytesDecoded != elmtLen0)
1721 {
1722 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
1723 longjmp (env, -117);
1724 }
1725 else
1726 return;
1727 } // EncapsulatedContentInfo::BDecContent
1728
1729 AsnLen EncapsulatedContentInfo::BEnc (BUF_TYPE b)
1730 {
1731 AsnLen l;
1732 l = BEncContent (b);
1733 l += BEncConsLen (b, l);
1734 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
1735 return l;
1736 }
1737
1738 void EncapsulatedContentInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
1739 {
1740 AsnTag tag;
1741 AsnLen elmtLen1;
1742
1743 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
1744 {
1745 Asn1Error << "EncapsulatedContentInfo::BDec: ERROR - wrong tag" << endl;
1746 longjmp (env, -118);
1747 }
1748 elmtLen1 = BDecLen (b, bytesDecoded, env);
1749 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
1750 }
1751
1752 int EncapsulatedContentInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
1753 {
1754 bytesEncoded = BEnc (b);
1755 return !b.WriteError();
1756 }
1757
1758 int EncapsulatedContentInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
1759 {
1760 ENV_TYPE env;
1761 int val;
1762
1763 bytesDecoded = 0;
1764 if ((val = setjmp (env)) == 0)
1765 {
1766 BDec (b, bytesDecoded, env);
1767 return !b.ReadError();
1768 }
1769 else
1770 return false;
1771 }
1772
1773 void EncapsulatedContentInfo::Print (ostream &os) const
1774 {
1775 #ifndef NDEBUG
1776 os << "{ -- SEQUENCE --" << endl;
1777 indentG += stdIndentG;
1778
1779 {
1780 Indent (os, indentG);
1781 os << "eContentType ";
1782 os << eContentType;
1783 os << "," << endl;
1784 }
1785
1786 if (NOT_NULL (eContent))
1787 {
1788 os << ","<< endl;
1789 Indent (os, indentG);
1790 os << "eContent ";
1791 os << *eContent;
1792 }
1793 else
1794 {
1795 Indent (os, indentG);
1796 os << "eContent ";
1797 os << "-- void --";
1798 os << endl;
1799 }
1800
1801 os << endl;
1802 indentG -= stdIndentG;
1803 Indent (os, indentG);
1804 os << "}";
1805 #endif /* NDEBUG */
1806 } // EncapsulatedContentInfo::Print
1807
1808
1809 SignerIdentifier::SignerIdentifier()
1810 {
1811 choiceId = issuerAndSerialNumberCid;
1812 #if TCL
1813 issuerAndSerialNumber = new IssuerAndSerialNumber;
1814 #else
1815 issuerAndSerialNumber = NULL; // incomplete initialization of mandatory element!
1816 #endif // TCL
1817 }
1818
1819 SignerIdentifier::SignerIdentifier (const SignerIdentifier &)
1820 {
1821 Asn1Error << "use of incompletely defined SignerIdentifier::SignerIdentifier (const SignerIdentifier &)" << endl;
1822 abort();
1823 }
1824
1825 SignerIdentifier::~SignerIdentifier()
1826 {
1827 switch (choiceId)
1828 {
1829 case issuerAndSerialNumberCid:
1830 delete issuerAndSerialNumber;
1831 break;
1832 case subjectKeyIdentifierCid:
1833 delete subjectKeyIdentifier;
1834 break;
1835 } // end of switch
1836 } // end of destructor
1837
1838 AsnType *SignerIdentifier::Clone() const
1839 {
1840 return new SignerIdentifier;
1841 }
1842
1843 AsnType *SignerIdentifier::Copy() const
1844 {
1845 return new SignerIdentifier (*this);
1846 }
1847
1848 #if SNACC_DEEP_COPY
1849 SignerIdentifier &SignerIdentifier::operator = (const SignerIdentifier &that)
1850 #else // SNACC_DEEP_COPY
1851 SignerIdentifier &SignerIdentifier::operator = (const SignerIdentifier &)
1852 #endif // SNACC_DEEP_COPY
1853 {
1854 #if SNACC_DEEP_COPY
1855 if (this != &that)
1856 {
1857 switch (choiceId)
1858 {
1859 case issuerAndSerialNumberCid:
1860 delete issuerAndSerialNumber;
1861 break;
1862 case subjectKeyIdentifierCid:
1863 delete subjectKeyIdentifier;
1864 break;
1865 }
1866 switch (choiceId = that.choiceId)
1867 {
1868 case issuerAndSerialNumberCid:
1869 issuerAndSerialNumber = new IssuerAndSerialNumber;
1870 *issuerAndSerialNumber = *that.issuerAndSerialNumber;
1871 break;
1872 case subjectKeyIdentifierCid:
1873 subjectKeyIdentifier = new KeyIdentifier;
1874 *subjectKeyIdentifier = *that.subjectKeyIdentifier;
1875 break;
1876 }
1877 }
1878
1879 return *this;
1880 #else // SNACC_DEEP_COPY
1881 Asn1Error << "use of incompletely defined SignerIdentifier &SignerIdentifier::operator = (const SignerIdentifier &)" << endl;
1882 abort();
1883 // if your compiler complains here, check the -novolat option
1884 #endif // SNACC_DEEP_COPY
1885 }
1886
1887 AsnLen
1888 SignerIdentifier::BEncContent (BUF_TYPE b)
1889 {
1890 AsnLen l;
1891 switch (choiceId)
1892 {
1893 case issuerAndSerialNumberCid:
1894 BEncEocIfNec (b);
1895 l = issuerAndSerialNumber->BEncContent (b);
1896 l += BEncConsLen (b, l);
1897
1898 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
1899 break;
1900
1901 case subjectKeyIdentifierCid:
1902 l = subjectKeyIdentifier->BEncContent (b);
1903 l += BEncDefLen (b, l);
1904
1905 l += BEncTag1 (b, CNTX, PRIM, 0);
1906 break;
1907
1908 } // end switch
1909 return l;
1910 } // SignerIdentifier::BEncContent
1911
1912
1913 void SignerIdentifier::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
1914 {
1915 switch (tag)
1916 {
1917 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
1918 choiceId = issuerAndSerialNumberCid;
1919 issuerAndSerialNumber = new IssuerAndSerialNumber;
1920 issuerAndSerialNumber->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
1921 break;
1922
1923 case MAKE_TAG_ID (CNTX, PRIM, 0):
1924 case MAKE_TAG_ID (CNTX, CONS, 0):
1925 choiceId = subjectKeyIdentifierCid;
1926 subjectKeyIdentifier = new KeyIdentifier;
1927 subjectKeyIdentifier->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
1928 break;
1929
1930 default:
1931 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
1932 longjmp (env, -119);
1933 break;
1934 } // end switch
1935 } // SignerIdentifier::BDecContent
1936
1937
1938 AsnLen SignerIdentifier::BEnc (BUF_TYPE b)
1939 {
1940 AsnLen l;
1941 l = BEncContent (b);
1942 return l;
1943 }
1944
1945 void SignerIdentifier::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
1946 {
1947 AsnLen elmtLen;
1948 AsnTag tag;
1949
1950 /* CHOICEs are a special case - grab identifying tag */
1951 /* this allows easier handling of nested CHOICEs */
1952 tag = BDecTag (b, bytesDecoded, env);
1953 elmtLen = BDecLen (b, bytesDecoded, env);
1954 BDecContent (b, tag, elmtLen, bytesDecoded, env);
1955 }
1956
1957 int SignerIdentifier::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
1958 {
1959 bytesEncoded = BEnc (b);
1960 return !b.WriteError();
1961 }
1962
1963 int SignerIdentifier::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
1964 {
1965 ENV_TYPE env;
1966 int val;
1967
1968 bytesDecoded = 0;
1969 if ((val = setjmp (env)) == 0)
1970 {
1971 BDec (b, bytesDecoded, env);
1972 return !b.ReadError();
1973 }
1974 else
1975 return false;
1976 }
1977
1978 void SignerIdentifier::Print (ostream &os) const
1979 {
1980 #ifndef NDEBUG
1981 switch (choiceId)
1982 {
1983 case issuerAndSerialNumberCid:
1984 os << "issuerAndSerialNumber ";
1985 if (issuerAndSerialNumber)
1986 os << *issuerAndSerialNumber;
1987 else
1988 os << "-- void3 --\n";
1989 break;
1990
1991 case subjectKeyIdentifierCid:
1992 os << "subjectKeyIdentifier ";
1993 if (subjectKeyIdentifier)
1994 os << *subjectKeyIdentifier;
1995 else
1996 os << "-- void3 --\n";
1997 break;
1998
1999 } // end of switch
2000 #endif /* NDEBUG */
2001 } // SignerIdentifier::Print
2002
2003 EncryptedContentInfo::EncryptedContentInfo()
2004 {
2005 #if TCL
2006 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier;
2007 #else
2008 contentEncryptionAlgorithm = NULL; // incomplete initialization of mandatory element!
2009 #endif // TCL
2010 encryptedContent = NULL;
2011 }
2012
2013 EncryptedContentInfo::EncryptedContentInfo (const EncryptedContentInfo &)
2014 {
2015 Asn1Error << "use of incompletely defined EncryptedContentInfo::EncryptedContentInfo (const EncryptedContentInfo &)" << endl;
2016 abort();
2017 }
2018
2019 EncryptedContentInfo::~EncryptedContentInfo()
2020 {
2021 delete contentEncryptionAlgorithm;
2022 delete encryptedContent;
2023 }
2024
2025 AsnType *EncryptedContentInfo::Clone() const
2026 {
2027 return new EncryptedContentInfo;
2028 }
2029
2030 AsnType *EncryptedContentInfo::Copy() const
2031 {
2032 return new EncryptedContentInfo (*this);
2033 }
2034
2035 #if SNACC_DEEP_COPY
2036 EncryptedContentInfo &EncryptedContentInfo::operator = (const EncryptedContentInfo &that)
2037 #else // SNACC_DEEP_COPY
2038 EncryptedContentInfo &EncryptedContentInfo::operator = (const EncryptedContentInfo &)
2039 #endif // SNACC_DEEP_COPY
2040 {
2041 #if SNACC_DEEP_COPY
2042 if (this != &that)
2043 {
2044 contentType = that.contentType;
2045 if (that.contentEncryptionAlgorithm)
2046 {
2047 if (!contentEncryptionAlgorithm)
2048 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier;
2049 *contentEncryptionAlgorithm = *that.contentEncryptionAlgorithm;
2050 }
2051 else
2052 {
2053 delete contentEncryptionAlgorithm;
2054 contentEncryptionAlgorithm = NULL;
2055 }
2056 if (that.encryptedContent)
2057 {
2058 if (!encryptedContent)
2059 encryptedContent = new EncryptedContent;
2060 *encryptedContent = *that.encryptedContent;
2061 }
2062 else
2063 {
2064 delete encryptedContent;
2065 encryptedContent = NULL;
2066 }
2067 }
2068
2069 return *this;
2070 #else // SNACC_DEEP_COPY
2071 Asn1Error << "use of incompletely defined EncryptedContentInfo &EncryptedContentInfo::operator = (const EncryptedContentInfo &)" << endl;
2072 abort();
2073 // if your compiler complains here, check the -novolat option
2074 #endif // SNACC_DEEP_COPY
2075 }
2076
2077 AsnLen
2078 EncryptedContentInfo::BEncContent (BUF_TYPE b)
2079 {
2080 AsnLen totalLen = 0;
2081 AsnLen l;
2082
2083 if (NOT_NULL (encryptedContent))
2084 {
2085 l = encryptedContent->BEncContent (b);
2086 l += BEncDefLen (b, l);
2087
2088 l += BEncTag1 (b, CNTX, PRIM, 0);
2089 totalLen += l;
2090 }
2091
2092 BEncEocIfNec (b);
2093 l = contentEncryptionAlgorithm->BEncContent (b);
2094 l += BEncConsLen (b, l);
2095
2096 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2097 totalLen += l;
2098
2099 l = contentType.BEncContent (b);
2100 l += BEncDefLen (b, l);
2101
2102 l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
2103 totalLen += l;
2104
2105 return totalLen;
2106 } // EncryptedContentInfo::BEncContent
2107
2108
2109 void EncryptedContentInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
2110 {
2111 AsnTag tag1;
2112 AsnLen seqBytesDecoded = 0;
2113 AsnLen elmtLen1;
2114 tag1 = BDecTag (b, seqBytesDecoded, env);
2115
2116 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
2117 {
2118 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2119 contentType.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2120 tag1 = BDecTag (b, seqBytesDecoded, env);
2121 }
2122 else
2123 {
2124 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
2125 longjmp (env, -120);
2126 }
2127
2128 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
2129 {
2130 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2131 contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier;
2132 contentEncryptionAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2133 if (seqBytesDecoded == elmtLen0)
2134 {
2135 bytesDecoded += seqBytesDecoded;
2136 return;
2137 }
2138 else
2139 {
2140 tag1 = BDecTag (b, seqBytesDecoded, env);
2141
2142 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
2143 {
2144 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
2145 bytesDecoded += seqBytesDecoded;
2146 return;
2147 }
2148 }
2149 }
2150 else
2151 {
2152 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
2153 longjmp (env, -121);
2154 }
2155
2156 if ((tag1 == MAKE_TAG_ID (CNTX, PRIM, 0))
2157 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
2158 {
2159 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2160 encryptedContent = new EncryptedContent;
2161 encryptedContent->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2162 }
2163
2164 bytesDecoded += seqBytesDecoded;
2165 if (elmtLen0 == INDEFINITE_LEN)
2166 {
2167 BDecEoc (b, bytesDecoded, env);
2168 return;
2169 }
2170 else if (seqBytesDecoded != elmtLen0)
2171 {
2172 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
2173 longjmp (env, -122);
2174 }
2175 else
2176 return;
2177 } // EncryptedContentInfo::BDecContent
2178
2179 AsnLen EncryptedContentInfo::BEnc (BUF_TYPE b)
2180 {
2181 AsnLen l;
2182 l = BEncContent (b);
2183 l += BEncConsLen (b, l);
2184 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2185 return l;
2186 }
2187
2188 void EncryptedContentInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
2189 {
2190 AsnTag tag;
2191 AsnLen elmtLen1;
2192
2193 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
2194 {
2195 Asn1Error << "EncryptedContentInfo::BDec: ERROR - wrong tag" << endl;
2196 longjmp (env, -123);
2197 }
2198 elmtLen1 = BDecLen (b, bytesDecoded, env);
2199 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
2200 }
2201
2202 int EncryptedContentInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
2203 {
2204 bytesEncoded = BEnc (b);
2205 return !b.WriteError();
2206 }
2207
2208 int EncryptedContentInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
2209 {
2210 ENV_TYPE env;
2211 int val;
2212
2213 bytesDecoded = 0;
2214 if ((val = setjmp (env)) == 0)
2215 {
2216 BDec (b, bytesDecoded, env);
2217 return !b.ReadError();
2218 }
2219 else
2220 return false;
2221 }
2222
2223 void EncryptedContentInfo::Print (ostream &os) const
2224 {
2225 #ifndef NDEBUG
2226 os << "{ -- SEQUENCE --" << endl;
2227 indentG += stdIndentG;
2228
2229 {
2230 Indent (os, indentG);
2231 os << "contentType ";
2232 os << contentType;
2233 os << "," << endl;
2234 }
2235
2236 if (NOT_NULL (contentEncryptionAlgorithm))
2237 {
2238 Indent (os, indentG);
2239 os << "contentEncryptionAlgorithm ";
2240 os << *contentEncryptionAlgorithm;
2241 }
2242 else
2243 {
2244 Indent (os, indentG);
2245 os << "contentEncryptionAlgorithm ";
2246 os << "-- void --";
2247 os << "," << endl;
2248 }
2249
2250 if (NOT_NULL (encryptedContent))
2251 {
2252 os << ","<< endl;
2253 Indent (os, indentG);
2254 os << "encryptedContent ";
2255 os << *encryptedContent;
2256 }
2257 else
2258 {
2259 Indent (os, indentG);
2260 os << "encryptedContent ";
2261 os << "-- void --";
2262 os << endl;
2263 }
2264
2265 os << endl;
2266 indentG -= stdIndentG;
2267 Indent (os, indentG);
2268 os << "}";
2269 #endif /* NDEBUG */
2270 } // EncryptedContentInfo::Print
2271
2272
2273 RecipientIdentifier::RecipientIdentifier()
2274 {
2275 choiceId = issuerAndSerialNumberCid;
2276 #if TCL
2277 issuerAndSerialNumber = new IssuerAndSerialNumber;
2278 #else
2279 issuerAndSerialNumber = NULL; // incomplete initialization of mandatory element!
2280 #endif // TCL
2281 }
2282
2283 RecipientIdentifier::RecipientIdentifier (const RecipientIdentifier &)
2284 {
2285 Asn1Error << "use of incompletely defined RecipientIdentifier::RecipientIdentifier (const RecipientIdentifier &)" << endl;
2286 abort();
2287 }
2288
2289 RecipientIdentifier::~RecipientIdentifier()
2290 {
2291 switch (choiceId)
2292 {
2293 case issuerAndSerialNumberCid:
2294 delete issuerAndSerialNumber;
2295 break;
2296 case subjectKeyIdentifierCid:
2297 delete subjectKeyIdentifier;
2298 break;
2299 } // end of switch
2300 } // end of destructor
2301
2302 AsnType *RecipientIdentifier::Clone() const
2303 {
2304 return new RecipientIdentifier;
2305 }
2306
2307 AsnType *RecipientIdentifier::Copy() const
2308 {
2309 return new RecipientIdentifier (*this);
2310 }
2311
2312 #if SNACC_DEEP_COPY
2313 RecipientIdentifier &RecipientIdentifier::operator = (const RecipientIdentifier &that)
2314 #else // SNACC_DEEP_COPY
2315 RecipientIdentifier &RecipientIdentifier::operator = (const RecipientIdentifier &)
2316 #endif // SNACC_DEEP_COPY
2317 {
2318 #if SNACC_DEEP_COPY
2319 if (this != &that)
2320 {
2321 switch (choiceId)
2322 {
2323 case issuerAndSerialNumberCid:
2324 delete issuerAndSerialNumber;
2325 break;
2326 case subjectKeyIdentifierCid:
2327 delete subjectKeyIdentifier;
2328 break;
2329 }
2330 switch (choiceId = that.choiceId)
2331 {
2332 case issuerAndSerialNumberCid:
2333 issuerAndSerialNumber = new IssuerAndSerialNumber;
2334 *issuerAndSerialNumber = *that.issuerAndSerialNumber;
2335 break;
2336 case subjectKeyIdentifierCid:
2337 subjectKeyIdentifier = new KeyIdentifier;
2338 *subjectKeyIdentifier = *that.subjectKeyIdentifier;
2339 break;
2340 }
2341 }
2342
2343 return *this;
2344 #else // SNACC_DEEP_COPY
2345 Asn1Error << "use of incompletely defined RecipientIdentifier &RecipientIdentifier::operator = (const RecipientIdentifier &)" << endl;
2346 abort();
2347 // if your compiler complains here, check the -novolat option
2348 #endif // SNACC_DEEP_COPY
2349 }
2350
2351 AsnLen
2352 RecipientIdentifier::BEncContent (BUF_TYPE b)
2353 {
2354 AsnLen l;
2355 switch (choiceId)
2356 {
2357 case issuerAndSerialNumberCid:
2358 BEncEocIfNec (b);
2359 l = issuerAndSerialNumber->BEncContent (b);
2360 l += BEncConsLen (b, l);
2361
2362 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2363 break;
2364
2365 case subjectKeyIdentifierCid:
2366 l = subjectKeyIdentifier->BEncContent (b);
2367 l += BEncDefLen (b, l);
2368
2369 l += BEncTag1 (b, CNTX, PRIM, 0);
2370 break;
2371
2372 } // end switch
2373 return l;
2374 } // RecipientIdentifier::BEncContent
2375
2376
2377 void RecipientIdentifier::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
2378 {
2379 switch (tag)
2380 {
2381 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
2382 choiceId = issuerAndSerialNumberCid;
2383 issuerAndSerialNumber = new IssuerAndSerialNumber;
2384 issuerAndSerialNumber->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
2385 break;
2386
2387 case MAKE_TAG_ID (CNTX, PRIM, 0):
2388 case MAKE_TAG_ID (CNTX, CONS, 0):
2389 choiceId = subjectKeyIdentifierCid;
2390 subjectKeyIdentifier = new KeyIdentifier;
2391 subjectKeyIdentifier->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
2392 break;
2393
2394 default:
2395 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
2396 longjmp (env, -124);
2397 break;
2398 } // end switch
2399 } // RecipientIdentifier::BDecContent
2400
2401
2402 AsnLen RecipientIdentifier::BEnc (BUF_TYPE b)
2403 {
2404 AsnLen l;
2405 l = BEncContent (b);
2406 return l;
2407 }
2408
2409 void RecipientIdentifier::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
2410 {
2411 AsnLen elmtLen;
2412 AsnTag tag;
2413
2414 /* CHOICEs are a special case - grab identifying tag */
2415 /* this allows easier handling of nested CHOICEs */
2416 tag = BDecTag (b, bytesDecoded, env);
2417 elmtLen = BDecLen (b, bytesDecoded, env);
2418 BDecContent (b, tag, elmtLen, bytesDecoded, env);
2419 }
2420
2421 int RecipientIdentifier::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
2422 {
2423 bytesEncoded = BEnc (b);
2424 return !b.WriteError();
2425 }
2426
2427 int RecipientIdentifier::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
2428 {
2429 ENV_TYPE env;
2430 int val;
2431
2432 bytesDecoded = 0;
2433 if ((val = setjmp (env)) == 0)
2434 {
2435 BDec (b, bytesDecoded, env);
2436 return !b.ReadError();
2437 }
2438 else
2439 return false;
2440 }
2441
2442 void RecipientIdentifier::Print (ostream &os) const
2443 {
2444 #ifndef NDEBUG
2445 switch (choiceId)
2446 {
2447 case issuerAndSerialNumberCid:
2448 os << "issuerAndSerialNumber ";
2449 if (issuerAndSerialNumber)
2450 os << *issuerAndSerialNumber;
2451 else
2452 os << "-- void3 --\n";
2453 break;
2454
2455 case subjectKeyIdentifierCid:
2456 os << "subjectKeyIdentifier ";
2457 if (subjectKeyIdentifier)
2458 os << *subjectKeyIdentifier;
2459 else
2460 os << "-- void3 --\n";
2461 break;
2462
2463 } // end of switch
2464 #endif /* NDEBUG */
2465 } // RecipientIdentifier::Print
2466
2467 OriginatorIdentifierOrKey::OriginatorIdentifierOrKey()
2468 {
2469 choiceId = issuerAndSerialNumberCid;
2470 #if TCL
2471 issuerAndSerialNumber = new IssuerAndSerialNumber;
2472 #else
2473 issuerAndSerialNumber = NULL; // incomplete initialization of mandatory element!
2474 #endif // TCL
2475 }
2476
2477 OriginatorIdentifierOrKey::OriginatorIdentifierOrKey (const OriginatorIdentifierOrKey &)
2478 {
2479 Asn1Error << "use of incompletely defined OriginatorIdentifierOrKey::OriginatorIdentifierOrKey (const OriginatorIdentifierOrKey &)" << endl;
2480 abort();
2481 }
2482
2483 OriginatorIdentifierOrKey::~OriginatorIdentifierOrKey()
2484 {
2485 switch (choiceId)
2486 {
2487 case issuerAndSerialNumberCid:
2488 delete issuerAndSerialNumber;
2489 break;
2490 case subjectKeyIdentifierCid:
2491 delete subjectKeyIdentifier;
2492 break;
2493 case originatorKeyCid:
2494 delete originatorKey;
2495 break;
2496 } // end of switch
2497 } // end of destructor
2498
2499 AsnType *OriginatorIdentifierOrKey::Clone() const
2500 {
2501 return new OriginatorIdentifierOrKey;
2502 }
2503
2504 AsnType *OriginatorIdentifierOrKey::Copy() const
2505 {
2506 return new OriginatorIdentifierOrKey (*this);
2507 }
2508
2509 #if SNACC_DEEP_COPY
2510 OriginatorIdentifierOrKey &OriginatorIdentifierOrKey::operator = (const OriginatorIdentifierOrKey &that)
2511 #else // SNACC_DEEP_COPY
2512 OriginatorIdentifierOrKey &OriginatorIdentifierOrKey::operator = (const OriginatorIdentifierOrKey &)
2513 #endif // SNACC_DEEP_COPY
2514 {
2515 #if SNACC_DEEP_COPY
2516 if (this != &that)
2517 {
2518 switch (choiceId)
2519 {
2520 case issuerAndSerialNumberCid:
2521 delete issuerAndSerialNumber;
2522 break;
2523 case subjectKeyIdentifierCid:
2524 delete subjectKeyIdentifier;
2525 break;
2526 case originatorKeyCid:
2527 delete originatorKey;
2528 break;
2529 }
2530 switch (choiceId = that.choiceId)
2531 {
2532 case issuerAndSerialNumberCid:
2533 issuerAndSerialNumber = new IssuerAndSerialNumber;
2534 *issuerAndSerialNumber = *that.issuerAndSerialNumber;
2535 break;
2536 case subjectKeyIdentifierCid:
2537 subjectKeyIdentifier = new KeyIdentifier;
2538 *subjectKeyIdentifier = *that.subjectKeyIdentifier;
2539 break;
2540 case originatorKeyCid:
2541 originatorKey = new OriginatorPublicKey;
2542 *originatorKey = *that.originatorKey;
2543 break;
2544 }
2545 }
2546
2547 return *this;
2548 #else // SNACC_DEEP_COPY
2549 Asn1Error << "use of incompletely defined OriginatorIdentifierOrKey &OriginatorIdentifierOrKey::operator = (const OriginatorIdentifierOrKey &)" << endl;
2550 abort();
2551 // if your compiler complains here, check the -novolat option
2552 #endif // SNACC_DEEP_COPY
2553 }
2554
2555 AsnLen
2556 OriginatorIdentifierOrKey::BEncContent (BUF_TYPE b)
2557 {
2558 AsnLen l;
2559 switch (choiceId)
2560 {
2561 case issuerAndSerialNumberCid:
2562 BEncEocIfNec (b);
2563 l = issuerAndSerialNumber->BEncContent (b);
2564 l += BEncConsLen (b, l);
2565
2566 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2567 break;
2568
2569 case subjectKeyIdentifierCid:
2570 l = subjectKeyIdentifier->BEncContent (b);
2571 l += BEncDefLen (b, l);
2572
2573 l += BEncTag1 (b, CNTX, PRIM, 0);
2574 break;
2575
2576 case originatorKeyCid:
2577 BEncEocIfNec (b);
2578 l = originatorKey->BEncContent (b);
2579 l += BEncConsLen (b, l);
2580
2581 l += BEncTag1 (b, CNTX, CONS, 1);
2582 break;
2583
2584 } // end switch
2585 return l;
2586 } // OriginatorIdentifierOrKey::BEncContent
2587
2588
2589 void OriginatorIdentifierOrKey::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
2590 {
2591 switch (tag)
2592 {
2593 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
2594 choiceId = issuerAndSerialNumberCid;
2595 issuerAndSerialNumber = new IssuerAndSerialNumber;
2596 issuerAndSerialNumber->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
2597 break;
2598
2599 case MAKE_TAG_ID (CNTX, PRIM, 0):
2600 case MAKE_TAG_ID (CNTX, CONS, 0):
2601 choiceId = subjectKeyIdentifierCid;
2602 subjectKeyIdentifier = new KeyIdentifier;
2603 subjectKeyIdentifier->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
2604 break;
2605
2606 case MAKE_TAG_ID (CNTX, CONS, 1):
2607 choiceId = originatorKeyCid;
2608 originatorKey = new OriginatorPublicKey;
2609 originatorKey->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
2610 break;
2611
2612 default:
2613 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
2614 longjmp (env, -125);
2615 break;
2616 } // end switch
2617 } // OriginatorIdentifierOrKey::BDecContent
2618
2619
2620 AsnLen OriginatorIdentifierOrKey::BEnc (BUF_TYPE b)
2621 {
2622 AsnLen l;
2623 l = BEncContent (b);
2624 return l;
2625 }
2626
2627 void OriginatorIdentifierOrKey::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
2628 {
2629 AsnLen elmtLen;
2630 AsnTag tag;
2631
2632 /* CHOICEs are a special case - grab identifying tag */
2633 /* this allows easier handling of nested CHOICEs */
2634 tag = BDecTag (b, bytesDecoded, env);
2635 elmtLen = BDecLen (b, bytesDecoded, env);
2636 BDecContent (b, tag, elmtLen, bytesDecoded, env);
2637 }
2638
2639 int OriginatorIdentifierOrKey::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
2640 {
2641 bytesEncoded = BEnc (b);
2642 return !b.WriteError();
2643 }
2644
2645 int OriginatorIdentifierOrKey::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
2646 {
2647 ENV_TYPE env;
2648 int val;
2649
2650 bytesDecoded = 0;
2651 if ((val = setjmp (env)) == 0)
2652 {
2653 BDec (b, bytesDecoded, env);
2654 return !b.ReadError();
2655 }
2656 else
2657 return false;
2658 }
2659
2660 void OriginatorIdentifierOrKey::Print (ostream &os) const
2661 {
2662 #ifndef NDEBUG
2663 switch (choiceId)
2664 {
2665 case issuerAndSerialNumberCid:
2666 os << "issuerAndSerialNumber ";
2667 if (issuerAndSerialNumber)
2668 os << *issuerAndSerialNumber;
2669 else
2670 os << "-- void3 --\n";
2671 break;
2672
2673 case subjectKeyIdentifierCid:
2674 os << "subjectKeyIdentifier ";
2675 if (subjectKeyIdentifier)
2676 os << *subjectKeyIdentifier;
2677 else
2678 os << "-- void3 --\n";
2679 break;
2680
2681 case originatorKeyCid:
2682 os << "originatorKey ";
2683 if (originatorKey)
2684 os << *originatorKey;
2685 else
2686 os << "-- void3 --\n";
2687 break;
2688
2689 } // end of switch
2690 #endif /* NDEBUG */
2691 } // OriginatorIdentifierOrKey::Print
2692
2693 RecipientKeyIdentifier::RecipientKeyIdentifier()
2694 {
2695 date = NULL;
2696 other = NULL;
2697 }
2698
2699 RecipientKeyIdentifier::RecipientKeyIdentifier (const RecipientKeyIdentifier &)
2700 {
2701 Asn1Error << "use of incompletely defined RecipientKeyIdentifier::RecipientKeyIdentifier (const RecipientKeyIdentifier &)" << endl;
2702 abort();
2703 }
2704
2705 RecipientKeyIdentifier::~RecipientKeyIdentifier()
2706 {
2707 delete date;
2708 delete other;
2709 }
2710
2711 AsnType *RecipientKeyIdentifier::Clone() const
2712 {
2713 return new RecipientKeyIdentifier;
2714 }
2715
2716 AsnType *RecipientKeyIdentifier::Copy() const
2717 {
2718 return new RecipientKeyIdentifier (*this);
2719 }
2720
2721 #if SNACC_DEEP_COPY
2722 RecipientKeyIdentifier &RecipientKeyIdentifier::operator = (const RecipientKeyIdentifier &that)
2723 #else // SNACC_DEEP_COPY
2724 RecipientKeyIdentifier &RecipientKeyIdentifier::operator = (const RecipientKeyIdentifier &)
2725 #endif // SNACC_DEEP_COPY
2726 {
2727 #if SNACC_DEEP_COPY
2728 if (this != &that)
2729 {
2730 subjectKeyIdentifier = that.subjectKeyIdentifier;
2731 if (that.date)
2732 {
2733 if (!date)
2734 date = new GeneralizedTime;
2735 *date = *that.date;
2736 }
2737 else
2738 {
2739 delete date;
2740 date = NULL;
2741 }
2742 if (that.other)
2743 {
2744 if (!other)
2745 other = new OtherKeyAttribute;
2746 *other = *that.other;
2747 }
2748 else
2749 {
2750 delete other;
2751 other = NULL;
2752 }
2753 }
2754
2755 return *this;
2756 #else // SNACC_DEEP_COPY
2757 Asn1Error << "use of incompletely defined RecipientKeyIdentifier &RecipientKeyIdentifier::operator = (const RecipientKeyIdentifier &)" << endl;
2758 abort();
2759 // if your compiler complains here, check the -novolat option
2760 #endif // SNACC_DEEP_COPY
2761 }
2762
2763 AsnLen
2764 RecipientKeyIdentifier::BEncContent (BUF_TYPE b)
2765 {
2766 AsnLen totalLen = 0;
2767 AsnLen l;
2768
2769 if (NOT_NULL (other))
2770 {
2771 BEncEocIfNec (b);
2772 l = other->BEncContent (b);
2773 l += BEncConsLen (b, l);
2774
2775 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2776 totalLen += l;
2777 }
2778
2779 if (NOT_NULL (date))
2780 {
2781 l = date->BEncContent (b);
2782 l += BEncDefLen (b, l);
2783
2784 l += BEncTag1 (b, UNIV, PRIM, GENERALIZEDTIME_TAG_CODE);
2785 totalLen += l;
2786 }
2787
2788 l = subjectKeyIdentifier.BEncContent (b);
2789 l += BEncDefLen (b, l);
2790
2791 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
2792 totalLen += l;
2793
2794 return totalLen;
2795 } // RecipientKeyIdentifier::BEncContent
2796
2797
2798 void RecipientKeyIdentifier::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
2799 {
2800 AsnTag tag1;
2801 AsnLen seqBytesDecoded = 0;
2802 AsnLen elmtLen1;
2803 tag1 = BDecTag (b, seqBytesDecoded, env);
2804
2805 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
2806 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
2807 {
2808 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2809 subjectKeyIdentifier.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2810 if (seqBytesDecoded == elmtLen0)
2811 {
2812 bytesDecoded += seqBytesDecoded;
2813 return;
2814 }
2815 else
2816 {
2817 tag1 = BDecTag (b, seqBytesDecoded, env);
2818
2819 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
2820 {
2821 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
2822 bytesDecoded += seqBytesDecoded;
2823 return;
2824 }
2825 }
2826 }
2827 else
2828 {
2829 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
2830 longjmp (env, -126);
2831 }
2832
2833 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))
2834 || (tag1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))
2835 {
2836 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2837 date = new GeneralizedTime;
2838 date->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2839 if (seqBytesDecoded == elmtLen0)
2840 {
2841 bytesDecoded += seqBytesDecoded;
2842 return;
2843 }
2844 else
2845 {
2846 tag1 = BDecTag (b, seqBytesDecoded, env);
2847
2848 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
2849 {
2850 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
2851 bytesDecoded += seqBytesDecoded;
2852 return;
2853 }
2854 }
2855 }
2856
2857 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
2858 {
2859 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
2860 other = new OtherKeyAttribute;
2861 other->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
2862 }
2863
2864 bytesDecoded += seqBytesDecoded;
2865 if (elmtLen0 == INDEFINITE_LEN)
2866 {
2867 BDecEoc (b, bytesDecoded, env);
2868 return;
2869 }
2870 else if (seqBytesDecoded != elmtLen0)
2871 {
2872 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
2873 longjmp (env, -127);
2874 }
2875 else
2876 return;
2877 } // RecipientKeyIdentifier::BDecContent
2878
2879 AsnLen RecipientKeyIdentifier::BEnc (BUF_TYPE b)
2880 {
2881 AsnLen l;
2882 l = BEncContent (b);
2883 l += BEncConsLen (b, l);
2884 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
2885 return l;
2886 }
2887
2888 void RecipientKeyIdentifier::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
2889 {
2890 AsnTag tag;
2891 AsnLen elmtLen1;
2892
2893 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
2894 {
2895 Asn1Error << "RecipientKeyIdentifier::BDec: ERROR - wrong tag" << endl;
2896 longjmp (env, -128);
2897 }
2898 elmtLen1 = BDecLen (b, bytesDecoded, env);
2899 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
2900 }
2901
2902 int RecipientKeyIdentifier::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
2903 {
2904 bytesEncoded = BEnc (b);
2905 return !b.WriteError();
2906 }
2907
2908 int RecipientKeyIdentifier::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
2909 {
2910 ENV_TYPE env;
2911 int val;
2912
2913 bytesDecoded = 0;
2914 if ((val = setjmp (env)) == 0)
2915 {
2916 BDec (b, bytesDecoded, env);
2917 return !b.ReadError();
2918 }
2919 else
2920 return false;
2921 }
2922
2923 void RecipientKeyIdentifier::Print (ostream &os) const
2924 {
2925 #ifndef NDEBUG
2926 os << "{ -- SEQUENCE --" << endl;
2927 indentG += stdIndentG;
2928
2929 {
2930 Indent (os, indentG);
2931 os << "subjectKeyIdentifier ";
2932 os << subjectKeyIdentifier;
2933 os << "," << endl;
2934 }
2935
2936 if (NOT_NULL (date))
2937 {
2938 os << ","<< endl;
2939 Indent (os, indentG);
2940 os << "date ";
2941 os << *date;
2942 }
2943 else
2944 {
2945 Indent (os, indentG);
2946 os << "date ";
2947 os << "-- void --";
2948 os << "," << endl;
2949 }
2950
2951 if (NOT_NULL (other))
2952 {
2953 os << ","<< endl;
2954 Indent (os, indentG);
2955 os << "other ";
2956 os << *other;
2957 }
2958 else
2959 {
2960 Indent (os, indentG);
2961 os << "other ";
2962 os << "-- void --";
2963 os << endl;
2964 }
2965
2966 os << endl;
2967 indentG -= stdIndentG;
2968 Indent (os, indentG);
2969 os << "}";
2970 #endif /* NDEBUG */
2971 } // RecipientKeyIdentifier::Print
2972
2973
2974 KEKIdentifier::KEKIdentifier()
2975 {
2976 date = NULL;
2977 other = NULL;
2978 }
2979
2980 KEKIdentifier::KEKIdentifier (const KEKIdentifier &)
2981 {
2982 Asn1Error << "use of incompletely defined KEKIdentifier::KEKIdentifier (const KEKIdentifier &)" << endl;
2983 abort();
2984 }
2985
2986 KEKIdentifier::~KEKIdentifier()
2987 {
2988 delete date;
2989 delete other;
2990 }
2991
2992 AsnType *KEKIdentifier::Clone() const
2993 {
2994 return new KEKIdentifier;
2995 }
2996
2997 AsnType *KEKIdentifier::Copy() const
2998 {
2999 return new KEKIdentifier (*this);
3000 }
3001
3002 #if SNACC_DEEP_COPY
3003 KEKIdentifier &KEKIdentifier::operator = (const KEKIdentifier &that)
3004 #else // SNACC_DEEP_COPY
3005 KEKIdentifier &KEKIdentifier::operator = (const KEKIdentifier &)
3006 #endif // SNACC_DEEP_COPY
3007 {
3008 #if SNACC_DEEP_COPY
3009 if (this != &that)
3010 {
3011 keyIdentifier = that.keyIdentifier;
3012 if (that.date)
3013 {
3014 if (!date)
3015 date = new GeneralizedTime;
3016 *date = *that.date;
3017 }
3018 else
3019 {
3020 delete date;
3021 date = NULL;
3022 }
3023 if (that.other)
3024 {
3025 if (!other)
3026 other = new OtherKeyAttribute;
3027 *other = *that.other;
3028 }
3029 else
3030 {
3031 delete other;
3032 other = NULL;
3033 }
3034 }
3035
3036 return *this;
3037 #else // SNACC_DEEP_COPY
3038 Asn1Error << "use of incompletely defined KEKIdentifier &KEKIdentifier::operator = (const KEKIdentifier &)" << endl;
3039 abort();
3040 // if your compiler complains here, check the -novolat option
3041 #endif // SNACC_DEEP_COPY
3042 }
3043
3044 AsnLen
3045 KEKIdentifier::BEncContent (BUF_TYPE b)
3046 {
3047 AsnLen totalLen = 0;
3048 AsnLen l;
3049
3050 if (NOT_NULL (other))
3051 {
3052 BEncEocIfNec (b);
3053 l = other->BEncContent (b);
3054 l += BEncConsLen (b, l);
3055
3056 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3057 totalLen += l;
3058 }
3059
3060 if (NOT_NULL (date))
3061 {
3062 l = date->BEncContent (b);
3063 l += BEncDefLen (b, l);
3064
3065 l += BEncTag1 (b, UNIV, PRIM, GENERALIZEDTIME_TAG_CODE);
3066 totalLen += l;
3067 }
3068
3069 l = keyIdentifier.BEncContent (b);
3070 l += BEncDefLen (b, l);
3071
3072 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
3073 totalLen += l;
3074
3075 return totalLen;
3076 } // KEKIdentifier::BEncContent
3077
3078
3079 void KEKIdentifier::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
3080 {
3081 AsnTag tag1;
3082 AsnLen seqBytesDecoded = 0;
3083 AsnLen elmtLen1;
3084 tag1 = BDecTag (b, seqBytesDecoded, env);
3085
3086 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
3087 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
3088 {
3089 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3090 keyIdentifier.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3091 if (seqBytesDecoded == elmtLen0)
3092 {
3093 bytesDecoded += seqBytesDecoded;
3094 return;
3095 }
3096 else
3097 {
3098 tag1 = BDecTag (b, seqBytesDecoded, env);
3099
3100 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
3101 {
3102 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
3103 bytesDecoded += seqBytesDecoded;
3104 return;
3105 }
3106 }
3107 }
3108 else
3109 {
3110 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3111 longjmp (env, -129);
3112 }
3113
3114 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))
3115 || (tag1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))
3116 {
3117 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3118 date = new GeneralizedTime;
3119 date->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3120 if (seqBytesDecoded == elmtLen0)
3121 {
3122 bytesDecoded += seqBytesDecoded;
3123 return;
3124 }
3125 else
3126 {
3127 tag1 = BDecTag (b, seqBytesDecoded, env);
3128
3129 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
3130 {
3131 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
3132 bytesDecoded += seqBytesDecoded;
3133 return;
3134 }
3135 }
3136 }
3137
3138 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
3139 {
3140 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3141 other = new OtherKeyAttribute;
3142 other->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3143 }
3144
3145 bytesDecoded += seqBytesDecoded;
3146 if (elmtLen0 == INDEFINITE_LEN)
3147 {
3148 BDecEoc (b, bytesDecoded, env);
3149 return;
3150 }
3151 else if (seqBytesDecoded != elmtLen0)
3152 {
3153 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
3154 longjmp (env, -130);
3155 }
3156 else
3157 return;
3158 } // KEKIdentifier::BDecContent
3159
3160 AsnLen KEKIdentifier::BEnc (BUF_TYPE b)
3161 {
3162 AsnLen l;
3163 l = BEncContent (b);
3164 l += BEncConsLen (b, l);
3165 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3166 return l;
3167 }
3168
3169 void KEKIdentifier::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
3170 {
3171 AsnTag tag;
3172 AsnLen elmtLen1;
3173
3174 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
3175 {
3176 Asn1Error << "KEKIdentifier::BDec: ERROR - wrong tag" << endl;
3177 longjmp (env, -131);
3178 }
3179 elmtLen1 = BDecLen (b, bytesDecoded, env);
3180 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
3181 }
3182
3183 int KEKIdentifier::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
3184 {
3185 bytesEncoded = BEnc (b);
3186 return !b.WriteError();
3187 }
3188
3189 int KEKIdentifier::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
3190 {
3191 ENV_TYPE env;
3192 int val;
3193
3194 bytesDecoded = 0;
3195 if ((val = setjmp (env)) == 0)
3196 {
3197 BDec (b, bytesDecoded, env);
3198 return !b.ReadError();
3199 }
3200 else
3201 return false;
3202 }
3203
3204 void KEKIdentifier::Print (ostream &os) const
3205 {
3206 #ifndef NDEBUG
3207 os << "{ -- SEQUENCE --" << endl;
3208 indentG += stdIndentG;
3209
3210 {
3211 Indent (os, indentG);
3212 os << "keyIdentifier ";
3213 os << keyIdentifier;
3214 os << "," << endl;
3215 }
3216
3217 if (NOT_NULL (date))
3218 {
3219 os << ","<< endl;
3220 Indent (os, indentG);
3221 os << "date ";
3222 os << *date;
3223 }
3224 else
3225 {
3226 Indent (os, indentG);
3227 os << "date ";
3228 os << "-- void --";
3229 os << "," << endl;
3230 }
3231
3232 if (NOT_NULL (other))
3233 {
3234 os << ","<< endl;
3235 Indent (os, indentG);
3236 os << "other ";
3237 os << *other;
3238 }
3239 else
3240 {
3241 Indent (os, indentG);
3242 os << "other ";
3243 os << "-- void --";
3244 os << endl;
3245 }
3246
3247 os << endl;
3248 indentG -= stdIndentG;
3249 Indent (os, indentG);
3250 os << "}";
3251 #endif /* NDEBUG */
3252 } // KEKIdentifier::Print
3253
3254
3255 ExtendedCertificateInfo::ExtendedCertificateInfo()
3256 {
3257 #if TCL
3258 certificate = new Certificate;
3259 #else
3260 certificate = NULL; // incomplete initialization of mandatory element!
3261 #endif // TCL
3262 }
3263
3264 ExtendedCertificateInfo::ExtendedCertificateInfo (const ExtendedCertificateInfo &)
3265 {
3266 Asn1Error << "use of incompletely defined ExtendedCertificateInfo::ExtendedCertificateInfo (const ExtendedCertificateInfo &)" << endl;
3267 abort();
3268 }
3269
3270 ExtendedCertificateInfo::~ExtendedCertificateInfo()
3271 {
3272 delete certificate;
3273 }
3274
3275 AsnType *ExtendedCertificateInfo::Clone() const
3276 {
3277 return new ExtendedCertificateInfo;
3278 }
3279
3280 AsnType *ExtendedCertificateInfo::Copy() const
3281 {
3282 return new ExtendedCertificateInfo (*this);
3283 }
3284
3285 #if SNACC_DEEP_COPY
3286 ExtendedCertificateInfo &ExtendedCertificateInfo::operator = (const ExtendedCertificateInfo &that)
3287 #else // SNACC_DEEP_COPY
3288 ExtendedCertificateInfo &ExtendedCertificateInfo::operator = (const ExtendedCertificateInfo &)
3289 #endif // SNACC_DEEP_COPY
3290 {
3291 #if SNACC_DEEP_COPY
3292 if (this != &that)
3293 {
3294 version = that.version;
3295 if (that.certificate)
3296 {
3297 if (!certificate)
3298 certificate = new Certificate;
3299 *certificate = *that.certificate;
3300 }
3301 else
3302 {
3303 delete certificate;
3304 certificate = NULL;
3305 }
3306 attributes = that.attributes;
3307 }
3308
3309 return *this;
3310 #else // SNACC_DEEP_COPY
3311 Asn1Error << "use of incompletely defined ExtendedCertificateInfo &ExtendedCertificateInfo::operator = (const ExtendedCertificateInfo &)" << endl;
3312 abort();
3313 // if your compiler complains here, check the -novolat option
3314 #endif // SNACC_DEEP_COPY
3315 }
3316
3317 AsnLen
3318 ExtendedCertificateInfo::BEncContent (BUF_TYPE b)
3319 {
3320 AsnLen totalLen = 0;
3321 AsnLen l;
3322
3323 BEncEocIfNec (b);
3324 l = attributes.BEncContent (b);
3325 l += BEncConsLen (b, l);
3326
3327 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
3328 totalLen += l;
3329
3330 BEncEocIfNec (b);
3331 l = certificate->BEncContent (b);
3332 l += BEncConsLen (b, l);
3333
3334 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3335 totalLen += l;
3336
3337 l = version.BEncContent (b);
3338 BEncDefLenTo127 (b, l);
3339 l++;
3340
3341 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
3342 totalLen += l;
3343
3344 return totalLen;
3345 } // ExtendedCertificateInfo::BEncContent
3346
3347
3348 void ExtendedCertificateInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
3349 {
3350 AsnTag tag1;
3351 AsnLen seqBytesDecoded = 0;
3352 AsnLen elmtLen1;
3353 tag1 = BDecTag (b, seqBytesDecoded, env);
3354
3355 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
3356 {
3357 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3358 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3359 tag1 = BDecTag (b, seqBytesDecoded, env);
3360 }
3361 else
3362 {
3363 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3364 longjmp (env, -132);
3365 }
3366
3367 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
3368 {
3369 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3370 certificate = new Certificate;
3371 certificate->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3372 tag1 = BDecTag (b, seqBytesDecoded, env);
3373 }
3374 else
3375 {
3376 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3377 longjmp (env, -133);
3378 }
3379
3380 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
3381 {
3382 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3383 attributes.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3384 }
3385 else
3386 {
3387 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3388 longjmp (env, -134);
3389 }
3390
3391 bytesDecoded += seqBytesDecoded;
3392 if (elmtLen0 == INDEFINITE_LEN)
3393 {
3394 BDecEoc (b, bytesDecoded, env);
3395 return;
3396 }
3397 else if (seqBytesDecoded != elmtLen0)
3398 {
3399 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
3400 longjmp (env, -135);
3401 }
3402 else
3403 return;
3404 } // ExtendedCertificateInfo::BDecContent
3405
3406 AsnLen ExtendedCertificateInfo::BEnc (BUF_TYPE b)
3407 {
3408 AsnLen l;
3409 l = BEncContent (b);
3410 l += BEncConsLen (b, l);
3411 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3412 return l;
3413 }
3414
3415 void ExtendedCertificateInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
3416 {
3417 AsnTag tag;
3418 AsnLen elmtLen1;
3419
3420 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
3421 {
3422 Asn1Error << "ExtendedCertificateInfo::BDec: ERROR - wrong tag" << endl;
3423 longjmp (env, -136);
3424 }
3425 elmtLen1 = BDecLen (b, bytesDecoded, env);
3426 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
3427 }
3428
3429 int ExtendedCertificateInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
3430 {
3431 bytesEncoded = BEnc (b);
3432 return !b.WriteError();
3433 }
3434
3435 int ExtendedCertificateInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
3436 {
3437 ENV_TYPE env;
3438 int val;
3439
3440 bytesDecoded = 0;
3441 if ((val = setjmp (env)) == 0)
3442 {
3443 BDec (b, bytesDecoded, env);
3444 return !b.ReadError();
3445 }
3446 else
3447 return false;
3448 }
3449
3450 void ExtendedCertificateInfo::Print (ostream &os) const
3451 {
3452 #ifndef NDEBUG
3453 os << "{ -- SEQUENCE --" << endl;
3454 indentG += stdIndentG;
3455
3456 {
3457 Indent (os, indentG);
3458 os << "version ";
3459 os << version;
3460 os << "," << endl;
3461 }
3462
3463 if (NOT_NULL (certificate))
3464 {
3465 Indent (os, indentG);
3466 os << "certificate ";
3467 os << *certificate;
3468 }
3469 else
3470 {
3471 Indent (os, indentG);
3472 os << "certificate ";
3473 os << "-- void --";
3474 os << "," << endl;
3475 }
3476
3477 {
3478 Indent (os, indentG);
3479 os << "attributes ";
3480 os << attributes;
3481 }
3482
3483 os << endl;
3484 indentG -= stdIndentG;
3485 Indent (os, indentG);
3486 os << "}";
3487 #endif /* NDEBUG */
3488 } // ExtendedCertificateInfo::Print
3489
3490
3491 SignerInfo::SignerInfo()
3492 {
3493 #if TCL
3494 sid = new SignerIdentifier;
3495 #else
3496 sid = NULL; // incomplete initialization of mandatory element!
3497 #endif // TCL
3498 #if TCL
3499 digestAlgorithm = new DigestAlgorithmIdentifier;
3500 #else
3501 digestAlgorithm = NULL; // incomplete initialization of mandatory element!
3502 #endif // TCL
3503 signedAttrs = NULL;
3504 #if TCL
3505 signatureAlgorithm = new SignatureAlgorithmIdentifier;
3506 #else
3507 signatureAlgorithm = NULL; // incomplete initialization of mandatory element!
3508 #endif // TCL
3509 unsignedAttrs = NULL;
3510 }
3511
3512 SignerInfo::SignerInfo (const SignerInfo &)
3513 {
3514 Asn1Error << "use of incompletely defined SignerInfo::SignerInfo (const SignerInfo &)" << endl;
3515 abort();
3516 }
3517
3518 SignerInfo::~SignerInfo()
3519 {
3520 delete sid;
3521 delete digestAlgorithm;
3522 delete signedAttrs;
3523 delete signatureAlgorithm;
3524 delete unsignedAttrs;
3525 }
3526
3527 AsnType *SignerInfo::Clone() const
3528 {
3529 return new SignerInfo;
3530 }
3531
3532 AsnType *SignerInfo::Copy() const
3533 {
3534 return new SignerInfo (*this);
3535 }
3536
3537 #if SNACC_DEEP_COPY
3538 SignerInfo &SignerInfo::operator = (const SignerInfo &that)
3539 #else // SNACC_DEEP_COPY
3540 SignerInfo &SignerInfo::operator = (const SignerInfo &)
3541 #endif // SNACC_DEEP_COPY
3542 {
3543 #if SNACC_DEEP_COPY
3544 if (this != &that)
3545 {
3546 version = that.version;
3547 if (that.sid)
3548 {
3549 if (!sid)
3550 sid = new SignerIdentifier;
3551 *sid = *that.sid;
3552 }
3553 else
3554 {
3555 delete sid;
3556 sid = NULL;
3557 }
3558 if (that.digestAlgorithm)
3559 {
3560 if (!digestAlgorithm)
3561 digestAlgorithm = new DigestAlgorithmIdentifier;
3562 *digestAlgorithm = *that.digestAlgorithm;
3563 }
3564 else
3565 {
3566 delete digestAlgorithm;
3567 digestAlgorithm = NULL;
3568 }
3569 if (that.signedAttrs)
3570 {
3571 if (!signedAttrs)
3572 signedAttrs = new Attributes;
3573 *signedAttrs = *that.signedAttrs;
3574 }
3575 else
3576 {
3577 delete signedAttrs;
3578 signedAttrs = NULL;
3579 }
3580 if (that.signatureAlgorithm)
3581 {
3582 if (!signatureAlgorithm)
3583 signatureAlgorithm = new SignatureAlgorithmIdentifier;
3584 *signatureAlgorithm = *that.signatureAlgorithm;
3585 }
3586 else
3587 {
3588 delete signatureAlgorithm;
3589 signatureAlgorithm = NULL;
3590 }
3591 signature = that.signature;
3592 if (that.unsignedAttrs)
3593 {
3594 if (!unsignedAttrs)
3595 unsignedAttrs = new Attributes;
3596 *unsignedAttrs = *that.unsignedAttrs;
3597 }
3598 else
3599 {
3600 delete unsignedAttrs;
3601 unsignedAttrs = NULL;
3602 }
3603 }
3604
3605 return *this;
3606 #else // SNACC_DEEP_COPY
3607 Asn1Error << "use of incompletely defined SignerInfo &SignerInfo::operator = (const SignerInfo &)" << endl;
3608 abort();
3609 // if your compiler complains here, check the -novolat option
3610 #endif // SNACC_DEEP_COPY
3611 }
3612
3613 AsnLen
3614 SignerInfo::BEncContent (BUF_TYPE b)
3615 {
3616 AsnLen totalLen = 0;
3617 AsnLen l;
3618
3619 if (NOT_NULL (unsignedAttrs))
3620 {
3621 BEncEocIfNec (b);
3622 l = unsignedAttrs->BEncContent (b);
3623 l += BEncConsLen (b, l);
3624
3625 l += BEncTag1 (b, CNTX, CONS, 1);
3626 totalLen += l;
3627 }
3628
3629 l = signature.BEncContent (b);
3630 l += BEncDefLen (b, l);
3631
3632 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
3633 totalLen += l;
3634
3635 BEncEocIfNec (b);
3636 l = signatureAlgorithm->BEncContent (b);
3637 l += BEncConsLen (b, l);
3638
3639 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3640 totalLen += l;
3641
3642 if (NOT_NULL (signedAttrs))
3643 {
3644 BEncEocIfNec (b);
3645 l = signedAttrs->BEncContent (b);
3646 l += BEncConsLen (b, l);
3647
3648 l += BEncTag1 (b, CNTX, CONS, 0);
3649 totalLen += l;
3650 }
3651
3652 BEncEocIfNec (b);
3653 l = digestAlgorithm->BEncContent (b);
3654 l += BEncConsLen (b, l);
3655
3656 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3657 totalLen += l;
3658
3659 l = sid->BEncContent (b);
3660 totalLen += l;
3661
3662 l = version.BEncContent (b);
3663 BEncDefLenTo127 (b, l);
3664 l++;
3665
3666 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
3667 totalLen += l;
3668
3669 return totalLen;
3670 } // SignerInfo::BEncContent
3671
3672
3673 void SignerInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
3674 {
3675 AsnTag tag1;
3676 AsnLen seqBytesDecoded = 0;
3677 AsnLen elmtLen1;
3678 tag1 = BDecTag (b, seqBytesDecoded, env);
3679
3680 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
3681 {
3682 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3683 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3684 tag1 = BDecTag (b, seqBytesDecoded, env);
3685 }
3686 else
3687 {
3688 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3689 longjmp (env, -137);
3690 }
3691
3692 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
3693 || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 0))
3694 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
3695 {
3696 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3697 sid = new SignerIdentifier;
3698 sid->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3699 tag1 = BDecTag (b, seqBytesDecoded, env);
3700 }
3701 else
3702 {
3703 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3704 longjmp (env, -138);
3705 }
3706
3707 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
3708 {
3709 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3710 digestAlgorithm = new DigestAlgorithmIdentifier;
3711 digestAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3712 tag1 = BDecTag (b, seqBytesDecoded, env);
3713 }
3714 else
3715 {
3716 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3717 longjmp (env, -139);
3718 }
3719
3720 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
3721 {
3722 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3723 signedAttrs = new Attributes;
3724 signedAttrs->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3725 tag1 = BDecTag (b, seqBytesDecoded, env);
3726 }
3727
3728 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
3729 {
3730 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3731 signatureAlgorithm = new SignatureAlgorithmIdentifier;
3732 signatureAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3733 tag1 = BDecTag (b, seqBytesDecoded, env);
3734 }
3735 else
3736 {
3737 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3738 longjmp (env, -140);
3739 }
3740
3741 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
3742 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
3743 {
3744 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3745 signature.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3746 if (seqBytesDecoded == elmtLen0)
3747 {
3748 bytesDecoded += seqBytesDecoded;
3749 return;
3750 }
3751 else
3752 {
3753 tag1 = BDecTag (b, seqBytesDecoded, env);
3754
3755 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
3756 {
3757 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
3758 bytesDecoded += seqBytesDecoded;
3759 return;
3760 }
3761 }
3762 }
3763 else
3764 {
3765 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
3766 longjmp (env, -141);
3767 }
3768
3769 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
3770 {
3771 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
3772 unsignedAttrs = new Attributes;
3773 unsignedAttrs->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
3774 }
3775
3776 bytesDecoded += seqBytesDecoded;
3777 if (elmtLen0 == INDEFINITE_LEN)
3778 {
3779 BDecEoc (b, bytesDecoded, env);
3780 return;
3781 }
3782 else if (seqBytesDecoded != elmtLen0)
3783 {
3784 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
3785 longjmp (env, -142);
3786 }
3787 else
3788 return;
3789 } // SignerInfo::BDecContent
3790
3791 AsnLen SignerInfo::BEnc (BUF_TYPE b)
3792 {
3793 AsnLen l;
3794 l = BEncContent (b);
3795 l += BEncConsLen (b, l);
3796 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
3797 return l;
3798 }
3799
3800 void SignerInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
3801 {
3802 AsnTag tag;
3803 AsnLen elmtLen1;
3804
3805 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
3806 {
3807 Asn1Error << "SignerInfo::BDec: ERROR - wrong tag" << endl;
3808 longjmp (env, -143);
3809 }
3810 elmtLen1 = BDecLen (b, bytesDecoded, env);
3811 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
3812 }
3813
3814 int SignerInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
3815 {
3816 bytesEncoded = BEnc (b);
3817 return !b.WriteError();
3818 }
3819
3820 int SignerInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
3821 {
3822 ENV_TYPE env;
3823 int val;
3824
3825 bytesDecoded = 0;
3826 if ((val = setjmp (env)) == 0)
3827 {
3828 BDec (b, bytesDecoded, env);
3829 return !b.ReadError();
3830 }
3831 else
3832 return false;
3833 }
3834
3835 void SignerInfo::Print (ostream &os) const
3836 {
3837 #ifndef NDEBUG
3838 os << "{ -- SEQUENCE --" << endl;
3839 indentG += stdIndentG;
3840
3841 {
3842 Indent (os, indentG);
3843 os << "version ";
3844 os << version;
3845 os << "," << endl;
3846 }
3847
3848 if (NOT_NULL (sid))
3849 {
3850 Indent (os, indentG);
3851 os << "sid ";
3852 os << *sid;
3853 }
3854 else
3855 {
3856 Indent (os, indentG);
3857 os << "sid ";
3858 os << "-- void --";
3859 os << "," << endl;
3860 }
3861
3862 if (NOT_NULL (digestAlgorithm))
3863 {
3864 Indent (os, indentG);
3865 os << "digestAlgorithm ";
3866 os << *digestAlgorithm;
3867 }
3868 else
3869 {
3870 Indent (os, indentG);
3871 os << "digestAlgorithm ";
3872 os << "-- void --";
3873 os << "," << endl;
3874 }
3875
3876 if (NOT_NULL (signedAttrs))
3877 {
3878 Indent (os, indentG);
3879 os << "signedAttrs ";
3880 os << *signedAttrs;
3881 }
3882 else
3883 {
3884 Indent (os, indentG);
3885 os << "signedAttrs ";
3886 os << "-- void --";
3887 os << "," << endl;
3888 }
3889
3890 if (NOT_NULL (signatureAlgorithm))
3891 {
3892 Indent (os, indentG);
3893 os << "signatureAlgorithm ";
3894 os << *signatureAlgorithm;
3895 }
3896 else
3897 {
3898 Indent (os, indentG);
3899 os << "signatureAlgorithm ";
3900 os << "-- void --";
3901 os << "," << endl;
3902 }
3903
3904 {
3905 Indent (os, indentG);
3906 os << "signature ";
3907 os << signature;
3908 os << "," << endl;
3909 }
3910
3911 if (NOT_NULL (unsignedAttrs))
3912 {
3913 os << ","<< endl;
3914 Indent (os, indentG);
3915 os << "unsignedAttrs ";
3916 os << *unsignedAttrs;
3917 }
3918 else
3919 {
3920 Indent (os, indentG);
3921 os << "unsignedAttrs ";
3922 os << "-- void --";
3923 os << endl;
3924 }
3925
3926 os << endl;
3927 indentG -= stdIndentG;
3928 Indent (os, indentG);
3929 os << "}";
3930 #endif /* NDEBUG */
3931 } // SignerInfo::Print
3932
3933
3934 KeyTransRecipientInfo::KeyTransRecipientInfo()
3935 {
3936 #if TCL
3937 rid = new RecipientIdentifier;
3938 #else
3939 rid = NULL; // incomplete initialization of mandatory element!
3940 #endif // TCL
3941 #if TCL
3942 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
3943 #else
3944 keyEncryptionAlgorithm = NULL; // incomplete initialization of mandatory element!
3945 #endif // TCL
3946 }
3947
3948 KeyTransRecipientInfo::KeyTransRecipientInfo (const KeyTransRecipientInfo &)
3949 {
3950 Asn1Error << "use of incompletely defined KeyTransRecipientInfo::KeyTransRecipientInfo (const KeyTransRecipientInfo &)" << endl;
3951 abort();
3952 }
3953
3954 KeyTransRecipientInfo::~KeyTransRecipientInfo()
3955 {
3956 delete rid;
3957 delete keyEncryptionAlgorithm;
3958 }
3959
3960 AsnType *KeyTransRecipientInfo::Clone() const
3961 {
3962 return new KeyTransRecipientInfo;
3963 }
3964
3965 AsnType *KeyTransRecipientInfo::Copy() const
3966 {
3967 return new KeyTransRecipientInfo (*this);
3968 }
3969
3970 #if SNACC_DEEP_COPY
3971 KeyTransRecipientInfo &KeyTransRecipientInfo::operator = (const KeyTransRecipientInfo &that)
3972 #else // SNACC_DEEP_COPY
3973 KeyTransRecipientInfo &KeyTransRecipientInfo::operator = (const KeyTransRecipientInfo &)
3974 #endif // SNACC_DEEP_COPY
3975 {
3976 #if SNACC_DEEP_COPY
3977 if (this != &that)
3978 {
3979 version = that.version;
3980 if (that.rid)
3981 {
3982 if (!rid)
3983 rid = new RecipientIdentifier;
3984 *rid = *that.rid;
3985 }
3986 else
3987 {
3988 delete rid;
3989 rid = NULL;
3990 }
3991 if (that.keyEncryptionAlgorithm)
3992 {
3993 if (!keyEncryptionAlgorithm)
3994 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
3995 *keyEncryptionAlgorithm = *that.keyEncryptionAlgorithm;
3996 }
3997 else
3998 {
3999 delete keyEncryptionAlgorithm;
4000 keyEncryptionAlgorithm = NULL;
4001 }
4002 encryptedKey = that.encryptedKey;
4003 }
4004
4005 return *this;
4006 #else // SNACC_DEEP_COPY
4007 Asn1Error << "use of incompletely defined KeyTransRecipientInfo &KeyTransRecipientInfo::operator = (const KeyTransRecipientInfo &)" << endl;
4008 abort();
4009 // if your compiler complains here, check the -novolat option
4010 #endif // SNACC_DEEP_COPY
4011 }
4012
4013 AsnLen
4014 KeyTransRecipientInfo::BEncContent (BUF_TYPE b)
4015 {
4016 AsnLen totalLen = 0;
4017 AsnLen l;
4018
4019 l = encryptedKey.BEncContent (b);
4020 l += BEncDefLen (b, l);
4021
4022 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
4023 totalLen += l;
4024
4025 BEncEocIfNec (b);
4026 l = keyEncryptionAlgorithm->BEncContent (b);
4027 l += BEncConsLen (b, l);
4028
4029 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4030 totalLen += l;
4031
4032 l = rid->BEncContent (b);
4033 totalLen += l;
4034
4035 l = version.BEncContent (b);
4036 BEncDefLenTo127 (b, l);
4037 l++;
4038
4039 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
4040 totalLen += l;
4041
4042 return totalLen;
4043 } // KeyTransRecipientInfo::BEncContent
4044
4045
4046 void KeyTransRecipientInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
4047 {
4048 AsnTag tag1;
4049 AsnLen seqBytesDecoded = 0;
4050 AsnLen elmtLen1;
4051 tag1 = BDecTag (b, seqBytesDecoded, env);
4052
4053 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
4054 {
4055 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4056 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4057 tag1 = BDecTag (b, seqBytesDecoded, env);
4058 }
4059 else
4060 {
4061 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4062 longjmp (env, -144);
4063 }
4064
4065 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
4066 || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 0))
4067 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
4068 {
4069 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4070 rid = new RecipientIdentifier;
4071 rid->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4072 tag1 = BDecTag (b, seqBytesDecoded, env);
4073 }
4074 else
4075 {
4076 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4077 longjmp (env, -145);
4078 }
4079
4080 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
4081 {
4082 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4083 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
4084 keyEncryptionAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4085 tag1 = BDecTag (b, seqBytesDecoded, env);
4086 }
4087 else
4088 {
4089 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4090 longjmp (env, -146);
4091 }
4092
4093 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
4094 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
4095 {
4096 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4097 encryptedKey.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4098 }
4099 else
4100 {
4101 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4102 longjmp (env, -147);
4103 }
4104
4105 bytesDecoded += seqBytesDecoded;
4106 if (elmtLen0 == INDEFINITE_LEN)
4107 {
4108 BDecEoc (b, bytesDecoded, env);
4109 return;
4110 }
4111 else if (seqBytesDecoded != elmtLen0)
4112 {
4113 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
4114 longjmp (env, -148);
4115 }
4116 else
4117 return;
4118 } // KeyTransRecipientInfo::BDecContent
4119
4120 AsnLen KeyTransRecipientInfo::BEnc (BUF_TYPE b)
4121 {
4122 AsnLen l;
4123 l = BEncContent (b);
4124 l += BEncConsLen (b, l);
4125 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4126 return l;
4127 }
4128
4129 void KeyTransRecipientInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
4130 {
4131 AsnTag tag;
4132 AsnLen elmtLen1;
4133
4134 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
4135 {
4136 Asn1Error << "KeyTransRecipientInfo::BDec: ERROR - wrong tag" << endl;
4137 longjmp (env, -149);
4138 }
4139 elmtLen1 = BDecLen (b, bytesDecoded, env);
4140 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
4141 }
4142
4143 int KeyTransRecipientInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
4144 {
4145 bytesEncoded = BEnc (b);
4146 return !b.WriteError();
4147 }
4148
4149 int KeyTransRecipientInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
4150 {
4151 ENV_TYPE env;
4152 int val;
4153
4154 bytesDecoded = 0;
4155 if ((val = setjmp (env)) == 0)
4156 {
4157 BDec (b, bytesDecoded, env);
4158 return !b.ReadError();
4159 }
4160 else
4161 return false;
4162 }
4163
4164 void KeyTransRecipientInfo::Print (ostream &os) const
4165 {
4166 #ifndef NDEBUG
4167 os << "{ -- SEQUENCE --" << endl;
4168 indentG += stdIndentG;
4169
4170 {
4171 Indent (os, indentG);
4172 os << "version ";
4173 os << version;
4174 os << "," << endl;
4175 }
4176
4177 if (NOT_NULL (rid))
4178 {
4179 Indent (os, indentG);
4180 os << "rid ";
4181 os << *rid;
4182 }
4183 else
4184 {
4185 Indent (os, indentG);
4186 os << "rid ";
4187 os << "-- void --";
4188 os << "," << endl;
4189 }
4190
4191 if (NOT_NULL (keyEncryptionAlgorithm))
4192 {
4193 Indent (os, indentG);
4194 os << "keyEncryptionAlgorithm ";
4195 os << *keyEncryptionAlgorithm;
4196 }
4197 else
4198 {
4199 Indent (os, indentG);
4200 os << "keyEncryptionAlgorithm ";
4201 os << "-- void --";
4202 os << "," << endl;
4203 }
4204
4205 {
4206 Indent (os, indentG);
4207 os << "encryptedKey ";
4208 os << encryptedKey;
4209 }
4210
4211 os << endl;
4212 indentG -= stdIndentG;
4213 Indent (os, indentG);
4214 os << "}";
4215 #endif /* NDEBUG */
4216 } // KeyTransRecipientInfo::Print
4217
4218
4219 KeyAgreeRecipientIdentifier::KeyAgreeRecipientIdentifier()
4220 {
4221 choiceId = issuerAndSerialNumberCid;
4222 #if TCL
4223 issuerAndSerialNumber = new IssuerAndSerialNumber;
4224 #else
4225 issuerAndSerialNumber = NULL; // incomplete initialization of mandatory element!
4226 #endif // TCL
4227 }
4228
4229 KeyAgreeRecipientIdentifier::KeyAgreeRecipientIdentifier (const KeyAgreeRecipientIdentifier &)
4230 {
4231 Asn1Error << "use of incompletely defined KeyAgreeRecipientIdentifier::KeyAgreeRecipientIdentifier (const KeyAgreeRecipientIdentifier &)" << endl;
4232 abort();
4233 }
4234
4235 KeyAgreeRecipientIdentifier::~KeyAgreeRecipientIdentifier()
4236 {
4237 switch (choiceId)
4238 {
4239 case issuerAndSerialNumberCid:
4240 delete issuerAndSerialNumber;
4241 break;
4242 case rKeyIdCid:
4243 delete rKeyId;
4244 break;
4245 } // end of switch
4246 } // end of destructor
4247
4248 AsnType *KeyAgreeRecipientIdentifier::Clone() const
4249 {
4250 return new KeyAgreeRecipientIdentifier;
4251 }
4252
4253 AsnType *KeyAgreeRecipientIdentifier::Copy() const
4254 {
4255 return new KeyAgreeRecipientIdentifier (*this);
4256 }
4257
4258 #if SNACC_DEEP_COPY
4259 KeyAgreeRecipientIdentifier &KeyAgreeRecipientIdentifier::operator = (const KeyAgreeRecipientIdentifier &that)
4260 #else // SNACC_DEEP_COPY
4261 KeyAgreeRecipientIdentifier &KeyAgreeRecipientIdentifier::operator = (const KeyAgreeRecipientIdentifier &)
4262 #endif // SNACC_DEEP_COPY
4263 {
4264 #if SNACC_DEEP_COPY
4265 if (this != &that)
4266 {
4267 switch (choiceId)
4268 {
4269 case issuerAndSerialNumberCid:
4270 delete issuerAndSerialNumber;
4271 break;
4272 case rKeyIdCid:
4273 delete rKeyId;
4274 break;
4275 }
4276 switch (choiceId = that.choiceId)
4277 {
4278 case issuerAndSerialNumberCid:
4279 issuerAndSerialNumber = new IssuerAndSerialNumber;
4280 *issuerAndSerialNumber = *that.issuerAndSerialNumber;
4281 break;
4282 case rKeyIdCid:
4283 rKeyId = new RecipientKeyIdentifier;
4284 *rKeyId = *that.rKeyId;
4285 break;
4286 }
4287 }
4288
4289 return *this;
4290 #else // SNACC_DEEP_COPY
4291 Asn1Error << "use of incompletely defined KeyAgreeRecipientIdentifier &KeyAgreeRecipientIdentifier::operator = (const KeyAgreeRecipientIdentifier &)" << endl;
4292 abort();
4293 // if your compiler complains here, check the -novolat option
4294 #endif // SNACC_DEEP_COPY
4295 }
4296
4297 AsnLen
4298 KeyAgreeRecipientIdentifier::BEncContent (BUF_TYPE b)
4299 {
4300 AsnLen l;
4301 switch (choiceId)
4302 {
4303 case issuerAndSerialNumberCid:
4304 BEncEocIfNec (b);
4305 l = issuerAndSerialNumber->BEncContent (b);
4306 l += BEncConsLen (b, l);
4307
4308 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4309 break;
4310
4311 case rKeyIdCid:
4312 BEncEocIfNec (b);
4313 l = rKeyId->BEncContent (b);
4314 l += BEncConsLen (b, l);
4315
4316 l += BEncTag1 (b, CNTX, CONS, 0);
4317 break;
4318
4319 } // end switch
4320 return l;
4321 } // KeyAgreeRecipientIdentifier::BEncContent
4322
4323
4324 void KeyAgreeRecipientIdentifier::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
4325 {
4326 switch (tag)
4327 {
4328 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
4329 choiceId = issuerAndSerialNumberCid;
4330 issuerAndSerialNumber = new IssuerAndSerialNumber;
4331 issuerAndSerialNumber->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
4332 break;
4333
4334 case MAKE_TAG_ID (CNTX, CONS, 0):
4335 choiceId = rKeyIdCid;
4336 rKeyId = new RecipientKeyIdentifier;
4337 rKeyId->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
4338 break;
4339
4340 default:
4341 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
4342 longjmp (env, -150);
4343 break;
4344 } // end switch
4345 } // KeyAgreeRecipientIdentifier::BDecContent
4346
4347
4348 AsnLen KeyAgreeRecipientIdentifier::BEnc (BUF_TYPE b)
4349 {
4350 AsnLen l;
4351 l = BEncContent (b);
4352 return l;
4353 }
4354
4355 void KeyAgreeRecipientIdentifier::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
4356 {
4357 AsnLen elmtLen;
4358 AsnTag tag;
4359
4360 /* CHOICEs are a special case - grab identifying tag */
4361 /* this allows easier handling of nested CHOICEs */
4362 tag = BDecTag (b, bytesDecoded, env);
4363 elmtLen = BDecLen (b, bytesDecoded, env);
4364 BDecContent (b, tag, elmtLen, bytesDecoded, env);
4365 }
4366
4367 int KeyAgreeRecipientIdentifier::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
4368 {
4369 bytesEncoded = BEnc (b);
4370 return !b.WriteError();
4371 }
4372
4373 int KeyAgreeRecipientIdentifier::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
4374 {
4375 ENV_TYPE env;
4376 int val;
4377
4378 bytesDecoded = 0;
4379 if ((val = setjmp (env)) == 0)
4380 {
4381 BDec (b, bytesDecoded, env);
4382 return !b.ReadError();
4383 }
4384 else
4385 return false;
4386 }
4387
4388 void KeyAgreeRecipientIdentifier::Print (ostream &os) const
4389 {
4390 #ifndef NDEBUG
4391 switch (choiceId)
4392 {
4393 case issuerAndSerialNumberCid:
4394 os << "issuerAndSerialNumber ";
4395 if (issuerAndSerialNumber)
4396 os << *issuerAndSerialNumber;
4397 else
4398 os << "-- void3 --\n";
4399 break;
4400
4401 case rKeyIdCid:
4402 os << "rKeyId ";
4403 if (rKeyId)
4404 os << *rKeyId;
4405 else
4406 os << "-- void3 --\n";
4407 break;
4408
4409 } // end of switch
4410 #endif /* NDEBUG */
4411 } // KeyAgreeRecipientIdentifier::Print
4412
4413 KEKRecipientInfo::KEKRecipientInfo()
4414 {
4415 #if TCL
4416 kekid = new KEKIdentifier;
4417 #else
4418 kekid = NULL; // incomplete initialization of mandatory element!
4419 #endif // TCL
4420 #if TCL
4421 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
4422 #else
4423 keyEncryptionAlgorithm = NULL; // incomplete initialization of mandatory element!
4424 #endif // TCL
4425 }
4426
4427 KEKRecipientInfo::KEKRecipientInfo (const KEKRecipientInfo &)
4428 {
4429 Asn1Error << "use of incompletely defined KEKRecipientInfo::KEKRecipientInfo (const KEKRecipientInfo &)" << endl;
4430 abort();
4431 }
4432
4433 KEKRecipientInfo::~KEKRecipientInfo()
4434 {
4435 delete kekid;
4436 delete keyEncryptionAlgorithm;
4437 }
4438
4439 AsnType *KEKRecipientInfo::Clone() const
4440 {
4441 return new KEKRecipientInfo;
4442 }
4443
4444 AsnType *KEKRecipientInfo::Copy() const
4445 {
4446 return new KEKRecipientInfo (*this);
4447 }
4448
4449 #if SNACC_DEEP_COPY
4450 KEKRecipientInfo &KEKRecipientInfo::operator = (const KEKRecipientInfo &that)
4451 #else // SNACC_DEEP_COPY
4452 KEKRecipientInfo &KEKRecipientInfo::operator = (const KEKRecipientInfo &)
4453 #endif // SNACC_DEEP_COPY
4454 {
4455 #if SNACC_DEEP_COPY
4456 if (this != &that)
4457 {
4458 version = that.version;
4459 if (that.kekid)
4460 {
4461 if (!kekid)
4462 kekid = new KEKIdentifier;
4463 *kekid = *that.kekid;
4464 }
4465 else
4466 {
4467 delete kekid;
4468 kekid = NULL;
4469 }
4470 if (that.keyEncryptionAlgorithm)
4471 {
4472 if (!keyEncryptionAlgorithm)
4473 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
4474 *keyEncryptionAlgorithm = *that.keyEncryptionAlgorithm;
4475 }
4476 else
4477 {
4478 delete keyEncryptionAlgorithm;
4479 keyEncryptionAlgorithm = NULL;
4480 }
4481 encryptedKey = that.encryptedKey;
4482 }
4483
4484 return *this;
4485 #else // SNACC_DEEP_COPY
4486 Asn1Error << "use of incompletely defined KEKRecipientInfo &KEKRecipientInfo::operator = (const KEKRecipientInfo &)" << endl;
4487 abort();
4488 // if your compiler complains here, check the -novolat option
4489 #endif // SNACC_DEEP_COPY
4490 }
4491
4492 AsnLen
4493 KEKRecipientInfo::BEncContent (BUF_TYPE b)
4494 {
4495 AsnLen totalLen = 0;
4496 AsnLen l;
4497
4498 l = encryptedKey.BEncContent (b);
4499 l += BEncDefLen (b, l);
4500
4501 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
4502 totalLen += l;
4503
4504 BEncEocIfNec (b);
4505 l = keyEncryptionAlgorithm->BEncContent (b);
4506 l += BEncConsLen (b, l);
4507
4508 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4509 totalLen += l;
4510
4511 BEncEocIfNec (b);
4512 l = kekid->BEncContent (b);
4513 l += BEncConsLen (b, l);
4514
4515 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4516 totalLen += l;
4517
4518 l = version.BEncContent (b);
4519 BEncDefLenTo127 (b, l);
4520 l++;
4521
4522 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
4523 totalLen += l;
4524
4525 return totalLen;
4526 } // KEKRecipientInfo::BEncContent
4527
4528
4529 void KEKRecipientInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
4530 {
4531 AsnTag tag1;
4532 AsnLen seqBytesDecoded = 0;
4533 AsnLen elmtLen1;
4534 tag1 = BDecTag (b, seqBytesDecoded, env);
4535
4536 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
4537 {
4538 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4539 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4540 tag1 = BDecTag (b, seqBytesDecoded, env);
4541 }
4542 else
4543 {
4544 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4545 longjmp (env, -151);
4546 }
4547
4548 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
4549 {
4550 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4551 kekid = new KEKIdentifier;
4552 kekid->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4553 tag1 = BDecTag (b, seqBytesDecoded, env);
4554 }
4555 else
4556 {
4557 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4558 longjmp (env, -152);
4559 }
4560
4561 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
4562 {
4563 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4564 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
4565 keyEncryptionAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4566 tag1 = BDecTag (b, seqBytesDecoded, env);
4567 }
4568 else
4569 {
4570 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4571 longjmp (env, -153);
4572 }
4573
4574 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
4575 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
4576 {
4577 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4578 encryptedKey.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4579 }
4580 else
4581 {
4582 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4583 longjmp (env, -154);
4584 }
4585
4586 bytesDecoded += seqBytesDecoded;
4587 if (elmtLen0 == INDEFINITE_LEN)
4588 {
4589 BDecEoc (b, bytesDecoded, env);
4590 return;
4591 }
4592 else if (seqBytesDecoded != elmtLen0)
4593 {
4594 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
4595 longjmp (env, -155);
4596 }
4597 else
4598 return;
4599 } // KEKRecipientInfo::BDecContent
4600
4601 AsnLen KEKRecipientInfo::BEnc (BUF_TYPE b)
4602 {
4603 AsnLen l;
4604 l = BEncContent (b);
4605 l += BEncConsLen (b, l);
4606 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4607 return l;
4608 }
4609
4610 void KEKRecipientInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
4611 {
4612 AsnTag tag;
4613 AsnLen elmtLen1;
4614
4615 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
4616 {
4617 Asn1Error << "KEKRecipientInfo::BDec: ERROR - wrong tag" << endl;
4618 longjmp (env, -156);
4619 }
4620 elmtLen1 = BDecLen (b, bytesDecoded, env);
4621 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
4622 }
4623
4624 int KEKRecipientInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
4625 {
4626 bytesEncoded = BEnc (b);
4627 return !b.WriteError();
4628 }
4629
4630 int KEKRecipientInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
4631 {
4632 ENV_TYPE env;
4633 int val;
4634
4635 bytesDecoded = 0;
4636 if ((val = setjmp (env)) == 0)
4637 {
4638 BDec (b, bytesDecoded, env);
4639 return !b.ReadError();
4640 }
4641 else
4642 return false;
4643 }
4644
4645 void KEKRecipientInfo::Print (ostream &os) const
4646 {
4647 #ifndef NDEBUG
4648 os << "{ -- SEQUENCE --" << endl;
4649 indentG += stdIndentG;
4650
4651 {
4652 Indent (os, indentG);
4653 os << "version ";
4654 os << version;
4655 os << "," << endl;
4656 }
4657
4658 if (NOT_NULL (kekid))
4659 {
4660 Indent (os, indentG);
4661 os << "kekid ";
4662 os << *kekid;
4663 }
4664 else
4665 {
4666 Indent (os, indentG);
4667 os << "kekid ";
4668 os << "-- void --";
4669 os << "," << endl;
4670 }
4671
4672 if (NOT_NULL (keyEncryptionAlgorithm))
4673 {
4674 Indent (os, indentG);
4675 os << "keyEncryptionAlgorithm ";
4676 os << *keyEncryptionAlgorithm;
4677 }
4678 else
4679 {
4680 Indent (os, indentG);
4681 os << "keyEncryptionAlgorithm ";
4682 os << "-- void --";
4683 os << "," << endl;
4684 }
4685
4686 {
4687 Indent (os, indentG);
4688 os << "encryptedKey ";
4689 os << encryptedKey;
4690 }
4691
4692 os << endl;
4693 indentG -= stdIndentG;
4694 Indent (os, indentG);
4695 os << "}";
4696 #endif /* NDEBUG */
4697 } // KEKRecipientInfo::Print
4698
4699
4700 ExtendedCertificate::ExtendedCertificate()
4701 {
4702 #if TCL
4703 extendedCertificateInfo = new ExtendedCertificateInfo;
4704 #else
4705 extendedCertificateInfo = NULL; // incomplete initialization of mandatory element!
4706 #endif // TCL
4707 #if TCL
4708 signatureAlgorithm = new SignatureAlgorithmIdentifier;
4709 #else
4710 signatureAlgorithm = NULL; // incomplete initialization of mandatory element!
4711 #endif // TCL
4712 }
4713
4714 ExtendedCertificate::ExtendedCertificate (const ExtendedCertificate &)
4715 {
4716 Asn1Error << "use of incompletely defined ExtendedCertificate::ExtendedCertificate (const ExtendedCertificate &)" << endl;
4717 abort();
4718 }
4719
4720 ExtendedCertificate::~ExtendedCertificate()
4721 {
4722 delete extendedCertificateInfo;
4723 delete signatureAlgorithm;
4724 }
4725
4726 AsnType *ExtendedCertificate::Clone() const
4727 {
4728 return new ExtendedCertificate;
4729 }
4730
4731 AsnType *ExtendedCertificate::Copy() const
4732 {
4733 return new ExtendedCertificate (*this);
4734 }
4735
4736 #if SNACC_DEEP_COPY
4737 ExtendedCertificate &ExtendedCertificate::operator = (const ExtendedCertificate &that)
4738 #else // SNACC_DEEP_COPY
4739 ExtendedCertificate &ExtendedCertificate::operator = (const ExtendedCertificate &)
4740 #endif // SNACC_DEEP_COPY
4741 {
4742 #if SNACC_DEEP_COPY
4743 if (this != &that)
4744 {
4745 if (that.extendedCertificateInfo)
4746 {
4747 if (!extendedCertificateInfo)
4748 extendedCertificateInfo = new ExtendedCertificateInfo;
4749 *extendedCertificateInfo = *that.extendedCertificateInfo;
4750 }
4751 else
4752 {
4753 delete extendedCertificateInfo;
4754 extendedCertificateInfo = NULL;
4755 }
4756 if (that.signatureAlgorithm)
4757 {
4758 if (!signatureAlgorithm)
4759 signatureAlgorithm = new SignatureAlgorithmIdentifier;
4760 *signatureAlgorithm = *that.signatureAlgorithm;
4761 }
4762 else
4763 {
4764 delete signatureAlgorithm;
4765 signatureAlgorithm = NULL;
4766 }
4767 signature = that.signature;
4768 }
4769
4770 return *this;
4771 #else // SNACC_DEEP_COPY
4772 Asn1Error << "use of incompletely defined ExtendedCertificate &ExtendedCertificate::operator = (const ExtendedCertificate &)" << endl;
4773 abort();
4774 // if your compiler complains here, check the -novolat option
4775 #endif // SNACC_DEEP_COPY
4776 }
4777
4778 AsnLen
4779 ExtendedCertificate::BEncContent (BUF_TYPE b)
4780 {
4781 AsnLen totalLen = 0;
4782 AsnLen l;
4783
4784 l = signature.BEncContent (b);
4785 l += BEncDefLen (b, l);
4786
4787 l += BEncTag1 (b, UNIV, PRIM, BITSTRING_TAG_CODE);
4788 totalLen += l;
4789
4790 BEncEocIfNec (b);
4791 l = signatureAlgorithm->BEncContent (b);
4792 l += BEncConsLen (b, l);
4793
4794 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4795 totalLen += l;
4796
4797 BEncEocIfNec (b);
4798 l = extendedCertificateInfo->BEncContent (b);
4799 l += BEncConsLen (b, l);
4800
4801 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4802 totalLen += l;
4803
4804 return totalLen;
4805 } // ExtendedCertificate::BEncContent
4806
4807
4808 void ExtendedCertificate::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
4809 {
4810 AsnTag tag1;
4811 AsnLen seqBytesDecoded = 0;
4812 AsnLen elmtLen1;
4813 tag1 = BDecTag (b, seqBytesDecoded, env);
4814
4815 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
4816 {
4817 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4818 extendedCertificateInfo = new ExtendedCertificateInfo;
4819 extendedCertificateInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4820 tag1 = BDecTag (b, seqBytesDecoded, env);
4821 }
4822 else
4823 {
4824 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4825 longjmp (env, -157);
4826 }
4827
4828 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
4829 {
4830 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4831 signatureAlgorithm = new SignatureAlgorithmIdentifier;
4832 signatureAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4833 tag1 = BDecTag (b, seqBytesDecoded, env);
4834 }
4835 else
4836 {
4837 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4838 longjmp (env, -158);
4839 }
4840
4841 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE))
4842 || (tag1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))
4843 {
4844 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
4845 signature.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
4846 }
4847 else
4848 {
4849 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
4850 longjmp (env, -159);
4851 }
4852
4853 bytesDecoded += seqBytesDecoded;
4854 if (elmtLen0 == INDEFINITE_LEN)
4855 {
4856 BDecEoc (b, bytesDecoded, env);
4857 return;
4858 }
4859 else if (seqBytesDecoded != elmtLen0)
4860 {
4861 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
4862 longjmp (env, -160);
4863 }
4864 else
4865 return;
4866 } // ExtendedCertificate::BDecContent
4867
4868 AsnLen ExtendedCertificate::BEnc (BUF_TYPE b)
4869 {
4870 AsnLen l;
4871 l = BEncContent (b);
4872 l += BEncConsLen (b, l);
4873 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
4874 return l;
4875 }
4876
4877 void ExtendedCertificate::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
4878 {
4879 AsnTag tag;
4880 AsnLen elmtLen1;
4881
4882 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
4883 {
4884 Asn1Error << "ExtendedCertificate::BDec: ERROR - wrong tag" << endl;
4885 longjmp (env, -161);
4886 }
4887 elmtLen1 = BDecLen (b, bytesDecoded, env);
4888 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
4889 }
4890
4891 int ExtendedCertificate::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
4892 {
4893 bytesEncoded = BEnc (b);
4894 return !b.WriteError();
4895 }
4896
4897 int ExtendedCertificate::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
4898 {
4899 ENV_TYPE env;
4900 int val;
4901
4902 bytesDecoded = 0;
4903 if ((val = setjmp (env)) == 0)
4904 {
4905 BDec (b, bytesDecoded, env);
4906 return !b.ReadError();
4907 }
4908 else
4909 return false;
4910 }
4911
4912 void ExtendedCertificate::Print (ostream &os) const
4913 {
4914 #ifndef NDEBUG
4915 os << "{ -- SEQUENCE --" << endl;
4916 indentG += stdIndentG;
4917
4918 if (NOT_NULL (extendedCertificateInfo))
4919 {
4920 Indent (os, indentG);
4921 os << "extendedCertificateInfo ";
4922 os << *extendedCertificateInfo;
4923 }
4924 else
4925 {
4926 Indent (os, indentG);
4927 os << "extendedCertificateInfo ";
4928 os << "-- void --";
4929 os << "," << endl;
4930 }
4931
4932 if (NOT_NULL (signatureAlgorithm))
4933 {
4934 Indent (os, indentG);
4935 os << "signatureAlgorithm ";
4936 os << *signatureAlgorithm;
4937 }
4938 else
4939 {
4940 Indent (os, indentG);
4941 os << "signatureAlgorithm ";
4942 os << "-- void --";
4943 os << "," << endl;
4944 }
4945
4946 {
4947 Indent (os, indentG);
4948 os << "signature ";
4949 os << signature;
4950 }
4951
4952 os << endl;
4953 indentG -= stdIndentG;
4954 Indent (os, indentG);
4955 os << "}";
4956 #endif /* NDEBUG */
4957 } // ExtendedCertificate::Print
4958
4959
4960 AsnType *SignerInfos::Clone() const
4961 {
4962 return new SignerInfos;
4963 }
4964
4965 AsnType *SignerInfos::Copy() const
4966 {
4967 return new SignerInfos (*this);
4968 }
4969
4970 AsnLen SignerInfos::BEnc (BUF_TYPE b)
4971 {
4972 AsnLen l;
4973 l = BEncContent (b);
4974 l += BEncConsLen (b, l);
4975 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
4976 return l;
4977 }
4978
4979 void SignerInfos::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
4980 {
4981 AsnTag tag;
4982 AsnLen elmtLen1;
4983
4984 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
4985 {
4986 Asn1Error << "SignerInfos::BDec: ERROR - wrong tag" << endl;
4987 longjmp (env, -162);
4988 }
4989 elmtLen1 = BDecLen (b, bytesDecoded, env);
4990 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
4991 }
4992
4993 SignerInfos::SignerInfos (const SignerInfos &)
4994 {
4995 Asn1Error << "use of incompletely defined SignerInfos::SignerInfos (const SignerInfos &)" << endl;
4996 abort();
4997 }
4998
4999 SignerInfos::~SignerInfos()
5000 {
5001 SetCurrToFirst();
5002 for (; Curr() != NULL; RemoveCurrFromList())
5003 ;
5004 } // end of destructor
5005
5006 #if SNACC_DEEP_COPY
5007 SignerInfos &SignerInfos::operator = (const SignerInfos &that)
5008 #else // SNACC_DEEP_COPY
5009 SignerInfos &SignerInfos::operator = (const SignerInfos &)
5010 #endif // SNACC_DEEP_COPY
5011 {
5012 #if SNACC_DEEP_COPY
5013 if (this != &that)
5014 {
5015 SetCurrToFirst();
5016 for (; Curr(); RemoveCurrFromList())
5017 ;
5018
5019 //that.SetCurrToFirst();
5020 //for (; that.Curr(); that.GoNext())
5021 // AppendCopy (*that.Curr());
5022 for (const AsnListElmt *run=that.first; run; run=run->next)
5023 AppendCopy (*run->elmt);
5024 }
5025
5026 return *this;
5027 #else // SNACC_DEEP_COPY
5028 Asn1Error << "use of incompletely defined SignerInfos &SignerInfos::operator = (const SignerInfos &)" << endl;
5029 abort();
5030 // if your compiler complains here, check the -novolat option
5031 #endif // SNACC_DEEP_COPY
5032 }
5033
5034 void SignerInfos::Print (ostream &os) const
5035 {
5036 #ifndef NDEBUG
5037 os << "{ -- SEQUENCE/SET OF -- " << endl;
5038 indentG += stdIndentG;
5039 //SetCurrToFirst();
5040 //for (; Curr() != NULL; GoNext())
5041 for (const AsnListElmt *run=first; run; run=run->next)
5042 {
5043 Indent (os, indentG);
5044 //os << *Curr();
5045 os << *run->elmt;
5046 //if (Curr() != Last())
5047 if (run != last)
5048 os << ",";
5049 os << endl;
5050 }
5051 indentG -= stdIndentG;
5052 Indent (os, indentG);
5053 os << "}\n";
5054 #endif /* NDEBUG */
5055
5056
5057 } // Print
5058
5059
5060 void SignerInfos::SetCurrElmt (unsigned long int index)
5061 {
5062 unsigned long int i;
5063 curr = first;
5064 if (count)
5065 for (i = 0; (i < (count-1)) && (i < index); i++)
5066 curr = curr->next;
5067 } // SignerInfos::SetCurrElmt
5068
5069
5070 unsigned long int SignerInfos::GetCurrElmtIndex()
5071 {
5072 unsigned long int i;
5073 AsnListElmt *tmp;
5074 if (curr != NULL)
5075 {
5076 for (i = 0, tmp = first; tmp != NULL; i++)
5077 {
5078 if (tmp == curr)
5079 return i;
5080 else
5081 tmp = tmp->next;
5082 }
5083 }
5084 return count;
5085 } // SignerInfos::GetCurrElmtIndex
5086
5087
5088 // alloc new list elmt, put at end of list
5089 // and return the component type
5090 SignerInfo *SignerInfos::Append()
5091 {
5092 AsnListElmt *newElmt;
5093 newElmt = new AsnListElmt;
5094 newElmt->elmt = new SignerInfo;
5095 newElmt->next = NULL;
5096 if (last == NULL)
5097 {
5098 newElmt->prev = NULL;
5099 first = last = newElmt;
5100 }
5101 else
5102 {
5103 newElmt->prev = last;
5104 last->next = newElmt;
5105 last = newElmt;
5106 }
5107 count++;
5108 return (curr = newElmt)->elmt;
5109 } // SignerInfos::Append
5110
5111
5112 // alloc new list elmt, put at begining of list
5113 // and return the component type
5114 SignerInfo *SignerInfos::Prepend()
5115 {
5116 AsnListElmt *newElmt;
5117 newElmt = new AsnListElmt;
5118 newElmt->elmt = new SignerInfo;
5119 newElmt->prev = NULL;
5120 if (first == NULL)
5121 {
5122 newElmt->next = NULL;
5123 first = last = newElmt;
5124 }
5125 else
5126 {
5127 newElmt->next = first;
5128 first->prev = newElmt;
5129 first = newElmt;
5130 }
5131 count++;
5132 return (curr = newElmt)->elmt;
5133 } // SignerInfos::Prepend
5134
5135
5136 // alloc new list elmt, insert it before the
5137 // current element and return the component type
5138 // if the current element is null, the new element
5139 // is placed at the beginning of the list.
5140 SignerInfo *SignerInfos::InsertBefore()
5141 {
5142 AsnListElmt *newElmt;
5143 newElmt = new AsnListElmt;
5144 newElmt->elmt = new SignerInfo;
5145 if (curr == NULL)
5146 {
5147 newElmt->next = first;
5148 newElmt->prev = NULL;
5149 first = newElmt;
5150 if (last == NULL)
5151 last = newElmt;
5152 }
5153 else
5154 {
5155 newElmt->next = curr;
5156 newElmt->prev = curr->prev;
5157 curr->prev = newElmt;
5158 if (curr == first)
5159 first = newElmt;
5160 else
5161 newElmt->prev->next = newElmt;
5162 }
5163 count++;
5164 return (curr = newElmt)->elmt;
5165 } // SignerInfos::InsertBefore
5166
5167
5168 // alloc new list elmt, insert it after the
5169 // current element and return the component type
5170 // if the current element is null, the new element
5171 // is placed at the end of the list.
5172 SignerInfo *SignerInfos::InsertAfter()
5173 {
5174 AsnListElmt *newElmt;
5175 newElmt = new AsnListElmt;
5176 newElmt->elmt = new SignerInfo;
5177 if (curr == NULL)
5178 {
5179 newElmt->prev = last;
5180 newElmt->next = NULL;
5181 last = newElmt;
5182 if (first == NULL)
5183 first = newElmt;
5184 }
5185 else
5186 {
5187 newElmt->prev = curr;
5188 newElmt->next = curr->next;
5189 curr->next = newElmt;
5190 if (curr == last)
5191 last = newElmt;
5192 else
5193 newElmt->next->prev = newElmt;
5194 }
5195 count++;
5196 return (curr = newElmt)->elmt;
5197 } // SignerInfos::InsertAfter
5198
5199
5200 SignerInfos &SignerInfos::AppendCopy (SignerInfo &elmt)
5201 {
5202 AsnListElmt *newElmt;
5203 newElmt = new AsnListElmt;
5204 newElmt->elmt = new SignerInfo;
5205 *newElmt->elmt = elmt;
5206 newElmt->next = NULL;
5207 if (last == NULL)
5208 {
5209 newElmt->prev = NULL;
5210 first = last = newElmt;
5211 }
5212 else
5213 {
5214 newElmt->prev = last;
5215 last->next = newElmt;
5216 last = newElmt;
5217 }
5218 count++;
5219 return *this;
5220 } // AppendCopy
5221
5222
5223 SignerInfos &SignerInfos::PrependCopy (SignerInfo &elmt)
5224 {
5225 AsnListElmt *newElmt;
5226 newElmt = new AsnListElmt;
5227 newElmt->elmt = new SignerInfo;
5228 *newElmt->elmt = elmt;
5229 newElmt->prev = NULL;
5230 if (first == NULL)
5231 {
5232 newElmt->next = NULL;
5233 first = last = newElmt;
5234 }
5235 else
5236 {
5237 newElmt->next = first;
5238 first->prev = newElmt;
5239 first = newElmt;
5240 }
5241 count++;
5242 return *this;
5243 } // SignerInfos::PrependCopy
5244
5245
5246 // alloc new list elmt, insert it before the
5247 // current element, copy the given elmt into the new elmt
5248 // and return the component type.
5249 // if the current element is null, the new element
5250 // is placed at the beginning of the list.
5251 SignerInfos &SignerInfos::InsertBeforeAndCopy (SignerInfo &elmt)
5252 {
5253 AsnListElmt *newElmt;
5254
5255 newElmt = new AsnListElmt;
5256 newElmt->elmt = new SignerInfo;
5257 *newElmt->elmt = elmt;
5258
5259 if (curr == NULL)
5260 {
5261 newElmt->next = first;
5262 newElmt->prev = NULL;
5263 first = newElmt;
5264 if (last == NULL)
5265 last = newElmt;
5266 }
5267 else
5268 {
5269 newElmt->next = curr;
5270 newElmt->prev = curr->prev;
5271 curr->prev = newElmt;
5272 if (curr == first)
5273 first = newElmt;
5274 else
5275 newElmt->prev->next = newElmt;
5276 }
5277 count++;
5278 return *this;
5279 } // SignerInfos::InsertBeforeAndCopy
5280
5281
5282 // alloc new list elmt, insert it after the
5283 // current element, copy given elmt in to new elmt
5284 // and return the component type
5285 // if the current element is null, the new element
5286 // is placed at the end of the list.
5287 SignerInfos &SignerInfos::InsertAfterAndCopy (SignerInfo &elmt)
5288 {
5289 AsnListElmt *newElmt;
5290
5291 newElmt = new AsnListElmt;
5292 newElmt->elmt = new SignerInfo;
5293 *newElmt->elmt = elmt;
5294 if (curr == NULL)
5295 {
5296 newElmt->prev = last;
5297 newElmt->next = NULL;
5298 last = newElmt;
5299 if (first == NULL)
5300 first = newElmt;
5301 }
5302 else
5303 {
5304 newElmt->prev = curr;
5305 newElmt->next = curr->next;
5306 curr->next = newElmt;
5307 if (curr == last)
5308 last = newElmt;
5309 else
5310 newElmt->next->prev = newElmt;
5311 }
5312 count++;
5313 return *this;
5314 } // SignerInfos::InsertAfterAndCopy
5315
5316
5317 // remove current element from list if current element is not NULL
5318 // The new current element will be the next element.
5319 // If the current element is the last element in the list
5320 // the second but last element will become the new current element.
5321 void SignerInfos::RemoveCurrFromList()
5322 {
5323 AsnListElmt *del_elmt;
5324
5325 if (curr != NULL)
5326 {
5327 del_elmt = curr;
5328 count--;
5329
5330 if (count == 0)
5331 first = last = curr = NULL;
5332 else if (curr == first)
5333 {
5334 curr = first= first->next;
5335 first->prev = NULL;
5336 }
5337 else if (curr == last)
5338 {
5339 curr = last = last->prev;
5340 last->next = NULL;
5341 }
5342 else
5343 {
5344 curr->prev->next = curr->next;
5345 curr->next->prev = curr->prev;
5346 }
5347
5348 delete del_elmt->elmt;
5349 delete del_elmt;
5350 }
5351 }
5352
5353
5354 AsnLen SignerInfos::BEncContent (BUF_TYPE b)
5355 {
5356 AsnListElmt *currElmt;
5357 AsnLen elmtLen;
5358 AsnLen totalLen = 0;
5359 {
5360 int iii,icount;
5361 CSM_Buffer **tmpEnc=NULL;
5362 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
5363 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
5364 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
5365 {
5366 BEncEocIfNec (b);
5367 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
5368 elmtLen += BEncConsLen (outputBuf, elmtLen);
5369
5370 elmtLen += BEncTag1 (outputBuf, UNIV, CONS, SEQ_TAG_CODE);
5371 ENCODE_BUF2(tmpEnc[iii]);
5372 }
5373 vdasnacc_sortSetOf(tmpEnc, icount);
5374 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
5375 SM_WriteToAsnBuf(tmpEnc[iii], b);
5376 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
5377 free(tmpEnc);
5378 }
5379 totalLen += elmtLen;
5380 return totalLen;
5381 } // SignerInfos::BEncContent
5382
5383
5384 void SignerInfos::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
5385 AsnLen &bytesDecoded, ENV_TYPE env)
5386 {
5387 SignerInfo *listElmt;
5388 AsnTag tag1;
5389 AsnLen listBytesDecoded = 0;
5390 AsnLen elmtLen1;
5391
5392 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
5393 {
5394 tag1 = BDecTag (b, listBytesDecoded, env);
5395 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
5396 {
5397 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
5398 break;
5399 }
5400 if ((tag1 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
5401 {
5402 Asn1Error << "Unexpected Tag" << endl;
5403 longjmp (env, -163);
5404 }
5405
5406 elmtLen1 = BDecLen (b, listBytesDecoded, env);
5407 listElmt = Append();
5408 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
5409 }
5410
5411 bytesDecoded += listBytesDecoded;
5412 } // SignerInfos::BDecContent
5413
5414
5415 RecipientEncryptedKey::RecipientEncryptedKey()
5416 {
5417 #if TCL
5418 rid = new KeyAgreeRecipientIdentifier;
5419 #else
5420 rid = NULL; // incomplete initialization of mandatory element!
5421 #endif // TCL
5422 }
5423
5424 RecipientEncryptedKey::RecipientEncryptedKey (const RecipientEncryptedKey &)
5425 {
5426 Asn1Error << "use of incompletely defined RecipientEncryptedKey::RecipientEncryptedKey (const RecipientEncryptedKey &)" << endl;
5427 abort();
5428 }
5429
5430 RecipientEncryptedKey::~RecipientEncryptedKey()
5431 {
5432 delete rid;
5433 }
5434
5435 AsnType *RecipientEncryptedKey::Clone() const
5436 {
5437 return new RecipientEncryptedKey;
5438 }
5439
5440 AsnType *RecipientEncryptedKey::Copy() const
5441 {
5442 return new RecipientEncryptedKey (*this);
5443 }
5444
5445 #if SNACC_DEEP_COPY
5446 RecipientEncryptedKey &RecipientEncryptedKey::operator = (const RecipientEncryptedKey &that)
5447 #else // SNACC_DEEP_COPY
5448 RecipientEncryptedKey &RecipientEncryptedKey::operator = (const RecipientEncryptedKey &)
5449 #endif // SNACC_DEEP_COPY
5450 {
5451 #if SNACC_DEEP_COPY
5452 if (this != &that)
5453 {
5454 if (that.rid)
5455 {
5456 if (!rid)
5457 rid = new KeyAgreeRecipientIdentifier;
5458 *rid = *that.rid;
5459 }
5460 else
5461 {
5462 delete rid;
5463 rid = NULL;
5464 }
5465 encryptedKey = that.encryptedKey;
5466 }
5467
5468 return *this;
5469 #else // SNACC_DEEP_COPY
5470 Asn1Error << "use of incompletely defined RecipientEncryptedKey &RecipientEncryptedKey::operator = (const RecipientEncryptedKey &)" << endl;
5471 abort();
5472 // if your compiler complains here, check the -novolat option
5473 #endif // SNACC_DEEP_COPY
5474 }
5475
5476 AsnLen
5477 RecipientEncryptedKey::BEncContent (BUF_TYPE b)
5478 {
5479 AsnLen totalLen = 0;
5480 AsnLen l;
5481
5482 l = encryptedKey.BEncContent (b);
5483 l += BEncDefLen (b, l);
5484
5485 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
5486 totalLen += l;
5487
5488 l = rid->BEncContent (b);
5489 totalLen += l;
5490
5491 return totalLen;
5492 } // RecipientEncryptedKey::BEncContent
5493
5494
5495 void RecipientEncryptedKey::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
5496 {
5497 AsnTag tag1;
5498 AsnLen seqBytesDecoded = 0;
5499 AsnLen elmtLen1;
5500 tag1 = BDecTag (b, seqBytesDecoded, env);
5501
5502 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
5503 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
5504 {
5505 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
5506 rid = new KeyAgreeRecipientIdentifier;
5507 rid->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
5508 tag1 = BDecTag (b, seqBytesDecoded, env);
5509 }
5510 else
5511 {
5512 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
5513 longjmp (env, -164);
5514 }
5515
5516 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
5517 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
5518 {
5519 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
5520 encryptedKey.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
5521 }
5522 else
5523 {
5524 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
5525 longjmp (env, -165);
5526 }
5527
5528 bytesDecoded += seqBytesDecoded;
5529 if (elmtLen0 == INDEFINITE_LEN)
5530 {
5531 BDecEoc (b, bytesDecoded, env);
5532 return;
5533 }
5534 else if (seqBytesDecoded != elmtLen0)
5535 {
5536 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
5537 longjmp (env, -166);
5538 }
5539 else
5540 return;
5541 } // RecipientEncryptedKey::BDecContent
5542
5543 AsnLen RecipientEncryptedKey::BEnc (BUF_TYPE b)
5544 {
5545 AsnLen l;
5546 l = BEncContent (b);
5547 l += BEncConsLen (b, l);
5548 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
5549 return l;
5550 }
5551
5552 void RecipientEncryptedKey::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
5553 {
5554 AsnTag tag;
5555 AsnLen elmtLen1;
5556
5557 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
5558 {
5559 Asn1Error << "RecipientEncryptedKey::BDec: ERROR - wrong tag" << endl;
5560 longjmp (env, -167);
5561 }
5562 elmtLen1 = BDecLen (b, bytesDecoded, env);
5563 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
5564 }
5565
5566 int RecipientEncryptedKey::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
5567 {
5568 bytesEncoded = BEnc (b);
5569 return !b.WriteError();
5570 }
5571
5572 int RecipientEncryptedKey::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
5573 {
5574 ENV_TYPE env;
5575 int val;
5576
5577 bytesDecoded = 0;
5578 if ((val = setjmp (env)) == 0)
5579 {
5580 BDec (b, bytesDecoded, env);
5581 return !b.ReadError();
5582 }
5583 else
5584 return false;
5585 }
5586
5587 void RecipientEncryptedKey::Print (ostream &os) const
5588 {
5589 #ifndef NDEBUG
5590 os << "{ -- SEQUENCE --" << endl;
5591 indentG += stdIndentG;
5592
5593 if (NOT_NULL (rid))
5594 {
5595 Indent (os, indentG);
5596 os << "rid ";
5597 os << *rid;
5598 }
5599 else
5600 {
5601 Indent (os, indentG);
5602 os << "rid ";
5603 os << "-- void --";
5604 os << "," << endl;
5605 }
5606
5607 {
5608 Indent (os, indentG);
5609 os << "encryptedKey ";
5610 os << encryptedKey;
5611 }
5612
5613 os << endl;
5614 indentG -= stdIndentG;
5615 Indent (os, indentG);
5616 os << "}";
5617 #endif /* NDEBUG */
5618 } // RecipientEncryptedKey::Print
5619
5620
5621 CertificateChoices::CertificateChoices()
5622 {
5623 choiceId = certificateCid;
5624 #if TCL
5625 certificate = new Certificate;
5626 #else
5627 certificate = NULL; // incomplete initialization of mandatory element!
5628 #endif // TCL
5629 }
5630
5631 CertificateChoices::CertificateChoices (const CertificateChoices &)
5632 {
5633 Asn1Error << "use of incompletely defined CertificateChoices::CertificateChoices (const CertificateChoices &)" << endl;
5634 abort();
5635 }
5636
5637 CertificateChoices::~CertificateChoices()
5638 {
5639 switch (choiceId)
5640 {
5641 case certificateCid:
5642 delete certificate;
5643 break;
5644 case extendedCertificateCid:
5645 delete extendedCertificate;
5646 break;
5647 case attrCertCid:
5648 delete attrCert;
5649 break;
5650 } // end of switch
5651 } // end of destructor
5652
5653 AsnType *CertificateChoices::Clone() const
5654 {
5655 return new CertificateChoices;
5656 }
5657
5658 AsnType *CertificateChoices::Copy() const
5659 {
5660 return new CertificateChoices (*this);
5661 }
5662
5663 #if SNACC_DEEP_COPY
5664 CertificateChoices &CertificateChoices::operator = (const CertificateChoices &that)
5665 #else // SNACC_DEEP_COPY
5666 CertificateChoices &CertificateChoices::operator = (const CertificateChoices &)
5667 #endif // SNACC_DEEP_COPY
5668 {
5669 #if SNACC_DEEP_COPY
5670 if (this != &that)
5671 {
5672 switch (choiceId)
5673 {
5674 case certificateCid:
5675 delete certificate;
5676 break;
5677 case extendedCertificateCid:
5678 delete extendedCertificate;
5679 break;
5680 case attrCertCid:
5681 delete attrCert;
5682 break;
5683 }
5684 switch (choiceId = that.choiceId)
5685 {
5686 case certificateCid:
5687 certificate = new Certificate;
5688 *certificate = *that.certificate;
5689 break;
5690 case extendedCertificateCid:
5691 extendedCertificate = new ExtendedCertificate;
5692 *extendedCertificate = *that.extendedCertificate;
5693 break;
5694 case attrCertCid:
5695 attrCert = new AttributeCertificate;
5696 *attrCert = *that.attrCert;
5697 break;
5698 }
5699 }
5700
5701 return *this;
5702 #else // SNACC_DEEP_COPY
5703 Asn1Error << "use of incompletely defined CertificateChoices &CertificateChoices::operator = (const CertificateChoices &)" << endl;
5704 abort();
5705 // if your compiler complains here, check the -novolat option
5706 #endif // SNACC_DEEP_COPY
5707 }
5708
5709 AsnLen
5710 CertificateChoices::BEncContent (BUF_TYPE b)
5711 {
5712 AsnLen l;
5713 switch (choiceId)
5714 {
5715 case certificateCid:
5716 BEncEocIfNec (b);
5717 l = certificate->BEncContent (b);
5718 l += BEncConsLen (b, l);
5719
5720 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
5721 break;
5722
5723 case extendedCertificateCid:
5724 BEncEocIfNec (b);
5725 l = extendedCertificate->BEncContent (b);
5726 l += BEncConsLen (b, l);
5727
5728 l += BEncTag1 (b, CNTX, CONS, 0);
5729 break;
5730
5731 case attrCertCid:
5732 BEncEocIfNec (b);
5733 l = attrCert->BEncContent (b);
5734 l += BEncConsLen (b, l);
5735
5736 l += BEncTag1 (b, CNTX, CONS, 1);
5737 break;
5738
5739 } // end switch
5740 return l;
5741 } // CertificateChoices::BEncContent
5742
5743
5744 void CertificateChoices::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
5745 {
5746 switch (tag)
5747 {
5748 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
5749 choiceId = certificateCid;
5750 certificate = new Certificate;
5751 certificate->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
5752 break;
5753
5754 case MAKE_TAG_ID (CNTX, CONS, 0):
5755 choiceId = extendedCertificateCid;
5756 extendedCertificate = new ExtendedCertificate;
5757 extendedCertificate->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
5758 break;
5759
5760 case MAKE_TAG_ID (CNTX, CONS, 1):
5761 choiceId = attrCertCid;
5762 attrCert = new AttributeCertificate;
5763 attrCert->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
5764 break;
5765
5766 default:
5767 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
5768 longjmp (env, -168);
5769 break;
5770 } // end switch
5771 } // CertificateChoices::BDecContent
5772
5773
5774 AsnLen CertificateChoices::BEnc (BUF_TYPE b)
5775 {
5776 AsnLen l;
5777 l = BEncContent (b);
5778 return l;
5779 }
5780
5781 void CertificateChoices::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
5782 {
5783 AsnLen elmtLen;
5784 AsnTag tag;
5785
5786 /* CHOICEs are a special case - grab identifying tag */
5787 /* this allows easier handling of nested CHOICEs */
5788 tag = BDecTag (b, bytesDecoded, env);
5789 elmtLen = BDecLen (b, bytesDecoded, env);
5790 BDecContent (b, tag, elmtLen, bytesDecoded, env);
5791 }
5792
5793 int CertificateChoices::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
5794 {
5795 bytesEncoded = BEnc (b);
5796 return !b.WriteError();
5797 }
5798
5799 int CertificateChoices::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
5800 {
5801 ENV_TYPE env;
5802 int val;
5803
5804 bytesDecoded = 0;
5805 if ((val = setjmp (env)) == 0)
5806 {
5807 BDec (b, bytesDecoded, env);
5808 return !b.ReadError();
5809 }
5810 else
5811 return false;
5812 }
5813
5814 void CertificateChoices::Print (ostream &os) const
5815 {
5816 #ifndef NDEBUG
5817 switch (choiceId)
5818 {
5819 case certificateCid:
5820 os << "certificate ";
5821 if (certificate)
5822 os << *certificate;
5823 else
5824 os << "-- void3 --\n";
5825 break;
5826
5827 case extendedCertificateCid:
5828 os << "extendedCertificate ";
5829 if (extendedCertificate)
5830 os << *extendedCertificate;
5831 else
5832 os << "-- void3 --\n";
5833 break;
5834
5835 case attrCertCid:
5836 os << "attrCert ";
5837 if (attrCert)
5838 os << *attrCert;
5839 else
5840 os << "-- void3 --\n";
5841 break;
5842
5843 } // end of switch
5844 #endif /* NDEBUG */
5845 } // CertificateChoices::Print
5846
5847 AsnType *CertificateSet::Clone() const
5848 {
5849 return new CertificateSet;
5850 }
5851
5852 AsnType *CertificateSet::Copy() const
5853 {
5854 return new CertificateSet (*this);
5855 }
5856
5857 AsnLen CertificateSet::BEnc (BUF_TYPE b)
5858 {
5859 AsnLen l;
5860 l = BEncContent (b);
5861 l += BEncConsLen (b, l);
5862 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
5863 return l;
5864 }
5865
5866 void CertificateSet::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
5867 {
5868 AsnTag tag;
5869 AsnLen elmtLen1;
5870
5871 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
5872 {
5873 Asn1Error << "CertificateSet::BDec: ERROR - wrong tag" << endl;
5874 longjmp (env, -169);
5875 }
5876 elmtLen1 = BDecLen (b, bytesDecoded, env);
5877 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
5878 }
5879
5880 CertificateSet::CertificateSet (const CertificateSet &)
5881 {
5882 Asn1Error << "use of incompletely defined CertificateSet::CertificateSet (const CertificateSet &)" << endl;
5883 abort();
5884 }
5885
5886 CertificateSet::~CertificateSet()
5887 {
5888 SetCurrToFirst();
5889 for (; Curr() != NULL; RemoveCurrFromList())
5890 ;
5891 } // end of destructor
5892
5893 #if SNACC_DEEP_COPY
5894 CertificateSet &CertificateSet::operator = (const CertificateSet &that)
5895 #else // SNACC_DEEP_COPY
5896 CertificateSet &CertificateSet::operator = (const CertificateSet &)
5897 #endif // SNACC_DEEP_COPY
5898 {
5899 #if SNACC_DEEP_COPY
5900 if (this != &that)
5901 {
5902 SetCurrToFirst();
5903 for (; Curr(); RemoveCurrFromList())
5904 ;
5905
5906 //that.SetCurrToFirst();
5907 //for (; that.Curr(); that.GoNext())
5908 // AppendCopy (*that.Curr());
5909 for (const AsnListElmt *run=that.first; run; run=run->next)
5910 AppendCopy (*run->elmt);
5911 }
5912
5913 return *this;
5914 #else // SNACC_DEEP_COPY
5915 Asn1Error << "use of incompletely defined CertificateSet &CertificateSet::operator = (const CertificateSet &)" << endl;
5916 abort();
5917 // if your compiler complains here, check the -novolat option
5918 #endif // SNACC_DEEP_COPY
5919 }
5920
5921 void CertificateSet::Print (ostream &os) const
5922 {
5923 #ifndef NDEBUG
5924 os << "{ -- SEQUENCE/SET OF -- " << endl;
5925 indentG += stdIndentG;
5926 //SetCurrToFirst();
5927 //for (; Curr() != NULL; GoNext())
5928 for (const AsnListElmt *run=first; run; run=run->next)
5929 {
5930 Indent (os, indentG);
5931 //os << *Curr();
5932 os << *run->elmt;
5933 //if (Curr() != Last())
5934 if (run != last)
5935 os << ",";
5936 os << endl;
5937 }
5938 indentG -= stdIndentG;
5939 Indent (os, indentG);
5940 os << "}\n";
5941 #endif /* NDEBUG */
5942
5943
5944 } // Print
5945
5946
5947 void CertificateSet::SetCurrElmt (unsigned long int index)
5948 {
5949 unsigned long int i;
5950 curr = first;
5951 if (count)
5952 for (i = 0; (i < (count-1)) && (i < index); i++)
5953 curr = curr->next;
5954 } // CertificateSet::SetCurrElmt
5955
5956
5957 unsigned long int CertificateSet::GetCurrElmtIndex()
5958 {
5959 unsigned long int i;
5960 AsnListElmt *tmp;
5961 if (curr != NULL)
5962 {
5963 for (i = 0, tmp = first; tmp != NULL; i++)
5964 {
5965 if (tmp == curr)
5966 return i;
5967 else
5968 tmp = tmp->next;
5969 }
5970 }
5971 return count;
5972 } // CertificateSet::GetCurrElmtIndex
5973
5974
5975 // alloc new list elmt, put at end of list
5976 // and return the component type
5977 CertificateChoices *CertificateSet::Append()
5978 {
5979 AsnListElmt *newElmt;
5980 newElmt = new AsnListElmt;
5981 newElmt->elmt = new CertificateChoices;
5982 newElmt->next = NULL;
5983 if (last == NULL)
5984 {
5985 newElmt->prev = NULL;
5986 first = last = newElmt;
5987 }
5988 else
5989 {
5990 newElmt->prev = last;
5991 last->next = newElmt;
5992 last = newElmt;
5993 }
5994 count++;
5995 return (curr = newElmt)->elmt;
5996 } // CertificateSet::Append
5997
5998
5999 // alloc new list elmt, put at begining of list
6000 // and return the component type
6001 CertificateChoices *CertificateSet::Prepend()
6002 {
6003 AsnListElmt *newElmt;
6004 newElmt = new AsnListElmt;
6005 newElmt->elmt = new CertificateChoices;
6006 newElmt->prev = NULL;
6007 if (first == NULL)
6008 {
6009 newElmt->next = NULL;
6010 first = last = newElmt;
6011 }
6012 else
6013 {
6014 newElmt->next = first;
6015 first->prev = newElmt;
6016 first = newElmt;
6017 }
6018 count++;
6019 return (curr = newElmt)->elmt;
6020 } // CertificateSet::Prepend
6021
6022
6023 // alloc new list elmt, insert it before the
6024 // current element and return the component type
6025 // if the current element is null, the new element
6026 // is placed at the beginning of the list.
6027 CertificateChoices *CertificateSet::InsertBefore()
6028 {
6029 AsnListElmt *newElmt;
6030 newElmt = new AsnListElmt;
6031 newElmt->elmt = new CertificateChoices;
6032 if (curr == NULL)
6033 {
6034 newElmt->next = first;
6035 newElmt->prev = NULL;
6036 first = newElmt;
6037 if (last == NULL)
6038 last = newElmt;
6039 }
6040 else
6041 {
6042 newElmt->next = curr;
6043 newElmt->prev = curr->prev;
6044 curr->prev = newElmt;
6045 if (curr == first)
6046 first = newElmt;
6047 else
6048 newElmt->prev->next = newElmt;
6049 }
6050 count++;
6051 return (curr = newElmt)->elmt;
6052 } // CertificateSet::InsertBefore
6053
6054
6055 // alloc new list elmt, insert it after the
6056 // current element and return the component type
6057 // if the current element is null, the new element
6058 // is placed at the end of the list.
6059 CertificateChoices *CertificateSet::InsertAfter()
6060 {
6061 AsnListElmt *newElmt;
6062 newElmt = new AsnListElmt;
6063 newElmt->elmt = new CertificateChoices;
6064 if (curr == NULL)
6065 {
6066 newElmt->prev = last;
6067 newElmt->next = NULL;
6068 last = newElmt;
6069 if (first == NULL)
6070 first = newElmt;
6071 }
6072 else
6073 {
6074 newElmt->prev = curr;
6075 newElmt->next = curr->next;
6076 curr->next = newElmt;
6077 if (curr == last)
6078 last = newElmt;
6079 else
6080 newElmt->next->prev = newElmt;
6081 }
6082 count++;
6083 return (curr = newElmt)->elmt;
6084 } // CertificateSet::InsertAfter
6085
6086
6087 CertificateSet &CertificateSet::AppendCopy (CertificateChoices &elmt)
6088 {
6089 AsnListElmt *newElmt;
6090 newElmt = new AsnListElmt;
6091 newElmt->elmt = new CertificateChoices;
6092 *newElmt->elmt = elmt;
6093 newElmt->next = NULL;
6094 if (last == NULL)
6095 {
6096 newElmt->prev = NULL;
6097 first = last = newElmt;
6098 }
6099 else
6100 {
6101 newElmt->prev = last;
6102 last->next = newElmt;
6103 last = newElmt;
6104 }
6105 count++;
6106 return *this;
6107 } // AppendCopy
6108
6109
6110 CertificateSet &CertificateSet::PrependCopy (CertificateChoices &elmt)
6111 {
6112 AsnListElmt *newElmt;
6113 newElmt = new AsnListElmt;
6114 newElmt->elmt = new CertificateChoices;
6115 *newElmt->elmt = elmt;
6116 newElmt->prev = NULL;
6117 if (first == NULL)
6118 {
6119 newElmt->next = NULL;
6120 first = last = newElmt;
6121 }
6122 else
6123 {
6124 newElmt->next = first;
6125 first->prev = newElmt;
6126 first = newElmt;
6127 }
6128 count++;
6129 return *this;
6130 } // CertificateSet::PrependCopy
6131
6132
6133 // alloc new list elmt, insert it before the
6134 // current element, copy the given elmt into the new elmt
6135 // and return the component type.
6136 // if the current element is null, the new element
6137 // is placed at the beginning of the list.
6138 CertificateSet &CertificateSet::InsertBeforeAndCopy (CertificateChoices &elmt)
6139 {
6140 AsnListElmt *newElmt;
6141
6142 newElmt = new AsnListElmt;
6143 newElmt->elmt = new CertificateChoices;
6144 *newElmt->elmt = elmt;
6145
6146 if (curr == NULL)
6147 {
6148 newElmt->next = first;
6149 newElmt->prev = NULL;
6150 first = newElmt;
6151 if (last == NULL)
6152 last = newElmt;
6153 }
6154 else
6155 {
6156 newElmt->next = curr;
6157 newElmt->prev = curr->prev;
6158 curr->prev = newElmt;
6159 if (curr == first)
6160 first = newElmt;
6161 else
6162 newElmt->prev->next = newElmt;
6163 }
6164 count++;
6165 return *this;
6166 } // CertificateSet::InsertBeforeAndCopy
6167
6168
6169 // alloc new list elmt, insert it after the
6170 // current element, copy given elmt in to new elmt
6171 // and return the component type
6172 // if the current element is null, the new element
6173 // is placed at the end of the list.
6174 CertificateSet &CertificateSet::InsertAfterAndCopy (CertificateChoices &elmt)
6175 {
6176 AsnListElmt *newElmt;
6177
6178 newElmt = new AsnListElmt;
6179 newElmt->elmt = new CertificateChoices;
6180 *newElmt->elmt = elmt;
6181 if (curr == NULL)
6182 {
6183 newElmt->prev = last;
6184 newElmt->next = NULL;
6185 last = newElmt;
6186 if (first == NULL)
6187 first = newElmt;
6188 }
6189 else
6190 {
6191 newElmt->prev = curr;
6192 newElmt->next = curr->next;
6193 curr->next = newElmt;
6194 if (curr == last)
6195 last = newElmt;
6196 else
6197 newElmt->next->prev = newElmt;
6198 }
6199 count++;
6200 return *this;
6201 } // CertificateSet::InsertAfterAndCopy
6202
6203
6204 // remove current element from list if current element is not NULL
6205 // The new current element will be the next element.
6206 // If the current element is the last element in the list
6207 // the second but last element will become the new current element.
6208 void CertificateSet::RemoveCurrFromList()
6209 {
6210 AsnListElmt *del_elmt;
6211
6212 if (curr != NULL)
6213 {
6214 del_elmt = curr;
6215 count--;
6216
6217 if (count == 0)
6218 first = last = curr = NULL;
6219 else if (curr == first)
6220 {
6221 curr = first= first->next;
6222 first->prev = NULL;
6223 }
6224 else if (curr == last)
6225 {
6226 curr = last = last->prev;
6227 last->next = NULL;
6228 }
6229 else
6230 {
6231 curr->prev->next = curr->next;
6232 curr->next->prev = curr->prev;
6233 }
6234
6235 delete del_elmt->elmt;
6236 delete del_elmt;
6237 }
6238 }
6239
6240
6241 AsnLen CertificateSet::BEncContent (BUF_TYPE b)
6242 {
6243 AsnListElmt *currElmt;
6244 AsnLen elmtLen;
6245 AsnLen totalLen = 0;
6246 {
6247 int iii,icount;
6248 CSM_Buffer **tmpEnc=NULL;
6249 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
6250 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
6251 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
6252 {
6253 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
6254 ENCODE_BUF2(tmpEnc[iii]);
6255 }
6256 vdasnacc_sortSetOf(tmpEnc, icount);
6257 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
6258 SM_WriteToAsnBuf(tmpEnc[iii], b);
6259 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
6260 free(tmpEnc);
6261 }
6262 totalLen += elmtLen;
6263 return totalLen;
6264 } // CertificateSet::BEncContent
6265
6266
6267 void CertificateSet::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
6268 AsnLen &bytesDecoded, ENV_TYPE env)
6269 {
6270 CertificateChoices *listElmt;
6271 AsnTag tag1;
6272 AsnLen listBytesDecoded = 0;
6273 AsnLen elmtLen1;
6274
6275 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
6276 {
6277 tag1 = BDecTag (b, listBytesDecoded, env);
6278 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
6279 {
6280 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
6281 break;
6282 }
6283 if (!((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
6284 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 0))
6285 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 1))))
6286 {
6287 Asn1Error << "Unexpected Tag" << endl;
6288 longjmp (env, -170);
6289 }
6290
6291 elmtLen1 = BDecLen (b, listBytesDecoded, env);
6292 listElmt = Append();
6293 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
6294 }
6295
6296 bytesDecoded += listBytesDecoded;
6297 } // CertificateSet::BDecContent
6298
6299
6300 OriginatorInfo::OriginatorInfo()
6301 {
6302 certs = NULL;
6303 crls = NULL;
6304 }
6305
6306 OriginatorInfo::OriginatorInfo (const OriginatorInfo &)
6307 {
6308 Asn1Error << "use of incompletely defined OriginatorInfo::OriginatorInfo (const OriginatorInfo &)" << endl;
6309 abort();
6310 }
6311
6312 OriginatorInfo::~OriginatorInfo()
6313 {
6314 delete certs;
6315 delete crls;
6316 }
6317
6318 AsnType *OriginatorInfo::Clone() const
6319 {
6320 return new OriginatorInfo;
6321 }
6322
6323 AsnType *OriginatorInfo::Copy() const
6324 {
6325 return new OriginatorInfo (*this);
6326 }
6327
6328 #if SNACC_DEEP_COPY
6329 OriginatorInfo &OriginatorInfo::operator = (const OriginatorInfo &that)
6330 #else // SNACC_DEEP_COPY
6331 OriginatorInfo &OriginatorInfo::operator = (const OriginatorInfo &)
6332 #endif // SNACC_DEEP_COPY
6333 {
6334 #if SNACC_DEEP_COPY
6335 if (this != &that)
6336 {
6337 if (that.certs)
6338 {
6339 if (!certs)
6340 certs = new CertificateSet;
6341 *certs = *that.certs;
6342 }
6343 else
6344 {
6345 delete certs;
6346 certs = NULL;
6347 }
6348 if (that.crls)
6349 {
6350 if (!crls)
6351 crls = new CertificateRevocationLists;
6352 *crls = *that.crls;
6353 }
6354 else
6355 {
6356 delete crls;
6357 crls = NULL;
6358 }
6359 }
6360
6361 return *this;
6362 #else // SNACC_DEEP_COPY
6363 Asn1Error << "use of incompletely defined OriginatorInfo &OriginatorInfo::operator = (const OriginatorInfo &)" << endl;
6364 abort();
6365 // if your compiler complains here, check the -novolat option
6366 #endif // SNACC_DEEP_COPY
6367 }
6368
6369 AsnLen
6370 OriginatorInfo::BEncContent (BUF_TYPE b)
6371 {
6372 AsnLen totalLen = 0;
6373 AsnLen l;
6374
6375 if (NOT_NULL (crls))
6376 {
6377 BEncEocIfNec (b);
6378 l = crls->BEncContent (b);
6379 l += BEncConsLen (b, l);
6380
6381 l += BEncTag1 (b, CNTX, CONS, 1);
6382 totalLen += l;
6383 }
6384
6385 if (NOT_NULL (certs))
6386 {
6387 BEncEocIfNec (b);
6388 l = certs->BEncContent (b);
6389 l += BEncConsLen (b, l);
6390
6391 l += BEncTag1 (b, CNTX, CONS, 0);
6392 totalLen += l;
6393 }
6394
6395 return totalLen;
6396 } // OriginatorInfo::BEncContent
6397
6398
6399 void OriginatorInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
6400 {
6401 AsnTag tag1;
6402 AsnLen seqBytesDecoded = 0;
6403 AsnLen elmtLen1;
6404 if (elmtLen0 == 0)
6405 return;
6406 else
6407 {
6408 tag1 = BDecTag (b, seqBytesDecoded, env);
6409
6410 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
6411 {
6412 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
6413 bytesDecoded += seqBytesDecoded;
6414 return;
6415 }
6416 }
6417
6418 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
6419 {
6420 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
6421 certs = new CertificateSet;
6422 certs->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
6423 if (seqBytesDecoded == elmtLen0)
6424 {
6425 bytesDecoded += seqBytesDecoded;
6426 return;
6427 }
6428 else
6429 {
6430 tag1 = BDecTag (b, seqBytesDecoded, env);
6431
6432 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
6433 {
6434 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
6435 bytesDecoded += seqBytesDecoded;
6436 return;
6437 }
6438 }
6439 }
6440
6441 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
6442 {
6443 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
6444 crls = new CertificateRevocationLists;
6445 crls->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
6446 }
6447
6448 bytesDecoded += seqBytesDecoded;
6449 if (elmtLen0 == INDEFINITE_LEN)
6450 {
6451 BDecEoc (b, bytesDecoded, env);
6452 return;
6453 }
6454 else if (seqBytesDecoded != elmtLen0)
6455 {
6456 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
6457 longjmp (env, -171);
6458 }
6459 else
6460 return;
6461 } // OriginatorInfo::BDecContent
6462
6463 AsnLen OriginatorInfo::BEnc (BUF_TYPE b)
6464 {
6465 AsnLen l;
6466 l = BEncContent (b);
6467 l += BEncConsLen (b, l);
6468 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
6469 return l;
6470 }
6471
6472 void OriginatorInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
6473 {
6474 AsnTag tag;
6475 AsnLen elmtLen1;
6476
6477 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
6478 {
6479 Asn1Error << "OriginatorInfo::BDec: ERROR - wrong tag" << endl;
6480 longjmp (env, -172);
6481 }
6482 elmtLen1 = BDecLen (b, bytesDecoded, env);
6483 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
6484 }
6485
6486 int OriginatorInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
6487 {
6488 bytesEncoded = BEnc (b);
6489 return !b.WriteError();
6490 }
6491
6492 int OriginatorInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
6493 {
6494 ENV_TYPE env;
6495 int val;
6496
6497 bytesDecoded = 0;
6498 if ((val = setjmp (env)) == 0)
6499 {
6500 BDec (b, bytesDecoded, env);
6501 return !b.ReadError();
6502 }
6503 else
6504 return false;
6505 }
6506
6507 void OriginatorInfo::Print (ostream &os) const
6508 {
6509 #ifndef NDEBUG
6510 int nonePrinted = true;
6511 os << "{ -- SEQUENCE --" << endl;
6512 indentG += stdIndentG;
6513
6514 if (NOT_NULL (certs))
6515 {
6516 nonePrinted = false;
6517 Indent (os, indentG);
6518 os << "certs ";
6519 os << *certs;
6520 }
6521 else
6522 {
6523 Indent (os, indentG);
6524 os << "certs ";
6525 os << "-- void --";
6526 os << "," << endl;
6527 }
6528
6529 if (NOT_NULL (crls))
6530 {
6531 if (!nonePrinted)
6532 os << "," << endl;
6533 nonePrinted = false;
6534 Indent (os, indentG);
6535 os << "crls ";
6536 os << *crls;
6537 }
6538 else
6539 {
6540 Indent (os, indentG);
6541 os << "crls ";
6542 os << "-- void --";
6543 os << endl;
6544 }
6545
6546 os << endl;
6547 indentG -= stdIndentG;
6548 Indent (os, indentG);
6549 os << "}";
6550 #endif /* NDEBUG */
6551 } // OriginatorInfo::Print
6552
6553
6554 AsnType *RecipientEncryptedKeys::Clone() const
6555 {
6556 return new RecipientEncryptedKeys;
6557 }
6558
6559 AsnType *RecipientEncryptedKeys::Copy() const
6560 {
6561 return new RecipientEncryptedKeys (*this);
6562 }
6563
6564 AsnLen RecipientEncryptedKeys::BEnc (BUF_TYPE b)
6565 {
6566 AsnLen l;
6567 l = BEncContent (b);
6568 l += BEncConsLen (b, l);
6569 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
6570 return l;
6571 }
6572
6573 void RecipientEncryptedKeys::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
6574 {
6575 AsnTag tag;
6576 AsnLen elmtLen1;
6577
6578 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
6579 {
6580 Asn1Error << "RecipientEncryptedKeys::BDec: ERROR - wrong tag" << endl;
6581 longjmp (env, -173);
6582 }
6583 elmtLen1 = BDecLen (b, bytesDecoded, env);
6584 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
6585 }
6586
6587 RecipientEncryptedKeys::RecipientEncryptedKeys (const RecipientEncryptedKeys &)
6588 {
6589 Asn1Error << "use of incompletely defined RecipientEncryptedKeys::RecipientEncryptedKeys (const RecipientEncryptedKeys &)" << endl;
6590 abort();
6591 }
6592
6593 RecipientEncryptedKeys::~RecipientEncryptedKeys()
6594 {
6595 SetCurrToFirst();
6596 for (; Curr() != NULL; RemoveCurrFromList())
6597 ;
6598 } // end of destructor
6599
6600 #if SNACC_DEEP_COPY
6601 RecipientEncryptedKeys &RecipientEncryptedKeys::operator = (const RecipientEncryptedKeys &that)
6602 #else // SNACC_DEEP_COPY
6603 RecipientEncryptedKeys &RecipientEncryptedKeys::operator = (const RecipientEncryptedKeys &)
6604 #endif // SNACC_DEEP_COPY
6605 {
6606 #if SNACC_DEEP_COPY
6607 if (this != &that)
6608 {
6609 SetCurrToFirst();
6610 for (; Curr(); RemoveCurrFromList())
6611 ;
6612
6613 //that.SetCurrToFirst();
6614 //for (; that.Curr(); that.GoNext())
6615 // AppendCopy (*that.Curr());
6616 for (const AsnListElmt *run=that.first; run; run=run->next)
6617 AppendCopy (*run->elmt);
6618 }
6619
6620 return *this;
6621 #else // SNACC_DEEP_COPY
6622 Asn1Error << "use of incompletely defined RecipientEncryptedKeys &RecipientEncryptedKeys::operator = (const RecipientEncryptedKeys &)" << endl;
6623 abort();
6624 // if your compiler complains here, check the -novolat option
6625 #endif // SNACC_DEEP_COPY
6626 }
6627
6628 void RecipientEncryptedKeys::Print (ostream &os) const
6629 {
6630 #ifndef NDEBUG
6631 os << "{ -- SEQUENCE/SET OF -- " << endl;
6632 indentG += stdIndentG;
6633 //SetCurrToFirst();
6634 //for (; Curr() != NULL; GoNext())
6635 for (const AsnListElmt *run=first; run; run=run->next)
6636 {
6637 Indent (os, indentG);
6638 //os << *Curr();
6639 os << *run->elmt;
6640 //if (Curr() != Last())
6641 if (run != last)
6642 os << ",";
6643 os << endl;
6644 }
6645 indentG -= stdIndentG;
6646 Indent (os, indentG);
6647 os << "}\n";
6648 #endif /* NDEBUG */
6649
6650
6651 } // Print
6652
6653
6654 void RecipientEncryptedKeys::SetCurrElmt (unsigned long int index)
6655 {
6656 unsigned long int i;
6657 curr = first;
6658 if (count)
6659 for (i = 0; (i < (count-1)) && (i < index); i++)
6660 curr = curr->next;
6661 } // RecipientEncryptedKeys::SetCurrElmt
6662
6663
6664 unsigned long int RecipientEncryptedKeys::GetCurrElmtIndex()
6665 {
6666 unsigned long int i;
6667 AsnListElmt *tmp;
6668 if (curr != NULL)
6669 {
6670 for (i = 0, tmp = first; tmp != NULL; i++)
6671 {
6672 if (tmp == curr)
6673 return i;
6674 else
6675 tmp = tmp->next;
6676 }
6677 }
6678 return count;
6679 } // RecipientEncryptedKeys::GetCurrElmtIndex
6680
6681
6682 // alloc new list elmt, put at end of list
6683 // and return the component type
6684 RecipientEncryptedKey *RecipientEncryptedKeys::Append()
6685 {
6686 AsnListElmt *newElmt;
6687 newElmt = new AsnListElmt;
6688 newElmt->elmt = new RecipientEncryptedKey;
6689 newElmt->next = NULL;
6690 if (last == NULL)
6691 {
6692 newElmt->prev = NULL;
6693 first = last = newElmt;
6694 }
6695 else
6696 {
6697 newElmt->prev = last;
6698 last->next = newElmt;
6699 last = newElmt;
6700 }
6701 count++;
6702 return (curr = newElmt)->elmt;
6703 } // RecipientEncryptedKeys::Append
6704
6705
6706 // alloc new list elmt, put at begining of list
6707 // and return the component type
6708 RecipientEncryptedKey *RecipientEncryptedKeys::Prepend()
6709 {
6710 AsnListElmt *newElmt;
6711 newElmt = new AsnListElmt;
6712 newElmt->elmt = new RecipientEncryptedKey;
6713 newElmt->prev = NULL;
6714 if (first == NULL)
6715 {
6716 newElmt->next = NULL;
6717 first = last = newElmt;
6718 }
6719 else
6720 {
6721 newElmt->next = first;
6722 first->prev = newElmt;
6723 first = newElmt;
6724 }
6725 count++;
6726 return (curr = newElmt)->elmt;
6727 } // RecipientEncryptedKeys::Prepend
6728
6729
6730 // alloc new list elmt, insert it before the
6731 // current element and return the component type
6732 // if the current element is null, the new element
6733 // is placed at the beginning of the list.
6734 RecipientEncryptedKey *RecipientEncryptedKeys::InsertBefore()
6735 {
6736 AsnListElmt *newElmt;
6737 newElmt = new AsnListElmt;
6738 newElmt->elmt = new RecipientEncryptedKey;
6739 if (curr == NULL)
6740 {
6741 newElmt->next = first;
6742 newElmt->prev = NULL;
6743 first = newElmt;
6744 if (last == NULL)
6745 last = newElmt;
6746 }
6747 else
6748 {
6749 newElmt->next = curr;
6750 newElmt->prev = curr->prev;
6751 curr->prev = newElmt;
6752 if (curr == first)
6753 first = newElmt;
6754 else
6755 newElmt->prev->next = newElmt;
6756 }
6757 count++;
6758 return (curr = newElmt)->elmt;
6759 } // RecipientEncryptedKeys::InsertBefore
6760
6761
6762 // alloc new list elmt, insert it after the
6763 // current element and return the component type
6764 // if the current element is null, the new element
6765 // is placed at the end of the list.
6766 RecipientEncryptedKey *RecipientEncryptedKeys::InsertAfter()
6767 {
6768 AsnListElmt *newElmt;
6769 newElmt = new AsnListElmt;
6770 newElmt->elmt = new RecipientEncryptedKey;
6771 if (curr == NULL)
6772 {
6773 newElmt->prev = last;
6774 newElmt->next = NULL;
6775 last = newElmt;
6776 if (first == NULL)
6777 first = newElmt;
6778 }
6779 else
6780 {
6781 newElmt->prev = curr;
6782 newElmt->next = curr->next;
6783 curr->next = newElmt;
6784 if (curr == last)
6785 last = newElmt;
6786 else
6787 newElmt->next->prev = newElmt;
6788 }
6789 count++;
6790 return (curr = newElmt)->elmt;
6791 } // RecipientEncryptedKeys::InsertAfter
6792
6793
6794 RecipientEncryptedKeys &RecipientEncryptedKeys::AppendCopy (RecipientEncryptedKey &elmt)
6795 {
6796 AsnListElmt *newElmt;
6797 newElmt = new AsnListElmt;
6798 newElmt->elmt = new RecipientEncryptedKey;
6799 *newElmt->elmt = elmt;
6800 newElmt->next = NULL;
6801 if (last == NULL)
6802 {
6803 newElmt->prev = NULL;
6804 first = last = newElmt;
6805 }
6806 else
6807 {
6808 newElmt->prev = last;
6809 last->next = newElmt;
6810 last = newElmt;
6811 }
6812 count++;
6813 return *this;
6814 } // AppendCopy
6815
6816
6817 RecipientEncryptedKeys &RecipientEncryptedKeys::PrependCopy (RecipientEncryptedKey &elmt)
6818 {
6819 AsnListElmt *newElmt;
6820 newElmt = new AsnListElmt;
6821 newElmt->elmt = new RecipientEncryptedKey;
6822 *newElmt->elmt = elmt;
6823 newElmt->prev = NULL;
6824 if (first == NULL)
6825 {
6826 newElmt->next = NULL;
6827 first = last = newElmt;
6828 }
6829 else
6830 {
6831 newElmt->next = first;
6832 first->prev = newElmt;
6833 first = newElmt;
6834 }
6835 count++;
6836 return *this;
6837 } // RecipientEncryptedKeys::PrependCopy
6838
6839
6840 // alloc new list elmt, insert it before the
6841 // current element, copy the given elmt into the new elmt
6842 // and return the component type.
6843 // if the current element is null, the new element
6844 // is placed at the beginning of the list.
6845 RecipientEncryptedKeys &RecipientEncryptedKeys::InsertBeforeAndCopy (RecipientEncryptedKey &elmt)
6846 {
6847 AsnListElmt *newElmt;
6848
6849 newElmt = new AsnListElmt;
6850 newElmt->elmt = new RecipientEncryptedKey;
6851 *newElmt->elmt = elmt;
6852
6853 if (curr == NULL)
6854 {
6855 newElmt->next = first;
6856 newElmt->prev = NULL;
6857 first = newElmt;
6858 if (last == NULL)
6859 last = newElmt;
6860 }
6861 else
6862 {
6863 newElmt->next = curr;
6864 newElmt->prev = curr->prev;
6865 curr->prev = newElmt;
6866 if (curr == first)
6867 first = newElmt;
6868 else
6869 newElmt->prev->next = newElmt;
6870 }
6871 count++;
6872 return *this;
6873 } // RecipientEncryptedKeys::InsertBeforeAndCopy
6874
6875
6876 // alloc new list elmt, insert it after the
6877 // current element, copy given elmt in to new elmt
6878 // and return the component type
6879 // if the current element is null, the new element
6880 // is placed at the end of the list.
6881 RecipientEncryptedKeys &RecipientEncryptedKeys::InsertAfterAndCopy (RecipientEncryptedKey &elmt)
6882 {
6883 AsnListElmt *newElmt;
6884
6885 newElmt = new AsnListElmt;
6886 newElmt->elmt = new RecipientEncryptedKey;
6887 *newElmt->elmt = elmt;
6888 if (curr == NULL)
6889 {
6890 newElmt->prev = last;
6891 newElmt->next = NULL;
6892 last = newElmt;
6893 if (first == NULL)
6894 first = newElmt;
6895 }
6896 else
6897 {
6898 newElmt->prev = curr;
6899 newElmt->next = curr->next;
6900 curr->next = newElmt;
6901 if (curr == last)
6902 last = newElmt;
6903 else
6904 newElmt->next->prev = newElmt;
6905 }
6906 count++;
6907 return *this;
6908 } // RecipientEncryptedKeys::InsertAfterAndCopy
6909
6910
6911 // remove current element from list if current element is not NULL
6912 // The new current element will be the next element.
6913 // If the current element is the last element in the list
6914 // the second but last element will become the new current element.
6915 void RecipientEncryptedKeys::RemoveCurrFromList()
6916 {
6917 AsnListElmt *del_elmt;
6918
6919 if (curr != NULL)
6920 {
6921 del_elmt = curr;
6922 count--;
6923
6924 if (count == 0)
6925 first = last = curr = NULL;
6926 else if (curr == first)
6927 {
6928 curr = first= first->next;
6929 first->prev = NULL;
6930 }
6931 else if (curr == last)
6932 {
6933 curr = last = last->prev;
6934 last->next = NULL;
6935 }
6936 else
6937 {
6938 curr->prev->next = curr->next;
6939 curr->next->prev = curr->prev;
6940 }
6941
6942 delete del_elmt->elmt;
6943 delete del_elmt;
6944 }
6945 }
6946
6947
6948 AsnLen RecipientEncryptedKeys::BEncContent (BUF_TYPE b)
6949 {
6950 AsnListElmt *currElmt;
6951 AsnLen elmtLen;
6952 AsnLen totalLen = 0;
6953 for (currElmt = last; currElmt != NULL; currElmt = currElmt->prev)
6954 {
6955 BEncEocIfNec (b);
6956 elmtLen = currElmt->elmt->BEncContent (b);
6957 elmtLen += BEncConsLen (b, elmtLen);
6958
6959 elmtLen += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
6960 totalLen += elmtLen;
6961 }
6962 return totalLen;
6963 } // RecipientEncryptedKeys::BEncContent
6964
6965
6966 void RecipientEncryptedKeys::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
6967 AsnLen &bytesDecoded, ENV_TYPE env)
6968 {
6969 RecipientEncryptedKey *listElmt;
6970 AsnTag tag1;
6971 AsnLen listBytesDecoded = 0;
6972 AsnLen elmtLen1;
6973
6974 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
6975 {
6976 tag1 = BDecTag (b, listBytesDecoded, env);
6977 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
6978 {
6979 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
6980 break;
6981 }
6982 if ((tag1 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
6983 {
6984 Asn1Error << "Unexpected Tag" << endl;
6985 longjmp (env, -174);
6986 }
6987
6988 elmtLen1 = BDecLen (b, listBytesDecoded, env);
6989 listElmt = Append();
6990 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
6991 }
6992
6993 bytesDecoded += listBytesDecoded;
6994 } // RecipientEncryptedKeys::BDecContent
6995
6996
6997 KeyAgreeRecipientInfo::KeyAgreeRecipientInfo()
6998 {
6999 #if TCL
7000 originator = new OriginatorIdentifierOrKey;
7001 #else
7002 originator = NULL; // incomplete initialization of mandatory element!
7003 #endif // TCL
7004 ukm = NULL;
7005 #if TCL
7006 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
7007 #else
7008 keyEncryptionAlgorithm = NULL; // incomplete initialization of mandatory element!
7009 #endif // TCL
7010 }
7011
7012 KeyAgreeRecipientInfo::KeyAgreeRecipientInfo (const KeyAgreeRecipientInfo &)
7013 {
7014 Asn1Error << "use of incompletely defined KeyAgreeRecipientInfo::KeyAgreeRecipientInfo (const KeyAgreeRecipientInfo &)" << endl;
7015 abort();
7016 }
7017
7018 KeyAgreeRecipientInfo::~KeyAgreeRecipientInfo()
7019 {
7020 delete originator;
7021 delete ukm;
7022 delete keyEncryptionAlgorithm;
7023 }
7024
7025 AsnType *KeyAgreeRecipientInfo::Clone() const
7026 {
7027 return new KeyAgreeRecipientInfo;
7028 }
7029
7030 AsnType *KeyAgreeRecipientInfo::Copy() const
7031 {
7032 return new KeyAgreeRecipientInfo (*this);
7033 }
7034
7035 #if SNACC_DEEP_COPY
7036 KeyAgreeRecipientInfo &KeyAgreeRecipientInfo::operator = (const KeyAgreeRecipientInfo &that)
7037 #else // SNACC_DEEP_COPY
7038 KeyAgreeRecipientInfo &KeyAgreeRecipientInfo::operator = (const KeyAgreeRecipientInfo &)
7039 #endif // SNACC_DEEP_COPY
7040 {
7041 #if SNACC_DEEP_COPY
7042 if (this != &that)
7043 {
7044 version = that.version;
7045 if (that.originator)
7046 {
7047 if (!originator)
7048 originator = new OriginatorIdentifierOrKey;
7049 *originator = *that.originator;
7050 }
7051 else
7052 {
7053 delete originator;
7054 originator = NULL;
7055 }
7056 if (that.ukm)
7057 {
7058 if (!ukm)
7059 ukm = new UserKeyingMaterial;
7060 *ukm = *that.ukm;
7061 }
7062 else
7063 {
7064 delete ukm;
7065 ukm = NULL;
7066 }
7067 if (that.keyEncryptionAlgorithm)
7068 {
7069 if (!keyEncryptionAlgorithm)
7070 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
7071 *keyEncryptionAlgorithm = *that.keyEncryptionAlgorithm;
7072 }
7073 else
7074 {
7075 delete keyEncryptionAlgorithm;
7076 keyEncryptionAlgorithm = NULL;
7077 }
7078 recipientEncryptedKeys = that.recipientEncryptedKeys;
7079 }
7080
7081 return *this;
7082 #else // SNACC_DEEP_COPY
7083 Asn1Error << "use of incompletely defined KeyAgreeRecipientInfo &KeyAgreeRecipientInfo::operator = (const KeyAgreeRecipientInfo &)" << endl;
7084 abort();
7085 // if your compiler complains here, check the -novolat option
7086 #endif // SNACC_DEEP_COPY
7087 }
7088
7089 AsnLen
7090 KeyAgreeRecipientInfo::BEncContent (BUF_TYPE b)
7091 {
7092 AsnLen totalLen = 0;
7093 AsnLen l;
7094
7095 BEncEocIfNec (b);
7096 l = recipientEncryptedKeys.BEncContent (b);
7097 l += BEncConsLen (b, l);
7098
7099 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
7100 totalLen += l;
7101
7102 BEncEocIfNec (b);
7103 l = keyEncryptionAlgorithm->BEncContent (b);
7104 l += BEncConsLen (b, l);
7105
7106 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
7107 totalLen += l;
7108
7109 if (NOT_NULL (ukm))
7110 {
7111 BEncEocIfNec (b);
7112 l = ukm->BEncContent (b);
7113 l += BEncDefLen (b, l);
7114
7115 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
7116 l += BEncConsLen (b, l);
7117
7118 l += BEncTag1 (b, CNTX, CONS, 1);
7119 totalLen += l;
7120 }
7121
7122 BEncEocIfNec (b);
7123 l = originator->BEncContent (b);
7124 l += BEncConsLen (b, l);
7125
7126 l += BEncTag1 (b, CNTX, CONS, 0);
7127 totalLen += l;
7128
7129 l = version.BEncContent (b);
7130 BEncDefLenTo127 (b, l);
7131 l++;
7132
7133 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
7134 totalLen += l;
7135
7136 return totalLen;
7137 } // KeyAgreeRecipientInfo::BEncContent
7138
7139
7140 void KeyAgreeRecipientInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
7141 {
7142 AsnTag tag1;
7143 AsnLen seqBytesDecoded = 0;
7144 AsnLen elmtLen1;
7145 AsnLen elmtLen2;
7146 tag1 = BDecTag (b, seqBytesDecoded, env);
7147
7148 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
7149 {
7150 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
7151 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
7152 tag1 = BDecTag (b, seqBytesDecoded, env);
7153 }
7154 else
7155 {
7156 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
7157 longjmp (env, -175);
7158 }
7159
7160 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
7161 {
7162 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
7163 tag1 = BDecTag (b, seqBytesDecoded, env);
7164 elmtLen2 = BDecLen (b, seqBytesDecoded, env);
7165 originator = new OriginatorIdentifierOrKey;
7166 originator->BDecContent (b, tag1, elmtLen2, seqBytesDecoded, env);
7167 if (elmtLen1 == INDEFINITE_LEN)
7168 BDecEoc (b, seqBytesDecoded, env);
7169
7170 tag1 = BDecTag (b, seqBytesDecoded, env);
7171 }
7172 else
7173 {
7174 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
7175 longjmp (env, -176);
7176 }
7177
7178 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
7179 {
7180 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
7181 tag1 = BDecTag (b, seqBytesDecoded, env);
7182
7183 if ((tag1 != MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
7184 && (tag1 != MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
7185 {
7186 Asn1Error << "Unexpected Tag" << endl;
7187 longjmp (env, -177);
7188 }
7189
7190 elmtLen2 = BDecLen (b, seqBytesDecoded, env);
7191 ukm = new UserKeyingMaterial;
7192 ukm->BDecContent (b, tag1, elmtLen2, seqBytesDecoded, env);
7193 if (elmtLen1 == INDEFINITE_LEN)
7194 BDecEoc (b, seqBytesDecoded, env);
7195
7196 tag1 = BDecTag (b, seqBytesDecoded, env);
7197 }
7198
7199 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
7200 {
7201 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
7202 keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier;
7203 keyEncryptionAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
7204 tag1 = BDecTag (b, seqBytesDecoded, env);
7205 }
7206 else
7207 {
7208 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
7209 longjmp (env, -178);
7210 }
7211
7212 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
7213 {
7214 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
7215 recipientEncryptedKeys.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
7216 }
7217 else
7218 {
7219 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
7220 longjmp (env, -179);
7221 }
7222
7223 bytesDecoded += seqBytesDecoded;
7224 if (elmtLen0 == INDEFINITE_LEN)
7225 {
7226 BDecEoc (b, bytesDecoded, env);
7227 return;
7228 }
7229 else if (seqBytesDecoded != elmtLen0)
7230 {
7231 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
7232 longjmp (env, -180);
7233 }
7234 else
7235 return;
7236 } // KeyAgreeRecipientInfo::BDecContent
7237
7238 AsnLen KeyAgreeRecipientInfo::BEnc (BUF_TYPE b)
7239 {
7240 AsnLen l;
7241 l = BEncContent (b);
7242 l += BEncConsLen (b, l);
7243 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
7244 return l;
7245 }
7246
7247 void KeyAgreeRecipientInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
7248 {
7249 AsnTag tag;
7250 AsnLen elmtLen1;
7251
7252 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
7253 {
7254 Asn1Error << "KeyAgreeRecipientInfo::BDec: ERROR - wrong tag" << endl;
7255 longjmp (env, -181);
7256 }
7257 elmtLen1 = BDecLen (b, bytesDecoded, env);
7258 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
7259 }
7260
7261 int KeyAgreeRecipientInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
7262 {
7263 bytesEncoded = BEnc (b);
7264 return !b.WriteError();
7265 }
7266
7267 int KeyAgreeRecipientInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
7268 {
7269 ENV_TYPE env;
7270 int val;
7271
7272 bytesDecoded = 0;
7273 if ((val = setjmp (env)) == 0)
7274 {
7275 BDec (b, bytesDecoded, env);
7276 return !b.ReadError();
7277 }
7278 else
7279 return false;
7280 }
7281
7282 void KeyAgreeRecipientInfo::Print (ostream &os) const
7283 {
7284 #ifndef NDEBUG
7285 os << "{ -- SEQUENCE --" << endl;
7286 indentG += stdIndentG;
7287
7288 {
7289 Indent (os, indentG);
7290 os << "version ";
7291 os << version;
7292 os << "," << endl;
7293 }
7294
7295 if (NOT_NULL (originator))
7296 {
7297 Indent (os, indentG);
7298 os << "originator ";
7299 os << *originator;
7300 }
7301 else
7302 {
7303 Indent (os, indentG);
7304 os << "originator ";
7305 os << "-- void --";
7306 os << "," << endl;
7307 }
7308
7309 if (NOT_NULL (ukm))
7310 {
7311 Indent (os, indentG);
7312 os << "ukm ";
7313 os << *ukm;
7314 }
7315 else
7316 {
7317 Indent (os, indentG);
7318 os << "ukm ";
7319 os << "-- void --";
7320 os << "," << endl;
7321 }
7322
7323 if (NOT_NULL (keyEncryptionAlgorithm))
7324 {
7325 Indent (os, indentG);
7326 os << "keyEncryptionAlgorithm ";
7327 os << *keyEncryptionAlgorithm;
7328 }
7329 else
7330 {
7331 Indent (os, indentG);
7332 os << "keyEncryptionAlgorithm ";
7333 os << "-- void --";
7334 os << "," << endl;
7335 }
7336
7337 {
7338 Indent (os, indentG);
7339 os << "recipientEncryptedKeys ";
7340 os << recipientEncryptedKeys;
7341 }
7342
7343 os << endl;
7344 indentG -= stdIndentG;
7345 Indent (os, indentG);
7346 os << "}";
7347 #endif /* NDEBUG */
7348 } // KeyAgreeRecipientInfo::Print
7349
7350
7351 RecipientInfo::RecipientInfo()
7352 {
7353 choiceId = ktriCid;
7354 #if TCL
7355 ktri = new KeyTransRecipientInfo;
7356 #else
7357 ktri = NULL; // incomplete initialization of mandatory element!
7358 #endif // TCL
7359 }
7360
7361 RecipientInfo::RecipientInfo (const RecipientInfo &)
7362 {
7363 Asn1Error << "use of incompletely defined RecipientInfo::RecipientInfo (const RecipientInfo &)" << endl;
7364 abort();
7365 }
7366
7367 RecipientInfo::~RecipientInfo()
7368 {
7369 switch (choiceId)
7370 {
7371 case ktriCid:
7372 delete ktri;
7373 break;
7374 case kariCid:
7375 delete kari;
7376 break;
7377 case kekriCid:
7378 delete kekri;
7379 break;
7380 } // end of switch
7381 } // end of destructor
7382
7383 AsnType *RecipientInfo::Clone() const
7384 {
7385 return new RecipientInfo;
7386 }
7387
7388 AsnType *RecipientInfo::Copy() const
7389 {
7390 return new RecipientInfo (*this);
7391 }
7392
7393 #if SNACC_DEEP_COPY
7394 RecipientInfo &RecipientInfo::operator = (const RecipientInfo &that)
7395 #else // SNACC_DEEP_COPY
7396 RecipientInfo &RecipientInfo::operator = (const RecipientInfo &)
7397 #endif // SNACC_DEEP_COPY
7398 {
7399 #if SNACC_DEEP_COPY
7400 if (this != &that)
7401 {
7402 switch (choiceId)
7403 {
7404 case ktriCid:
7405 delete ktri;
7406 break;
7407 case kariCid:
7408 delete kari;
7409 break;
7410 case kekriCid:
7411 delete kekri;
7412 break;
7413 }
7414 switch (choiceId = that.choiceId)
7415 {
7416 case ktriCid:
7417 ktri = new KeyTransRecipientInfo;
7418 *ktri = *that.ktri;
7419 break;
7420 case kariCid:
7421 kari = new KeyAgreeRecipientInfo;
7422 *kari = *that.kari;
7423 break;
7424 case kekriCid:
7425 kekri = new KEKRecipientInfo;
7426 *kekri = *that.kekri;
7427 break;
7428 }
7429 }
7430
7431 return *this;
7432 #else // SNACC_DEEP_COPY
7433 Asn1Error << "use of incompletely defined RecipientInfo &RecipientInfo::operator = (const RecipientInfo &)" << endl;
7434 abort();
7435 // if your compiler complains here, check the -novolat option
7436 #endif // SNACC_DEEP_COPY
7437 }
7438
7439 AsnLen
7440 RecipientInfo::BEncContent (BUF_TYPE b)
7441 {
7442 AsnLen l;
7443 switch (choiceId)
7444 {
7445 case ktriCid:
7446 BEncEocIfNec (b);
7447 l = ktri->BEncContent (b);
7448 l += BEncConsLen (b, l);
7449
7450 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
7451 break;
7452
7453 case kariCid:
7454 BEncEocIfNec (b);
7455 l = kari->BEncContent (b);
7456 l += BEncConsLen (b, l);
7457
7458 l += BEncTag1 (b, CNTX, CONS, 1);
7459 break;
7460
7461 case kekriCid:
7462 BEncEocIfNec (b);
7463 l = kekri->BEncContent (b);
7464 l += BEncConsLen (b, l);
7465
7466 l += BEncTag1 (b, CNTX, CONS, 2);
7467 break;
7468
7469 } // end switch
7470 return l;
7471 } // RecipientInfo::BEncContent
7472
7473
7474 void RecipientInfo::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
7475 {
7476 switch (tag)
7477 {
7478 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
7479 choiceId = ktriCid;
7480 ktri = new KeyTransRecipientInfo;
7481 ktri->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
7482 break;
7483
7484 case MAKE_TAG_ID (CNTX, CONS, 1):
7485 choiceId = kariCid;
7486 kari = new KeyAgreeRecipientInfo;
7487 kari->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
7488 break;
7489
7490 case MAKE_TAG_ID (CNTX, CONS, 2):
7491 choiceId = kekriCid;
7492 kekri = new KEKRecipientInfo;
7493 kekri->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
7494 break;
7495
7496 default:
7497 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
7498 longjmp (env, -182);
7499 break;
7500 } // end switch
7501 } // RecipientInfo::BDecContent
7502
7503
7504 AsnLen RecipientInfo::BEnc (BUF_TYPE b)
7505 {
7506 AsnLen l;
7507 l = BEncContent (b);
7508 return l;
7509 }
7510
7511 void RecipientInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
7512 {
7513 AsnLen elmtLen;
7514 AsnTag tag;
7515
7516 /* CHOICEs are a special case - grab identifying tag */
7517 /* this allows easier handling of nested CHOICEs */
7518 tag = BDecTag (b, bytesDecoded, env);
7519 elmtLen = BDecLen (b, bytesDecoded, env);
7520 BDecContent (b, tag, elmtLen, bytesDecoded, env);
7521 }
7522
7523 int RecipientInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
7524 {
7525 bytesEncoded = BEnc (b);
7526 return !b.WriteError();
7527 }
7528
7529 int RecipientInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
7530 {
7531 ENV_TYPE env;
7532 int val;
7533
7534 bytesDecoded = 0;
7535 if ((val = setjmp (env)) == 0)
7536 {
7537 BDec (b, bytesDecoded, env);
7538 return !b.ReadError();
7539 }
7540 else
7541 return false;
7542 }
7543
7544 void RecipientInfo::Print (ostream &os) const
7545 {
7546 #ifndef NDEBUG
7547 switch (choiceId)
7548 {
7549 case ktriCid:
7550 os << "ktri ";
7551 if (ktri)
7552 os << *ktri;
7553 else
7554 os << "-- void3 --\n";
7555 break;
7556
7557 case kariCid:
7558 os << "kari ";
7559 if (kari)
7560 os << *kari;
7561 else
7562 os << "-- void3 --\n";
7563 break;
7564
7565 case kekriCid:
7566 os << "kekri ";
7567 if (kekri)
7568 os << *kekri;
7569 else
7570 os << "-- void3 --\n";
7571 break;
7572
7573 } // end of switch
7574 #endif /* NDEBUG */
7575 } // RecipientInfo::Print
7576
7577 AsnType *RecipientInfos::Clone() const
7578 {
7579 return new RecipientInfos;
7580 }
7581
7582 AsnType *RecipientInfos::Copy() const
7583 {
7584 return new RecipientInfos (*this);
7585 }
7586
7587 AsnLen RecipientInfos::BEnc (BUF_TYPE b)
7588 {
7589 AsnLen l;
7590 l = BEncContent (b);
7591 l += BEncConsLen (b, l);
7592 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
7593 return l;
7594 }
7595
7596 void RecipientInfos::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
7597 {
7598 AsnTag tag;
7599 AsnLen elmtLen1;
7600
7601 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
7602 {
7603 Asn1Error << "RecipientInfos::BDec: ERROR - wrong tag" << endl;
7604 longjmp (env, -183);
7605 }
7606 elmtLen1 = BDecLen (b, bytesDecoded, env);
7607 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
7608 }
7609
7610 RecipientInfos::RecipientInfos (const RecipientInfos &)
7611 {
7612 Asn1Error << "use of incompletely defined RecipientInfos::RecipientInfos (const RecipientInfos &)" << endl;
7613 abort();
7614 }
7615
7616 RecipientInfos::~RecipientInfos()
7617 {
7618 SetCurrToFirst();
7619 for (; Curr() != NULL; RemoveCurrFromList())
7620 ;
7621 } // end of destructor
7622
7623 #if SNACC_DEEP_COPY
7624 RecipientInfos &RecipientInfos::operator = (const RecipientInfos &that)
7625 #else // SNACC_DEEP_COPY
7626 RecipientInfos &RecipientInfos::operator = (const RecipientInfos &)
7627 #endif // SNACC_DEEP_COPY
7628 {
7629 #if SNACC_DEEP_COPY
7630 if (this != &that)
7631 {
7632 SetCurrToFirst();
7633 for (; Curr(); RemoveCurrFromList())
7634 ;
7635
7636 //that.SetCurrToFirst();
7637 //for (; that.Curr(); that.GoNext())
7638 // AppendCopy (*that.Curr());
7639 for (const AsnListElmt *run=that.first; run; run=run->next)
7640 AppendCopy (*run->elmt);
7641 }
7642
7643 return *this;
7644 #else // SNACC_DEEP_COPY
7645 Asn1Error << "use of incompletely defined RecipientInfos &RecipientInfos::operator = (const RecipientInfos &)" << endl;
7646 abort();
7647 // if your compiler complains here, check the -novolat option
7648 #endif // SNACC_DEEP_COPY
7649 }
7650
7651 void RecipientInfos::Print (ostream &os) const
7652 {
7653 #ifndef NDEBUG
7654 os << "{ -- SEQUENCE/SET OF -- " << endl;
7655 indentG += stdIndentG;
7656 //SetCurrToFirst();
7657 //for (; Curr() != NULL; GoNext())
7658 for (const AsnListElmt *run=first; run; run=run->next)
7659 {
7660 Indent (os, indentG);
7661 //os << *Curr();
7662 os << *run->elmt;
7663 //if (Curr() != Last())
7664 if (run != last)
7665 os << ",";
7666 os << endl;
7667 }
7668 indentG -= stdIndentG;
7669 Indent (os, indentG);
7670 os << "}\n";
7671 #endif /* NDEBUG */
7672
7673
7674 } // Print
7675
7676
7677 void RecipientInfos::SetCurrElmt (unsigned long int index)
7678 {
7679 unsigned long int i;
7680 curr = first;
7681 if (count)
7682 for (i = 0; (i < (count-1)) && (i < index); i++)
7683 curr = curr->next;
7684 } // RecipientInfos::SetCurrElmt
7685
7686
7687 unsigned long int RecipientInfos::GetCurrElmtIndex()
7688 {
7689 unsigned long int i;
7690 AsnListElmt *tmp;
7691 if (curr != NULL)
7692 {
7693 for (i = 0, tmp = first; tmp != NULL; i++)
7694 {
7695 if (tmp == curr)
7696 return i;
7697 else
7698 tmp = tmp->next;
7699 }
7700 }
7701 return count;
7702 } // RecipientInfos::GetCurrElmtIndex
7703
7704
7705 // alloc new list elmt, put at end of list
7706 // and return the component type
7707 RecipientInfo *RecipientInfos::Append()
7708 {
7709 AsnListElmt *newElmt;
7710 newElmt = new AsnListElmt;
7711 newElmt->elmt = new RecipientInfo;
7712 newElmt->next = NULL;
7713 if (last == NULL)
7714 {
7715 newElmt->prev = NULL;
7716 first = last = newElmt;
7717 }
7718 else
7719 {
7720 newElmt->prev = last;
7721 last->next = newElmt;
7722 last = newElmt;
7723 }
7724 count++;
7725 return (curr = newElmt)->elmt;
7726 } // RecipientInfos::Append
7727
7728
7729 // alloc new list elmt, put at begining of list
7730 // and return the component type
7731 RecipientInfo *RecipientInfos::Prepend()
7732 {
7733 AsnListElmt *newElmt;
7734 newElmt = new AsnListElmt;
7735 newElmt->elmt = new RecipientInfo;
7736 newElmt->prev = NULL;
7737 if (first == NULL)
7738 {
7739 newElmt->next = NULL;
7740 first = last = newElmt;
7741 }
7742 else
7743 {
7744 newElmt->next = first;
7745 first->prev = newElmt;
7746 first = newElmt;
7747 }
7748 count++;
7749 return (curr = newElmt)->elmt;
7750 } // RecipientInfos::Prepend
7751
7752
7753 // alloc new list elmt, insert it before the
7754 // current element and return the component type
7755 // if the current element is null, the new element
7756 // is placed at the beginning of the list.
7757 RecipientInfo *RecipientInfos::InsertBefore()
7758 {
7759 AsnListElmt *newElmt;
7760 newElmt = new AsnListElmt;
7761 newElmt->elmt = new RecipientInfo;
7762 if (curr == NULL)
7763 {
7764 newElmt->next = first;
7765 newElmt->prev = NULL;
7766 first = newElmt;
7767 if (last == NULL)
7768 last = newElmt;
7769 }
7770 else
7771 {
7772 newElmt->next = curr;
7773 newElmt->prev = curr->prev;
7774 curr->prev = newElmt;
7775 if (curr == first)
7776 first = newElmt;
7777 else
7778 newElmt->prev->next = newElmt;
7779 }
7780 count++;
7781 return (curr = newElmt)->elmt;
7782 } // RecipientInfos::InsertBefore
7783
7784
7785 // alloc new list elmt, insert it after the
7786 // current element and return the component type
7787 // if the current element is null, the new element
7788 // is placed at the end of the list.
7789 RecipientInfo *RecipientInfos::InsertAfter()
7790 {
7791 AsnListElmt *newElmt;
7792 newElmt = new AsnListElmt;
7793 newElmt->elmt = new RecipientInfo;
7794 if (curr == NULL)
7795 {
7796 newElmt->prev = last;
7797 newElmt->next = NULL;
7798 last = newElmt;
7799 if (first == NULL)
7800 first = newElmt;
7801 }
7802 else
7803 {
7804 newElmt->prev = curr;
7805 newElmt->next = curr->next;
7806 curr->next = newElmt;
7807 if (curr == last)
7808 last = newElmt;
7809 else
7810 newElmt->next->prev = newElmt;
7811 }
7812 count++;
7813 return (curr = newElmt)->elmt;
7814 } // RecipientInfos::InsertAfter
7815
7816
7817 RecipientInfos &RecipientInfos::AppendCopy (RecipientInfo &elmt)
7818 {
7819 AsnListElmt *newElmt;
7820 newElmt = new AsnListElmt;
7821 newElmt->elmt = new RecipientInfo;
7822 *newElmt->elmt = elmt;
7823 newElmt->next = NULL;
7824 if (last == NULL)
7825 {
7826 newElmt->prev = NULL;
7827 first = last = newElmt;
7828 }
7829 else
7830 {
7831 newElmt->prev = last;
7832 last->next = newElmt;
7833 last = newElmt;
7834 }
7835 count++;
7836 return *this;
7837 } // AppendCopy
7838
7839
7840 RecipientInfos &RecipientInfos::PrependCopy (RecipientInfo &elmt)
7841 {
7842 AsnListElmt *newElmt;
7843 newElmt = new AsnListElmt;
7844 newElmt->elmt = new RecipientInfo;
7845 *newElmt->elmt = elmt;
7846 newElmt->prev = NULL;
7847 if (first == NULL)
7848 {
7849 newElmt->next = NULL;
7850 first = last = newElmt;
7851 }
7852 else
7853 {
7854 newElmt->next = first;
7855 first->prev = newElmt;
7856 first = newElmt;
7857 }
7858 count++;
7859 return *this;
7860 } // RecipientInfos::PrependCopy
7861
7862
7863 // alloc new list elmt, insert it before the
7864 // current element, copy the given elmt into the new elmt
7865 // and return the component type.
7866 // if the current element is null, the new element
7867 // is placed at the beginning of the list.
7868 RecipientInfos &RecipientInfos::InsertBeforeAndCopy (RecipientInfo &elmt)
7869 {
7870 AsnListElmt *newElmt;
7871
7872 newElmt = new AsnListElmt;
7873 newElmt->elmt = new RecipientInfo;
7874 *newElmt->elmt = elmt;
7875
7876 if (curr == NULL)
7877 {
7878 newElmt->next = first;
7879 newElmt->prev = NULL;
7880 first = newElmt;
7881 if (last == NULL)
7882 last = newElmt;
7883 }
7884 else
7885 {
7886 newElmt->next = curr;
7887 newElmt->prev = curr->prev;
7888 curr->prev = newElmt;
7889 if (curr == first)
7890 first = newElmt;
7891 else
7892 newElmt->prev->next = newElmt;
7893 }
7894 count++;
7895 return *this;
7896 } // RecipientInfos::InsertBeforeAndCopy
7897
7898
7899 // alloc new list elmt, insert it after the
7900 // current element, copy given elmt in to new elmt
7901 // and return the component type
7902 // if the current element is null, the new element
7903 // is placed at the end of the list.
7904 RecipientInfos &RecipientInfos::InsertAfterAndCopy (RecipientInfo &elmt)
7905 {
7906 AsnListElmt *newElmt;
7907
7908 newElmt = new AsnListElmt;
7909 newElmt->elmt = new RecipientInfo;
7910 *newElmt->elmt = elmt;
7911 if (curr == NULL)
7912 {
7913 newElmt->prev = last;
7914 newElmt->next = NULL;
7915 last = newElmt;
7916 if (first == NULL)
7917 first = newElmt;
7918 }
7919 else
7920 {
7921 newElmt->prev = curr;
7922 newElmt->next = curr->next;
7923 curr->next = newElmt;
7924 if (curr == last)
7925 last = newElmt;
7926 else
7927 newElmt->next->prev = newElmt;
7928 }
7929 count++;
7930 return *this;
7931 } // RecipientInfos::InsertAfterAndCopy
7932
7933
7934 // remove current element from list if current element is not NULL
7935 // The new current element will be the next element.
7936 // If the current element is the last element in the list
7937 // the second but last element will become the new current element.
7938 void RecipientInfos::RemoveCurrFromList()
7939 {
7940 AsnListElmt *del_elmt;
7941
7942 if (curr != NULL)
7943 {
7944 del_elmt = curr;
7945 count--;
7946
7947 if (count == 0)
7948 first = last = curr = NULL;
7949 else if (curr == first)
7950 {
7951 curr = first= first->next;
7952 first->prev = NULL;
7953 }
7954 else if (curr == last)
7955 {
7956 curr = last = last->prev;
7957 last->next = NULL;
7958 }
7959 else
7960 {
7961 curr->prev->next = curr->next;
7962 curr->next->prev = curr->prev;
7963 }
7964
7965 delete del_elmt->elmt;
7966 delete del_elmt;
7967 }
7968 }
7969
7970
7971 AsnLen RecipientInfos::BEncContent (BUF_TYPE b)
7972 {
7973 AsnListElmt *currElmt;
7974 AsnLen elmtLen;
7975 AsnLen totalLen = 0;
7976 {
7977 int iii,icount;
7978 CSM_Buffer **tmpEnc=NULL;
7979 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
7980 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
7981 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
7982 {
7983 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
7984 ENCODE_BUF2(tmpEnc[iii]);
7985 }
7986 vdasnacc_sortSetOf(tmpEnc, icount);
7987 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
7988 SM_WriteToAsnBuf(tmpEnc[iii], b);
7989 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
7990 free(tmpEnc);
7991 }
7992 totalLen += elmtLen;
7993 return totalLen;
7994 } // RecipientInfos::BEncContent
7995
7996
7997 void RecipientInfos::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
7998 AsnLen &bytesDecoded, ENV_TYPE env)
7999 {
8000 RecipientInfo *listElmt;
8001 AsnTag tag1;
8002 AsnLen listBytesDecoded = 0;
8003 AsnLen elmtLen1;
8004
8005 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
8006 {
8007 tag1 = BDecTag (b, listBytesDecoded, env);
8008 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
8009 {
8010 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
8011 break;
8012 }
8013 if (!((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
8014 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 1))
8015 || (tag1 == MAKE_TAG_ID (CNTX, CONS, 2))))
8016 {
8017 Asn1Error << "Unexpected Tag" << endl;
8018 longjmp (env, -184);
8019 }
8020
8021 elmtLen1 = BDecLen (b, listBytesDecoded, env);
8022 listElmt = Append();
8023 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
8024 }
8025
8026 bytesDecoded += listBytesDecoded;
8027 } // RecipientInfos::BDecContent
8028
8029
8030 ContentInfo::ContentInfo()
8031 {
8032 }
8033
8034 ContentInfo::ContentInfo (const ContentInfo &)
8035 {
8036 Asn1Error << "use of incompletely defined ContentInfo::ContentInfo (const ContentInfo &)" << endl;
8037 abort();
8038 }
8039
8040 ContentInfo::~ContentInfo()
8041 {
8042 }
8043
8044 AsnType *ContentInfo::Clone() const
8045 {
8046 return new ContentInfo;
8047 }
8048
8049 AsnType *ContentInfo::Copy() const
8050 {
8051 return new ContentInfo (*this);
8052 }
8053
8054 #if SNACC_DEEP_COPY
8055 ContentInfo &ContentInfo::operator = (const ContentInfo &that)
8056 #else // SNACC_DEEP_COPY
8057 ContentInfo &ContentInfo::operator = (const ContentInfo &)
8058 #endif // SNACC_DEEP_COPY
8059 {
8060 #if SNACC_DEEP_COPY
8061 if (this != &that)
8062 {
8063 contentType = that.contentType;
8064 content = that.content;
8065 }
8066
8067 return *this;
8068 #else // SNACC_DEEP_COPY
8069 Asn1Error << "use of incompletely defined ContentInfo &ContentInfo::operator = (const ContentInfo &)" << endl;
8070 abort();
8071 // if your compiler complains here, check the -novolat option
8072 #endif // SNACC_DEEP_COPY
8073 }
8074
8075 AsnLen
8076 ContentInfo::BEncContent (BUF_TYPE b)
8077 {
8078 AsnLen totalLen = 0;
8079 AsnLen l;
8080
8081 BEncEocIfNec (b);
8082 ENC_LOAD_ANYBUF(&content, b, l);
8083 l += BEncConsLen (b, l);
8084
8085 l += BEncTag1 (b, CNTX, CONS, 0);
8086 totalLen += l;
8087
8088 l = contentType.BEncContent (b);
8089 l += BEncDefLen (b, l);
8090
8091 l += BEncTag1 (b, UNIV, PRIM, OID_TAG_CODE);
8092 totalLen += l;
8093
8094 return totalLen;
8095 } // ContentInfo::BEncContent
8096
8097
8098 void ContentInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
8099 {
8100 AsnTag tag1;
8101 AsnLen seqBytesDecoded = 0;
8102 AsnLen elmtLen1;
8103 tag1 = BDecTag (b, seqBytesDecoded, env);
8104
8105 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))
8106 {
8107 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8108 contentType.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8109 tag1 = BDecTag (b, seqBytesDecoded, env);
8110 }
8111 else
8112 {
8113 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8114 longjmp (env, -185);
8115 }
8116
8117 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
8118 {
8119 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8120 DEC_LOAD_ANYBUF(&content, b, seqBytesDecoded, env);
8121 if (elmtLen1 == INDEFINITE_LEN)
8122 BDecEoc (b, seqBytesDecoded, env);
8123
8124 }
8125 else
8126 {
8127 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8128 longjmp (env, -186);
8129 }
8130
8131 bytesDecoded += seqBytesDecoded;
8132 if (elmtLen0 == INDEFINITE_LEN)
8133 {
8134 BDecEoc (b, bytesDecoded, env);
8135 return;
8136 }
8137 else if (seqBytesDecoded != elmtLen0)
8138 {
8139 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
8140 longjmp (env, -187);
8141 }
8142 else
8143 return;
8144 } // ContentInfo::BDecContent
8145
8146 AsnLen ContentInfo::BEnc (BUF_TYPE b)
8147 {
8148 AsnLen l;
8149 l = BEncContent (b);
8150 l += BEncConsLen (b, l);
8151 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
8152 return l;
8153 }
8154
8155 void ContentInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
8156 {
8157 AsnTag tag;
8158 AsnLen elmtLen1;
8159
8160 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
8161 {
8162 Asn1Error << "ContentInfo::BDec: ERROR - wrong tag" << endl;
8163 longjmp (env, -188);
8164 }
8165 elmtLen1 = BDecLen (b, bytesDecoded, env);
8166 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
8167 }
8168
8169 int ContentInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
8170 {
8171 bytesEncoded = BEnc (b);
8172 return !b.WriteError();
8173 }
8174
8175 int ContentInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
8176 {
8177 ENV_TYPE env;
8178 int val;
8179
8180 bytesDecoded = 0;
8181 if ((val = setjmp (env)) == 0)
8182 {
8183 BDec (b, bytesDecoded, env);
8184 return !b.ReadError();
8185 }
8186 else
8187 return false;
8188 }
8189
8190 void ContentInfo::Print (ostream &os) const
8191 {
8192 #ifndef NDEBUG
8193 os << "{ -- SEQUENCE --" << endl;
8194 indentG += stdIndentG;
8195
8196 {
8197 Indent (os, indentG);
8198 os << "contentType ";
8199 os << contentType;
8200 os << "," << endl;
8201 }
8202
8203 {
8204 Indent (os, indentG);
8205 os << "content ";
8206 os << content;
8207 }
8208
8209 os << endl;
8210 indentG -= stdIndentG;
8211 Indent (os, indentG);
8212 os << "}";
8213 #endif /* NDEBUG */
8214 } // ContentInfo::Print
8215
8216
8217 SignedData::SignedData()
8218 {
8219 #if TCL
8220 encapContentInfo = new EncapsulatedContentInfo;
8221 #else
8222 encapContentInfo = NULL; // incomplete initialization of mandatory element!
8223 #endif // TCL
8224 certificates = NULL;
8225 crls = NULL;
8226 }
8227
8228 SignedData::SignedData (const SignedData &)
8229 {
8230 Asn1Error << "use of incompletely defined SignedData::SignedData (const SignedData &)" << endl;
8231 abort();
8232 }
8233
8234 SignedData::~SignedData()
8235 {
8236 delete encapContentInfo;
8237 delete certificates;
8238 delete crls;
8239 }
8240
8241 AsnType *SignedData::Clone() const
8242 {
8243 return new SignedData;
8244 }
8245
8246 AsnType *SignedData::Copy() const
8247 {
8248 return new SignedData (*this);
8249 }
8250
8251 #if SNACC_DEEP_COPY
8252 SignedData &SignedData::operator = (const SignedData &that)
8253 #else // SNACC_DEEP_COPY
8254 SignedData &SignedData::operator = (const SignedData &)
8255 #endif // SNACC_DEEP_COPY
8256 {
8257 #if SNACC_DEEP_COPY
8258 if (this != &that)
8259 {
8260 version = that.version;
8261 digestAlgorithms = that.digestAlgorithms;
8262 if (that.encapContentInfo)
8263 {
8264 if (!encapContentInfo)
8265 encapContentInfo = new EncapsulatedContentInfo;
8266 *encapContentInfo = *that.encapContentInfo;
8267 }
8268 else
8269 {
8270 delete encapContentInfo;
8271 encapContentInfo = NULL;
8272 }
8273 if (that.certificates)
8274 {
8275 if (!certificates)
8276 certificates = new CertificateSet;
8277 *certificates = *that.certificates;
8278 }
8279 else
8280 {
8281 delete certificates;
8282 certificates = NULL;
8283 }
8284 if (that.crls)
8285 {
8286 if (!crls)
8287 crls = new CertificateRevocationLists;
8288 *crls = *that.crls;
8289 }
8290 else
8291 {
8292 delete crls;
8293 crls = NULL;
8294 }
8295 signerInfos = that.signerInfos;
8296 }
8297
8298 return *this;
8299 #else // SNACC_DEEP_COPY
8300 Asn1Error << "use of incompletely defined SignedData &SignedData::operator = (const SignedData &)" << endl;
8301 abort();
8302 // if your compiler complains here, check the -novolat option
8303 #endif // SNACC_DEEP_COPY
8304 }
8305
8306 AsnLen
8307 SignedData::BEncContent (BUF_TYPE b)
8308 {
8309 AsnLen totalLen = 0;
8310 AsnLen l;
8311
8312 BEncEocIfNec (b);
8313 l = signerInfos.BEncContent (b);
8314 l += BEncConsLen (b, l);
8315
8316 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
8317 totalLen += l;
8318
8319 if (NOT_NULL (crls))
8320 {
8321 BEncEocIfNec (b);
8322 l = crls->BEncContent (b);
8323 l += BEncConsLen (b, l);
8324
8325 l += BEncTag1 (b, CNTX, CONS, 1);
8326 totalLen += l;
8327 }
8328
8329 if (NOT_NULL (certificates))
8330 {
8331 BEncEocIfNec (b);
8332 l = certificates->BEncContent (b);
8333 l += BEncConsLen (b, l);
8334
8335 l += BEncTag1 (b, CNTX, CONS, 0);
8336 totalLen += l;
8337 }
8338
8339 BEncEocIfNec (b);
8340 l = encapContentInfo->BEncContent (b);
8341 l += BEncConsLen (b, l);
8342
8343 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
8344 totalLen += l;
8345
8346 BEncEocIfNec (b);
8347 l = digestAlgorithms.BEncContent (b);
8348 l += BEncConsLen (b, l);
8349
8350 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
8351 totalLen += l;
8352
8353 l = version.BEncContent (b);
8354 BEncDefLenTo127 (b, l);
8355 l++;
8356
8357 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
8358 totalLen += l;
8359
8360 return totalLen;
8361 } // SignedData::BEncContent
8362
8363
8364 void SignedData::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
8365 {
8366 AsnTag tag1;
8367 AsnLen seqBytesDecoded = 0;
8368 AsnLen elmtLen1;
8369 tag1 = BDecTag (b, seqBytesDecoded, env);
8370
8371 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
8372 {
8373 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8374 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8375 tag1 = BDecTag (b, seqBytesDecoded, env);
8376 }
8377 else
8378 {
8379 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8380 longjmp (env, -189);
8381 }
8382
8383 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
8384 {
8385 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8386 digestAlgorithms.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8387 tag1 = BDecTag (b, seqBytesDecoded, env);
8388 }
8389 else
8390 {
8391 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8392 longjmp (env, -190);
8393 }
8394
8395 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
8396 {
8397 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8398 encapContentInfo = new EncapsulatedContentInfo;
8399 encapContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8400 tag1 = BDecTag (b, seqBytesDecoded, env);
8401 }
8402 else
8403 {
8404 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8405 longjmp (env, -191);
8406 }
8407
8408 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
8409 {
8410 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8411 certificates = new CertificateSet;
8412 certificates->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8413 tag1 = BDecTag (b, seqBytesDecoded, env);
8414 }
8415
8416 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
8417 {
8418 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8419 crls = new CertificateRevocationLists;
8420 crls->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8421 tag1 = BDecTag (b, seqBytesDecoded, env);
8422 }
8423
8424 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
8425 {
8426 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8427 signerInfos.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8428 }
8429 else
8430 {
8431 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8432 longjmp (env, -192);
8433 }
8434
8435 bytesDecoded += seqBytesDecoded;
8436 if (elmtLen0 == INDEFINITE_LEN)
8437 {
8438 BDecEoc (b, bytesDecoded, env);
8439 return;
8440 }
8441 else if (seqBytesDecoded != elmtLen0)
8442 {
8443 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
8444 longjmp (env, -193);
8445 }
8446 else
8447 return;
8448 } // SignedData::BDecContent
8449
8450 AsnLen SignedData::BEnc (BUF_TYPE b)
8451 {
8452 AsnLen l;
8453 l = BEncContent (b);
8454 l += BEncConsLen (b, l);
8455 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
8456 return l;
8457 }
8458
8459 void SignedData::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
8460 {
8461 AsnTag tag;
8462 AsnLen elmtLen1;
8463
8464 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
8465 {
8466 Asn1Error << "SignedData::BDec: ERROR - wrong tag" << endl;
8467 longjmp (env, -194);
8468 }
8469 elmtLen1 = BDecLen (b, bytesDecoded, env);
8470 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
8471 }
8472
8473 int SignedData::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
8474 {
8475 bytesEncoded = BEnc (b);
8476 return !b.WriteError();
8477 }
8478
8479 int SignedData::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
8480 {
8481 ENV_TYPE env;
8482 int val;
8483
8484 bytesDecoded = 0;
8485 if ((val = setjmp (env)) == 0)
8486 {
8487 BDec (b, bytesDecoded, env);
8488 return !b.ReadError();
8489 }
8490 else
8491 return false;
8492 }
8493
8494 void SignedData::Print (ostream &os) const
8495 {
8496 #ifndef NDEBUG
8497 os << "{ -- SEQUENCE --" << endl;
8498 indentG += stdIndentG;
8499
8500 {
8501 Indent (os, indentG);
8502 os << "version ";
8503 os << version;
8504 os << "," << endl;
8505 }
8506
8507 {
8508 Indent (os, indentG);
8509 os << "digestAlgorithms ";
8510 os << digestAlgorithms;
8511 os << "," << endl;
8512 }
8513
8514 if (NOT_NULL (encapContentInfo))
8515 {
8516 Indent (os, indentG);
8517 os << "encapContentInfo ";
8518 os << *encapContentInfo;
8519 }
8520 else
8521 {
8522 Indent (os, indentG);
8523 os << "encapContentInfo ";
8524 os << "-- void --";
8525 os << "," << endl;
8526 }
8527
8528 if (NOT_NULL (certificates))
8529 {
8530 Indent (os, indentG);
8531 os << "certificates ";
8532 os << *certificates;
8533 }
8534 else
8535 {
8536 Indent (os, indentG);
8537 os << "certificates ";
8538 os << "-- void --";
8539 os << "," << endl;
8540 }
8541
8542 if (NOT_NULL (crls))
8543 {
8544 Indent (os, indentG);
8545 os << "crls ";
8546 os << *crls;
8547 }
8548 else
8549 {
8550 Indent (os, indentG);
8551 os << "crls ";
8552 os << "-- void --";
8553 os << "," << endl;
8554 }
8555
8556 {
8557 Indent (os, indentG);
8558 os << "signerInfos ";
8559 os << signerInfos;
8560 }
8561
8562 os << endl;
8563 indentG -= stdIndentG;
8564 Indent (os, indentG);
8565 os << "}";
8566 #endif /* NDEBUG */
8567 } // SignedData::Print
8568
8569
8570 EnvelopedData::EnvelopedData()
8571 {
8572 originatorInfo = NULL;
8573 #if TCL
8574 encryptedContentInfo = new EncryptedContentInfo;
8575 #else
8576 encryptedContentInfo = NULL; // incomplete initialization of mandatory element!
8577 #endif // TCL
8578 unprotectedAttrs = NULL;
8579 }
8580
8581 EnvelopedData::EnvelopedData (const EnvelopedData &)
8582 {
8583 Asn1Error << "use of incompletely defined EnvelopedData::EnvelopedData (const EnvelopedData &)" << endl;
8584 abort();
8585 }
8586
8587 EnvelopedData::~EnvelopedData()
8588 {
8589 delete originatorInfo;
8590 delete encryptedContentInfo;
8591 delete unprotectedAttrs;
8592 }
8593
8594 AsnType *EnvelopedData::Clone() const
8595 {
8596 return new EnvelopedData;
8597 }
8598
8599 AsnType *EnvelopedData::Copy() const
8600 {
8601 return new EnvelopedData (*this);
8602 }
8603
8604 #if SNACC_DEEP_COPY
8605 EnvelopedData &EnvelopedData::operator = (const EnvelopedData &that)
8606 #else // SNACC_DEEP_COPY
8607 EnvelopedData &EnvelopedData::operator = (const EnvelopedData &)
8608 #endif // SNACC_DEEP_COPY
8609 {
8610 #if SNACC_DEEP_COPY
8611 if (this != &that)
8612 {
8613 version = that.version;
8614 if (that.originatorInfo)
8615 {
8616 if (!originatorInfo)
8617 originatorInfo = new OriginatorInfo;
8618 *originatorInfo = *that.originatorInfo;
8619 }
8620 else
8621 {
8622 delete originatorInfo;
8623 originatorInfo = NULL;
8624 }
8625 recipientInfos = that.recipientInfos;
8626 if (that.encryptedContentInfo)
8627 {
8628 if (!encryptedContentInfo)
8629 encryptedContentInfo = new EncryptedContentInfo;
8630 *encryptedContentInfo = *that.encryptedContentInfo;
8631 }
8632 else
8633 {
8634 delete encryptedContentInfo;
8635 encryptedContentInfo = NULL;
8636 }
8637 if (that.unprotectedAttrs)
8638 {
8639 if (!unprotectedAttrs)
8640 unprotectedAttrs = new Attributes;
8641 *unprotectedAttrs = *that.unprotectedAttrs;
8642 }
8643 else
8644 {
8645 delete unprotectedAttrs;
8646 unprotectedAttrs = NULL;
8647 }
8648 }
8649
8650 return *this;
8651 #else // SNACC_DEEP_COPY
8652 Asn1Error << "use of incompletely defined EnvelopedData &EnvelopedData::operator = (const EnvelopedData &)" << endl;
8653 abort();
8654 // if your compiler complains here, check the -novolat option
8655 #endif // SNACC_DEEP_COPY
8656 }
8657
8658 AsnLen
8659 EnvelopedData::BEncContent (BUF_TYPE b)
8660 {
8661 AsnLen totalLen = 0;
8662 AsnLen l;
8663
8664 if (NOT_NULL (unprotectedAttrs))
8665 {
8666 BEncEocIfNec (b);
8667 l = unprotectedAttrs->BEncContent (b);
8668 l += BEncConsLen (b, l);
8669
8670 l += BEncTag1 (b, CNTX, CONS, 1);
8671 totalLen += l;
8672 }
8673
8674 BEncEocIfNec (b);
8675 l = encryptedContentInfo->BEncContent (b);
8676 l += BEncConsLen (b, l);
8677
8678 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
8679 totalLen += l;
8680
8681 BEncEocIfNec (b);
8682 l = recipientInfos.BEncContent (b);
8683 l += BEncConsLen (b, l);
8684
8685 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
8686 totalLen += l;
8687
8688 if (NOT_NULL (originatorInfo))
8689 {
8690 BEncEocIfNec (b);
8691 l = originatorInfo->BEncContent (b);
8692 l += BEncConsLen (b, l);
8693
8694 l += BEncTag1 (b, CNTX, CONS, 0);
8695 totalLen += l;
8696 }
8697
8698 l = version.BEncContent (b);
8699 BEncDefLenTo127 (b, l);
8700 l++;
8701
8702 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
8703 totalLen += l;
8704
8705 return totalLen;
8706 } // EnvelopedData::BEncContent
8707
8708
8709 void EnvelopedData::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
8710 {
8711 AsnTag tag1;
8712 AsnLen seqBytesDecoded = 0;
8713 AsnLen elmtLen1;
8714 tag1 = BDecTag (b, seqBytesDecoded, env);
8715
8716 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
8717 {
8718 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8719 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8720 tag1 = BDecTag (b, seqBytesDecoded, env);
8721 }
8722 else
8723 {
8724 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8725 longjmp (env, -195);
8726 }
8727
8728 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
8729 {
8730 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8731 originatorInfo = new OriginatorInfo;
8732 originatorInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8733 tag1 = BDecTag (b, seqBytesDecoded, env);
8734 }
8735
8736 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
8737 {
8738 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8739 recipientInfos.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8740 tag1 = BDecTag (b, seqBytesDecoded, env);
8741 }
8742 else
8743 {
8744 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8745 longjmp (env, -196);
8746 }
8747
8748 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
8749 {
8750 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8751 encryptedContentInfo = new EncryptedContentInfo;
8752 encryptedContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8753 if (seqBytesDecoded == elmtLen0)
8754 {
8755 bytesDecoded += seqBytesDecoded;
8756 return;
8757 }
8758 else
8759 {
8760 tag1 = BDecTag (b, seqBytesDecoded, env);
8761
8762 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
8763 {
8764 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
8765 bytesDecoded += seqBytesDecoded;
8766 return;
8767 }
8768 }
8769 }
8770 else
8771 {
8772 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
8773 longjmp (env, -197);
8774 }
8775
8776 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
8777 {
8778 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
8779 unprotectedAttrs = new Attributes;
8780 unprotectedAttrs->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
8781 }
8782
8783 bytesDecoded += seqBytesDecoded;
8784 if (elmtLen0 == INDEFINITE_LEN)
8785 {
8786 BDecEoc (b, bytesDecoded, env);
8787 return;
8788 }
8789 else if (seqBytesDecoded != elmtLen0)
8790 {
8791 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
8792 longjmp (env, -198);
8793 }
8794 else
8795 return;
8796 } // EnvelopedData::BDecContent
8797
8798 AsnLen EnvelopedData::BEnc (BUF_TYPE b)
8799 {
8800 AsnLen l;
8801 l = BEncContent (b);
8802 l += BEncConsLen (b, l);
8803 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
8804 return l;
8805 }
8806
8807 void EnvelopedData::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
8808 {
8809 AsnTag tag;
8810 AsnLen elmtLen1;
8811
8812 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
8813 {
8814 Asn1Error << "EnvelopedData::BDec: ERROR - wrong tag" << endl;
8815 longjmp (env, -199);
8816 }
8817 elmtLen1 = BDecLen (b, bytesDecoded, env);
8818 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
8819 }
8820
8821 int EnvelopedData::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
8822 {
8823 bytesEncoded = BEnc (b);
8824 return !b.WriteError();
8825 }
8826
8827 int EnvelopedData::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
8828 {
8829 ENV_TYPE env;
8830 int val;
8831
8832 bytesDecoded = 0;
8833 if ((val = setjmp (env)) == 0)
8834 {
8835 BDec (b, bytesDecoded, env);
8836 return !b.ReadError();
8837 }
8838 else
8839 return false;
8840 }
8841
8842 void EnvelopedData::Print (ostream &os) const
8843 {
8844 #ifndef NDEBUG
8845 os << "{ -- SEQUENCE --" << endl;
8846 indentG += stdIndentG;
8847
8848 {
8849 Indent (os, indentG);
8850 os << "version ";
8851 os << version;
8852 os << "," << endl;
8853 }
8854
8855 if (NOT_NULL (originatorInfo))
8856 {
8857 Indent (os, indentG);
8858 os << "originatorInfo ";
8859 os << *originatorInfo;
8860 }
8861 else
8862 {
8863 Indent (os, indentG);
8864 os << "originatorInfo ";
8865 os << "-- void --";
8866 os << "," << endl;
8867 }
8868
8869 {
8870 Indent (os, indentG);
8871 os << "recipientInfos ";
8872 os << recipientInfos;
8873 os << "," << endl;
8874 }
8875
8876 if (NOT_NULL (encryptedContentInfo))
8877 {
8878 Indent (os, indentG);
8879 os << "encryptedContentInfo ";
8880 os << *encryptedContentInfo;
8881 }
8882 else
8883 {
8884 Indent (os, indentG);
8885 os << "encryptedContentInfo ";
8886 os << "-- void --";
8887 os << "," << endl;
8888 }
8889
8890 if (NOT_NULL (unprotectedAttrs))
8891 {
8892 os << ","<< endl;
8893 Indent (os, indentG);
8894 os << "unprotectedAttrs ";
8895 os << *unprotectedAttrs;
8896 }
8897 else
8898 {
8899 Indent (os, indentG);
8900 os << "unprotectedAttrs ";
8901 os << "-- void --";
8902 os << endl;
8903 }
8904
8905 os << endl;
8906 indentG -= stdIndentG;
8907 Indent (os, indentG);
8908 os << "}";
8909 #endif /* NDEBUG */
8910 } // EnvelopedData::Print
8911
8912
8913 DigestedData::DigestedData()
8914 {
8915 #if TCL
8916 digestAlgorithm = new DigestAlgorithmIdentifier;
8917 #else
8918 digestAlgorithm = NULL; // incomplete initialization of mandatory element!
8919 #endif // TCL
8920 #if TCL
8921 encapContentInfo = new EncapsulatedContentInfo;
8922 #else
8923 encapContentInfo = NULL; // incomplete initialization of mandatory element!
8924 #endif // TCL
8925 }
8926
8927 DigestedData::DigestedData (const DigestedData &)
8928 {
8929 Asn1Error << "use of incompletely defined DigestedData::DigestedData (const DigestedData &)" << endl;
8930 abort();
8931 }
8932
8933 DigestedData::~DigestedData()
8934 {
8935 delete digestAlgorithm;
8936 delete encapContentInfo;
8937 }
8938
8939 AsnType *DigestedData::Clone() const
8940 {
8941 return new DigestedData;
8942 }
8943
8944 AsnType *DigestedData::Copy() const
8945 {
8946 return new DigestedData (*this);
8947 }
8948
8949 #if SNACC_DEEP_COPY
8950 DigestedData &DigestedData::operator = (const DigestedData &that)
8951 #else // SNACC_DEEP_COPY
8952 DigestedData &DigestedData::operator = (const DigestedData &)
8953 #endif // SNACC_DEEP_COPY
8954 {
8955 #if SNACC_DEEP_COPY
8956 if (this != &that)
8957 {
8958 version = that.version;
8959 if (that.digestAlgorithm)
8960 {
8961 if (!digestAlgorithm)
8962 digestAlgorithm = new DigestAlgorithmIdentifier;
8963 *digestAlgorithm = *that.digestAlgorithm;
8964 }
8965 else
8966 {
8967 delete digestAlgorithm;
8968 digestAlgorithm = NULL;
8969 }
8970 if (that.encapContentInfo)
8971 {
8972 if (!encapContentInfo)
8973 encapContentInfo = new EncapsulatedContentInfo;
8974 *encapContentInfo = *that.encapContentInfo;
8975 }
8976 else
8977 {
8978 delete encapContentInfo;
8979 encapContentInfo = NULL;
8980 }
8981 digest = that.digest;
8982 }
8983
8984 return *this;
8985 #else // SNACC_DEEP_COPY
8986 Asn1Error << "use of incompletely defined DigestedData &DigestedData::operator = (const DigestedData &)" << endl;
8987 abort();
8988 // if your compiler complains here, check the -novolat option
8989 #endif // SNACC_DEEP_COPY
8990 }
8991
8992 AsnLen
8993 DigestedData::BEncContent (BUF_TYPE b)
8994 {
8995 AsnLen totalLen = 0;
8996 AsnLen l;
8997
8998 l = digest.BEncContent (b);
8999 l += BEncDefLen (b, l);
9000
9001 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
9002 totalLen += l;
9003
9004 BEncEocIfNec (b);
9005 l = encapContentInfo->BEncContent (b);
9006 l += BEncConsLen (b, l);
9007
9008 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9009 totalLen += l;
9010
9011 BEncEocIfNec (b);
9012 l = digestAlgorithm->BEncContent (b);
9013 l += BEncConsLen (b, l);
9014
9015 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9016 totalLen += l;
9017
9018 l = version.BEncContent (b);
9019 BEncDefLenTo127 (b, l);
9020 l++;
9021
9022 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
9023 totalLen += l;
9024
9025 return totalLen;
9026 } // DigestedData::BEncContent
9027
9028
9029 void DigestedData::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
9030 {
9031 AsnTag tag1;
9032 AsnLen seqBytesDecoded = 0;
9033 AsnLen elmtLen1;
9034 tag1 = BDecTag (b, seqBytesDecoded, env);
9035
9036 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
9037 {
9038 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9039 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9040 tag1 = BDecTag (b, seqBytesDecoded, env);
9041 }
9042 else
9043 {
9044 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9045 longjmp (env, -200);
9046 }
9047
9048 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
9049 {
9050 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9051 digestAlgorithm = new DigestAlgorithmIdentifier;
9052 digestAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9053 tag1 = BDecTag (b, seqBytesDecoded, env);
9054 }
9055 else
9056 {
9057 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9058 longjmp (env, -201);
9059 }
9060
9061 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
9062 {
9063 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9064 encapContentInfo = new EncapsulatedContentInfo;
9065 encapContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9066 tag1 = BDecTag (b, seqBytesDecoded, env);
9067 }
9068 else
9069 {
9070 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9071 longjmp (env, -202);
9072 }
9073
9074 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
9075 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
9076 {
9077 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9078 digest.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9079 }
9080 else
9081 {
9082 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9083 longjmp (env, -203);
9084 }
9085
9086 bytesDecoded += seqBytesDecoded;
9087 if (elmtLen0 == INDEFINITE_LEN)
9088 {
9089 BDecEoc (b, bytesDecoded, env);
9090 return;
9091 }
9092 else if (seqBytesDecoded != elmtLen0)
9093 {
9094 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
9095 longjmp (env, -204);
9096 }
9097 else
9098 return;
9099 } // DigestedData::BDecContent
9100
9101 AsnLen DigestedData::BEnc (BUF_TYPE b)
9102 {
9103 AsnLen l;
9104 l = BEncContent (b);
9105 l += BEncConsLen (b, l);
9106 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9107 return l;
9108 }
9109
9110 void DigestedData::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
9111 {
9112 AsnTag tag;
9113 AsnLen elmtLen1;
9114
9115 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
9116 {
9117 Asn1Error << "DigestedData::BDec: ERROR - wrong tag" << endl;
9118 longjmp (env, -205);
9119 }
9120 elmtLen1 = BDecLen (b, bytesDecoded, env);
9121 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
9122 }
9123
9124 int DigestedData::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
9125 {
9126 bytesEncoded = BEnc (b);
9127 return !b.WriteError();
9128 }
9129
9130 int DigestedData::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
9131 {
9132 ENV_TYPE env;
9133 int val;
9134
9135 bytesDecoded = 0;
9136 if ((val = setjmp (env)) == 0)
9137 {
9138 BDec (b, bytesDecoded, env);
9139 return !b.ReadError();
9140 }
9141 else
9142 return false;
9143 }
9144
9145 void DigestedData::Print (ostream &os) const
9146 {
9147 #ifndef NDEBUG
9148 os << "{ -- SEQUENCE --" << endl;
9149 indentG += stdIndentG;
9150
9151 {
9152 Indent (os, indentG);
9153 os << "version ";
9154 os << version;
9155 os << "," << endl;
9156 }
9157
9158 if (NOT_NULL (digestAlgorithm))
9159 {
9160 Indent (os, indentG);
9161 os << "digestAlgorithm ";
9162 os << *digestAlgorithm;
9163 }
9164 else
9165 {
9166 Indent (os, indentG);
9167 os << "digestAlgorithm ";
9168 os << "-- void --";
9169 os << "," << endl;
9170 }
9171
9172 if (NOT_NULL (encapContentInfo))
9173 {
9174 Indent (os, indentG);
9175 os << "encapContentInfo ";
9176 os << *encapContentInfo;
9177 }
9178 else
9179 {
9180 Indent (os, indentG);
9181 os << "encapContentInfo ";
9182 os << "-- void --";
9183 os << "," << endl;
9184 }
9185
9186 {
9187 Indent (os, indentG);
9188 os << "digest ";
9189 os << digest;
9190 }
9191
9192 os << endl;
9193 indentG -= stdIndentG;
9194 Indent (os, indentG);
9195 os << "}";
9196 #endif /* NDEBUG */
9197 } // DigestedData::Print
9198
9199
9200 EncryptedData::EncryptedData()
9201 {
9202 #if TCL
9203 encryptedContentInfo = new EncryptedContentInfo;
9204 #else
9205 encryptedContentInfo = NULL; // incomplete initialization of mandatory element!
9206 #endif // TCL
9207 }
9208
9209 EncryptedData::EncryptedData (const EncryptedData &)
9210 {
9211 Asn1Error << "use of incompletely defined EncryptedData::EncryptedData (const EncryptedData &)" << endl;
9212 abort();
9213 }
9214
9215 EncryptedData::~EncryptedData()
9216 {
9217 delete encryptedContentInfo;
9218 }
9219
9220 AsnType *EncryptedData::Clone() const
9221 {
9222 return new EncryptedData;
9223 }
9224
9225 AsnType *EncryptedData::Copy() const
9226 {
9227 return new EncryptedData (*this);
9228 }
9229
9230 #if SNACC_DEEP_COPY
9231 EncryptedData &EncryptedData::operator = (const EncryptedData &that)
9232 #else // SNACC_DEEP_COPY
9233 EncryptedData &EncryptedData::operator = (const EncryptedData &)
9234 #endif // SNACC_DEEP_COPY
9235 {
9236 #if SNACC_DEEP_COPY
9237 if (this != &that)
9238 {
9239 version = that.version;
9240 if (that.encryptedContentInfo)
9241 {
9242 if (!encryptedContentInfo)
9243 encryptedContentInfo = new EncryptedContentInfo;
9244 *encryptedContentInfo = *that.encryptedContentInfo;
9245 }
9246 else
9247 {
9248 delete encryptedContentInfo;
9249 encryptedContentInfo = NULL;
9250 }
9251 }
9252
9253 return *this;
9254 #else // SNACC_DEEP_COPY
9255 Asn1Error << "use of incompletely defined EncryptedData &EncryptedData::operator = (const EncryptedData &)" << endl;
9256 abort();
9257 // if your compiler complains here, check the -novolat option
9258 #endif // SNACC_DEEP_COPY
9259 }
9260
9261 AsnLen
9262 EncryptedData::BEncContent (BUF_TYPE b)
9263 {
9264 AsnLen totalLen = 0;
9265 AsnLen l;
9266
9267 BEncEocIfNec (b);
9268 l = encryptedContentInfo->BEncContent (b);
9269 l += BEncConsLen (b, l);
9270
9271 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9272 totalLen += l;
9273
9274 l = version.BEncContent (b);
9275 BEncDefLenTo127 (b, l);
9276 l++;
9277
9278 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
9279 totalLen += l;
9280
9281 return totalLen;
9282 } // EncryptedData::BEncContent
9283
9284
9285 void EncryptedData::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
9286 {
9287 AsnTag tag1;
9288 AsnLen seqBytesDecoded = 0;
9289 AsnLen elmtLen1;
9290 tag1 = BDecTag (b, seqBytesDecoded, env);
9291
9292 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
9293 {
9294 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9295 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9296 tag1 = BDecTag (b, seqBytesDecoded, env);
9297 }
9298 else
9299 {
9300 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9301 longjmp (env, -206);
9302 }
9303
9304 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
9305 {
9306 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9307 encryptedContentInfo = new EncryptedContentInfo;
9308 encryptedContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9309 }
9310 else
9311 {
9312 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9313 longjmp (env, -207);
9314 }
9315
9316 bytesDecoded += seqBytesDecoded;
9317 if (elmtLen0 == INDEFINITE_LEN)
9318 {
9319 BDecEoc (b, bytesDecoded, env);
9320 return;
9321 }
9322 else if (seqBytesDecoded != elmtLen0)
9323 {
9324 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
9325 longjmp (env, -208);
9326 }
9327 else
9328 return;
9329 } // EncryptedData::BDecContent
9330
9331 AsnLen EncryptedData::BEnc (BUF_TYPE b)
9332 {
9333 AsnLen l;
9334 l = BEncContent (b);
9335 l += BEncConsLen (b, l);
9336 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9337 return l;
9338 }
9339
9340 void EncryptedData::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
9341 {
9342 AsnTag tag;
9343 AsnLen elmtLen1;
9344
9345 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
9346 {
9347 Asn1Error << "EncryptedData::BDec: ERROR - wrong tag" << endl;
9348 longjmp (env, -209);
9349 }
9350 elmtLen1 = BDecLen (b, bytesDecoded, env);
9351 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
9352 }
9353
9354 int EncryptedData::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
9355 {
9356 bytesEncoded = BEnc (b);
9357 return !b.WriteError();
9358 }
9359
9360 int EncryptedData::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
9361 {
9362 ENV_TYPE env;
9363 int val;
9364
9365 bytesDecoded = 0;
9366 if ((val = setjmp (env)) == 0)
9367 {
9368 BDec (b, bytesDecoded, env);
9369 return !b.ReadError();
9370 }
9371 else
9372 return false;
9373 }
9374
9375 void EncryptedData::Print (ostream &os) const
9376 {
9377 #ifndef NDEBUG
9378 os << "{ -- SEQUENCE --" << endl;
9379 indentG += stdIndentG;
9380
9381 {
9382 Indent (os, indentG);
9383 os << "version ";
9384 os << version;
9385 os << "," << endl;
9386 }
9387
9388 if (NOT_NULL (encryptedContentInfo))
9389 {
9390 Indent (os, indentG);
9391 os << "encryptedContentInfo ";
9392 os << *encryptedContentInfo;
9393 }
9394 else
9395 {
9396 Indent (os, indentG);
9397 os << "encryptedContentInfo ";
9398 os << "-- void --";
9399 os << endl;
9400 }
9401
9402 os << endl;
9403 indentG -= stdIndentG;
9404 Indent (os, indentG);
9405 os << "}";
9406 #endif /* NDEBUG */
9407 } // EncryptedData::Print
9408
9409
9410 AuthenticatedData::AuthenticatedData()
9411 {
9412 originatorInfo = NULL;
9413 #if TCL
9414 macAlgorithm = new MessageAuthenticationCodeAlgorithm;
9415 #else
9416 macAlgorithm = NULL; // incomplete initialization of mandatory element!
9417 #endif // TCL
9418 digestAlgorithm = NULL;
9419 #if TCL
9420 encapContentInfo = new EncapsulatedContentInfo;
9421 #else
9422 encapContentInfo = NULL; // incomplete initialization of mandatory element!
9423 #endif // TCL
9424 authenctiatedAttributes = NULL;
9425 unauthenticatedAttributes = NULL;
9426 }
9427
9428 AuthenticatedData::AuthenticatedData (const AuthenticatedData &)
9429 {
9430 Asn1Error << "use of incompletely defined AuthenticatedData::AuthenticatedData (const AuthenticatedData &)" << endl;
9431 abort();
9432 }
9433
9434 AuthenticatedData::~AuthenticatedData()
9435 {
9436 delete originatorInfo;
9437 delete macAlgorithm;
9438 delete digestAlgorithm;
9439 delete encapContentInfo;
9440 delete authenctiatedAttributes;
9441 delete unauthenticatedAttributes;
9442 }
9443
9444 AsnType *AuthenticatedData::Clone() const
9445 {
9446 return new AuthenticatedData;
9447 }
9448
9449 AsnType *AuthenticatedData::Copy() const
9450 {
9451 return new AuthenticatedData (*this);
9452 }
9453
9454 #if SNACC_DEEP_COPY
9455 AuthenticatedData &AuthenticatedData::operator = (const AuthenticatedData &that)
9456 #else // SNACC_DEEP_COPY
9457 AuthenticatedData &AuthenticatedData::operator = (const AuthenticatedData &)
9458 #endif // SNACC_DEEP_COPY
9459 {
9460 #if SNACC_DEEP_COPY
9461 if (this != &that)
9462 {
9463 version = that.version;
9464 if (that.originatorInfo)
9465 {
9466 if (!originatorInfo)
9467 originatorInfo = new OriginatorInfo;
9468 *originatorInfo = *that.originatorInfo;
9469 }
9470 else
9471 {
9472 delete originatorInfo;
9473 originatorInfo = NULL;
9474 }
9475 recipientInfos = that.recipientInfos;
9476 if (that.macAlgorithm)
9477 {
9478 if (!macAlgorithm)
9479 macAlgorithm = new MessageAuthenticationCodeAlgorithm;
9480 *macAlgorithm = *that.macAlgorithm;
9481 }
9482 else
9483 {
9484 delete macAlgorithm;
9485 macAlgorithm = NULL;
9486 }
9487 if (that.digestAlgorithm)
9488 {
9489 if (!digestAlgorithm)
9490 digestAlgorithm = new DigestAlgorithmIdentifier;
9491 *digestAlgorithm = *that.digestAlgorithm;
9492 }
9493 else
9494 {
9495 delete digestAlgorithm;
9496 digestAlgorithm = NULL;
9497 }
9498 if (that.encapContentInfo)
9499 {
9500 if (!encapContentInfo)
9501 encapContentInfo = new EncapsulatedContentInfo;
9502 *encapContentInfo = *that.encapContentInfo;
9503 }
9504 else
9505 {
9506 delete encapContentInfo;
9507 encapContentInfo = NULL;
9508 }
9509 if (that.authenctiatedAttributes)
9510 {
9511 if (!authenctiatedAttributes)
9512 authenctiatedAttributes = new Attributes;
9513 *authenctiatedAttributes = *that.authenctiatedAttributes;
9514 }
9515 else
9516 {
9517 delete authenctiatedAttributes;
9518 authenctiatedAttributes = NULL;
9519 }
9520 mac = that.mac;
9521 if (that.unauthenticatedAttributes)
9522 {
9523 if (!unauthenticatedAttributes)
9524 unauthenticatedAttributes = new Attributes;
9525 *unauthenticatedAttributes = *that.unauthenticatedAttributes;
9526 }
9527 else
9528 {
9529 delete unauthenticatedAttributes;
9530 unauthenticatedAttributes = NULL;
9531 }
9532 }
9533
9534 return *this;
9535 #else // SNACC_DEEP_COPY
9536 Asn1Error << "use of incompletely defined AuthenticatedData &AuthenticatedData::operator = (const AuthenticatedData &)" << endl;
9537 abort();
9538 // if your compiler complains here, check the -novolat option
9539 #endif // SNACC_DEEP_COPY
9540 }
9541
9542 AsnLen
9543 AuthenticatedData::BEncContent (BUF_TYPE b)
9544 {
9545 AsnLen totalLen = 0;
9546 AsnLen l;
9547
9548 if (NOT_NULL (unauthenticatedAttributes))
9549 {
9550 BEncEocIfNec (b);
9551 l = unauthenticatedAttributes->BEncContent (b);
9552 l += BEncConsLen (b, l);
9553
9554 l += BEncTag1 (b, CNTX, CONS, 3);
9555 totalLen += l;
9556 }
9557
9558 l = mac.BEncContent (b);
9559 l += BEncDefLen (b, l);
9560
9561 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
9562 totalLen += l;
9563
9564 if (NOT_NULL (authenctiatedAttributes))
9565 {
9566 BEncEocIfNec (b);
9567 l = authenctiatedAttributes->BEncContent (b);
9568 l += BEncConsLen (b, l);
9569
9570 l += BEncTag1 (b, CNTX, CONS, 2);
9571 totalLen += l;
9572 }
9573
9574 BEncEocIfNec (b);
9575 l = encapContentInfo->BEncContent (b);
9576 l += BEncConsLen (b, l);
9577
9578 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9579 totalLen += l;
9580
9581 if (NOT_NULL (digestAlgorithm))
9582 {
9583 BEncEocIfNec (b);
9584 l = digestAlgorithm->BEncContent (b);
9585 l += BEncConsLen (b, l);
9586
9587 l += BEncTag1 (b, CNTX, CONS, 1);
9588 totalLen += l;
9589 }
9590
9591 BEncEocIfNec (b);
9592 l = macAlgorithm->BEncContent (b);
9593 l += BEncConsLen (b, l);
9594
9595 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9596 totalLen += l;
9597
9598 BEncEocIfNec (b);
9599 l = recipientInfos.BEncContent (b);
9600 l += BEncConsLen (b, l);
9601
9602 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
9603 totalLen += l;
9604
9605 if (NOT_NULL (originatorInfo))
9606 {
9607 BEncEocIfNec (b);
9608 l = originatorInfo->BEncContent (b);
9609 l += BEncConsLen (b, l);
9610
9611 l += BEncTag1 (b, CNTX, CONS, 0);
9612 totalLen += l;
9613 }
9614
9615 l = version.BEncContent (b);
9616 BEncDefLenTo127 (b, l);
9617 l++;
9618
9619 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
9620 totalLen += l;
9621
9622 return totalLen;
9623 } // AuthenticatedData::BEncContent
9624
9625
9626 void AuthenticatedData::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
9627 {
9628 AsnTag tag1;
9629 AsnLen seqBytesDecoded = 0;
9630 AsnLen elmtLen1;
9631 tag1 = BDecTag (b, seqBytesDecoded, env);
9632
9633 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
9634 {
9635 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9636 version.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9637 tag1 = BDecTag (b, seqBytesDecoded, env);
9638 }
9639 else
9640 {
9641 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9642 longjmp (env, -210);
9643 }
9644
9645 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0)))
9646 {
9647 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9648 originatorInfo = new OriginatorInfo;
9649 originatorInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9650 tag1 = BDecTag (b, seqBytesDecoded, env);
9651 }
9652
9653 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE)))
9654 {
9655 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9656 recipientInfos.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9657 tag1 = BDecTag (b, seqBytesDecoded, env);
9658 }
9659 else
9660 {
9661 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9662 longjmp (env, -211);
9663 }
9664
9665 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
9666 {
9667 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9668 macAlgorithm = new MessageAuthenticationCodeAlgorithm;
9669 macAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9670 tag1 = BDecTag (b, seqBytesDecoded, env);
9671 }
9672 else
9673 {
9674 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9675 longjmp (env, -212);
9676 }
9677
9678 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1)))
9679 {
9680 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9681 digestAlgorithm = new DigestAlgorithmIdentifier;
9682 digestAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9683 tag1 = BDecTag (b, seqBytesDecoded, env);
9684 }
9685
9686 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
9687 {
9688 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9689 encapContentInfo = new EncapsulatedContentInfo;
9690 encapContentInfo->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9691 tag1 = BDecTag (b, seqBytesDecoded, env);
9692 }
9693 else
9694 {
9695 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9696 longjmp (env, -213);
9697 }
9698
9699 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 2)))
9700 {
9701 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9702 authenctiatedAttributes = new Attributes;
9703 authenctiatedAttributes->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9704 tag1 = BDecTag (b, seqBytesDecoded, env);
9705 }
9706
9707 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
9708 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
9709 {
9710 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9711 mac.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9712 if (seqBytesDecoded == elmtLen0)
9713 {
9714 bytesDecoded += seqBytesDecoded;
9715 return;
9716 }
9717 else
9718 {
9719 tag1 = BDecTag (b, seqBytesDecoded, env);
9720
9721 if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))
9722 {
9723 BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)
9724 bytesDecoded += seqBytesDecoded;
9725 return;
9726 }
9727 }
9728 }
9729 else
9730 {
9731 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
9732 longjmp (env, -214);
9733 }
9734
9735 if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 3)))
9736 {
9737 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
9738 unauthenticatedAttributes = new Attributes;
9739 unauthenticatedAttributes->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
9740 }
9741
9742 bytesDecoded += seqBytesDecoded;
9743 if (elmtLen0 == INDEFINITE_LEN)
9744 {
9745 BDecEoc (b, bytesDecoded, env);
9746 return;
9747 }
9748 else if (seqBytesDecoded != elmtLen0)
9749 {
9750 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
9751 longjmp (env, -215);
9752 }
9753 else
9754 return;
9755 } // AuthenticatedData::BDecContent
9756
9757 AsnLen AuthenticatedData::BEnc (BUF_TYPE b)
9758 {
9759 AsnLen l;
9760 l = BEncContent (b);
9761 l += BEncConsLen (b, l);
9762 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
9763 return l;
9764 }
9765
9766 void AuthenticatedData::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
9767 {
9768 AsnTag tag;
9769 AsnLen elmtLen1;
9770
9771 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
9772 {
9773 Asn1Error << "AuthenticatedData::BDec: ERROR - wrong tag" << endl;
9774 longjmp (env, -216);
9775 }
9776 elmtLen1 = BDecLen (b, bytesDecoded, env);
9777 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
9778 }
9779
9780 int AuthenticatedData::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
9781 {
9782 bytesEncoded = BEnc (b);
9783 return !b.WriteError();
9784 }
9785
9786 int AuthenticatedData::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
9787 {
9788 ENV_TYPE env;
9789 int val;
9790
9791 bytesDecoded = 0;
9792 if ((val = setjmp (env)) == 0)
9793 {
9794 BDec (b, bytesDecoded, env);
9795 return !b.ReadError();
9796 }
9797 else
9798 return false;
9799 }
9800
9801 void AuthenticatedData::Print (ostream &os) const
9802 {
9803 #ifndef NDEBUG
9804 os << "{ -- SEQUENCE --" << endl;
9805 indentG += stdIndentG;
9806
9807 {
9808 Indent (os, indentG);
9809 os << "version ";
9810 os << version;
9811 os << "," << endl;
9812 }
9813
9814 if (NOT_NULL (originatorInfo))
9815 {
9816 Indent (os, indentG);
9817 os << "originatorInfo ";
9818 os << *originatorInfo;
9819 }
9820 else
9821 {
9822 Indent (os, indentG);
9823 os << "originatorInfo ";
9824 os << "-- void --";
9825 os << "," << endl;
9826 }
9827
9828 {
9829 Indent (os, indentG);
9830 os << "recipientInfos ";
9831 os << recipientInfos;
9832 os << "," << endl;
9833 }
9834
9835 if (NOT_NULL (macAlgorithm))
9836 {
9837 Indent (os, indentG);
9838 os << "macAlgorithm ";
9839 os << *macAlgorithm;
9840 }
9841 else
9842 {
9843 Indent (os, indentG);
9844 os << "macAlgorithm ";
9845 os << "-- void --";
9846 os << "," << endl;
9847 }
9848
9849 if (NOT_NULL (digestAlgorithm))
9850 {
9851 Indent (os, indentG);
9852 os << "digestAlgorithm ";
9853 os << *digestAlgorithm;
9854 }
9855 else
9856 {
9857 Indent (os, indentG);
9858 os << "digestAlgorithm ";
9859 os << "-- void --";
9860 os << "," << endl;
9861 }
9862
9863 if (NOT_NULL (encapContentInfo))
9864 {
9865 Indent (os, indentG);
9866 os << "encapContentInfo ";
9867 os << *encapContentInfo;
9868 }
9869 else
9870 {
9871 Indent (os, indentG);
9872 os << "encapContentInfo ";
9873 os << "-- void --";
9874 os << "," << endl;
9875 }
9876
9877 if (NOT_NULL (authenctiatedAttributes))
9878 {
9879 Indent (os, indentG);
9880 os << "authenctiatedAttributes ";
9881 os << *authenctiatedAttributes;
9882 }
9883 else
9884 {
9885 Indent (os, indentG);
9886 os << "authenctiatedAttributes ";
9887 os << "-- void --";
9888 os << "," << endl;
9889 }
9890
9891 {
9892 Indent (os, indentG);
9893 os << "mac ";
9894 os << mac;
9895 os << "," << endl;
9896 }
9897
9898 if (NOT_NULL (unauthenticatedAttributes))
9899 {
9900 os << ","<< endl;
9901 Indent (os, indentG);
9902 os << "unauthenticatedAttributes ";
9903 os << *unauthenticatedAttributes;
9904 }
9905 else
9906 {
9907 Indent (os, indentG);
9908 os << "unauthenticatedAttributes ";
9909 os << "-- void --";
9910 os << endl;
9911 }
9912
9913 os << endl;
9914 indentG -= stdIndentG;
9915 Indent (os, indentG);
9916 os << "}";
9917 #endif /* NDEBUG */
9918 } // AuthenticatedData::Print
9919
9920
9921 AsnType *UserKeyingMaterials::Clone() const
9922 {
9923 return new UserKeyingMaterials;
9924 }
9925
9926 AsnType *UserKeyingMaterials::Copy() const
9927 {
9928 return new UserKeyingMaterials (*this);
9929 }
9930
9931 AsnLen UserKeyingMaterials::BEnc (BUF_TYPE b)
9932 {
9933 AsnLen l;
9934 l = BEncContent (b);
9935 l += BEncConsLen (b, l);
9936 l += BEncTag1 (b, UNIV, CONS, SET_TAG_CODE);
9937 return l;
9938 }
9939
9940 void UserKeyingMaterials::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
9941 {
9942 AsnTag tag;
9943 AsnLen elmtLen1;
9944
9945 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))
9946 {
9947 Asn1Error << "UserKeyingMaterials::BDec: ERROR - wrong tag" << endl;
9948 longjmp (env, -217);
9949 }
9950 elmtLen1 = BDecLen (b, bytesDecoded, env);
9951 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
9952 }
9953
9954 UserKeyingMaterials::UserKeyingMaterials (const UserKeyingMaterials &)
9955 {
9956 Asn1Error << "use of incompletely defined UserKeyingMaterials::UserKeyingMaterials (const UserKeyingMaterials &)" << endl;
9957 abort();
9958 }
9959
9960 UserKeyingMaterials::~UserKeyingMaterials()
9961 {
9962 SetCurrToFirst();
9963 for (; Curr() != NULL; RemoveCurrFromList())
9964 ;
9965 } // end of destructor
9966
9967 #if SNACC_DEEP_COPY
9968 UserKeyingMaterials &UserKeyingMaterials::operator = (const UserKeyingMaterials &that)
9969 #else // SNACC_DEEP_COPY
9970 UserKeyingMaterials &UserKeyingMaterials::operator = (const UserKeyingMaterials &)
9971 #endif // SNACC_DEEP_COPY
9972 {
9973 #if SNACC_DEEP_COPY
9974 if (this != &that)
9975 {
9976 SetCurrToFirst();
9977 for (; Curr(); RemoveCurrFromList())
9978 ;
9979
9980 //that.SetCurrToFirst();
9981 //for (; that.Curr(); that.GoNext())
9982 // AppendCopy (*that.Curr());
9983 for (const AsnListElmt *run=that.first; run; run=run->next)
9984 AppendCopy (*run->elmt);
9985 }
9986
9987 return *this;
9988 #else // SNACC_DEEP_COPY
9989 Asn1Error << "use of incompletely defined UserKeyingMaterials &UserKeyingMaterials::operator = (const UserKeyingMaterials &)" << endl;
9990 abort();
9991 // if your compiler complains here, check the -novolat option
9992 #endif // SNACC_DEEP_COPY
9993 }
9994
9995 void UserKeyingMaterials::Print (ostream &os) const
9996 {
9997 #ifndef NDEBUG
9998 os << "{ -- SEQUENCE/SET OF -- " << endl;
9999 indentG += stdIndentG;
10000 //SetCurrToFirst();
10001 //for (; Curr() != NULL; GoNext())
10002 for (const AsnListElmt *run=first; run; run=run->next)
10003 {
10004 Indent (os, indentG);
10005 //os << *Curr();
10006 os << *run->elmt;
10007 //if (Curr() != Last())
10008 if (run != last)
10009 os << ",";
10010 os << endl;
10011 }
10012 indentG -= stdIndentG;
10013 Indent (os, indentG);
10014 os << "}\n";
10015 #endif /* NDEBUG */
10016
10017
10018 } // Print
10019
10020
10021 void UserKeyingMaterials::SetCurrElmt (unsigned long int index)
10022 {
10023 unsigned long int i;
10024 curr = first;
10025 if (count)
10026 for (i = 0; (i < (count-1)) && (i < index); i++)
10027 curr = curr->next;
10028 } // UserKeyingMaterials::SetCurrElmt
10029
10030
10031 unsigned long int UserKeyingMaterials::GetCurrElmtIndex()
10032 {
10033 unsigned long int i;
10034 AsnListElmt *tmp;
10035 if (curr != NULL)
10036 {
10037 for (i = 0, tmp = first; tmp != NULL; i++)
10038 {
10039 if (tmp == curr)
10040 return i;
10041 else
10042 tmp = tmp->next;
10043 }
10044 }
10045 return count;
10046 } // UserKeyingMaterials::GetCurrElmtIndex
10047
10048
10049 // alloc new list elmt, put at end of list
10050 // and return the component type
10051 UserKeyingMaterial *UserKeyingMaterials::Append()
10052 {
10053 AsnListElmt *newElmt;
10054 newElmt = new AsnListElmt;
10055 newElmt->elmt = new UserKeyingMaterial;
10056 newElmt->next = NULL;
10057 if (last == NULL)
10058 {
10059 newElmt->prev = NULL;
10060 first = last = newElmt;
10061 }
10062 else
10063 {
10064 newElmt->prev = last;
10065 last->next = newElmt;
10066 last = newElmt;
10067 }
10068 count++;
10069 return (curr = newElmt)->elmt;
10070 } // UserKeyingMaterials::Append
10071
10072
10073 // alloc new list elmt, put at begining of list
10074 // and return the component type
10075 UserKeyingMaterial *UserKeyingMaterials::Prepend()
10076 {
10077 AsnListElmt *newElmt;
10078 newElmt = new AsnListElmt;
10079 newElmt->elmt = new UserKeyingMaterial;
10080 newElmt->prev = NULL;
10081 if (first == NULL)
10082 {
10083 newElmt->next = NULL;
10084 first = last = newElmt;
10085 }
10086 else
10087 {
10088 newElmt->next = first;
10089 first->prev = newElmt;
10090 first = newElmt;
10091 }
10092 count++;
10093 return (curr = newElmt)->elmt;
10094 } // UserKeyingMaterials::Prepend
10095
10096
10097 // alloc new list elmt, insert it before the
10098 // current element and return the component type
10099 // if the current element is null, the new element
10100 // is placed at the beginning of the list.
10101 UserKeyingMaterial *UserKeyingMaterials::InsertBefore()
10102 {
10103 AsnListElmt *newElmt;
10104 newElmt = new AsnListElmt;
10105 newElmt->elmt = new UserKeyingMaterial;
10106 if (curr == NULL)
10107 {
10108 newElmt->next = first;
10109 newElmt->prev = NULL;
10110 first = newElmt;
10111 if (last == NULL)
10112 last = newElmt;
10113 }
10114 else
10115 {
10116 newElmt->next = curr;
10117 newElmt->prev = curr->prev;
10118 curr->prev = newElmt;
10119 if (curr == first)
10120 first = newElmt;
10121 else
10122 newElmt->prev->next = newElmt;
10123 }
10124 count++;
10125 return (curr = newElmt)->elmt;
10126 } // UserKeyingMaterials::InsertBefore
10127
10128
10129 // alloc new list elmt, insert it after the
10130 // current element and return the component type
10131 // if the current element is null, the new element
10132 // is placed at the end of the list.
10133 UserKeyingMaterial *UserKeyingMaterials::InsertAfter()
10134 {
10135 AsnListElmt *newElmt;
10136 newElmt = new AsnListElmt;
10137 newElmt->elmt = new UserKeyingMaterial;
10138 if (curr == NULL)
10139 {
10140 newElmt->prev = last;
10141 newElmt->next = NULL;
10142 last = newElmt;
10143 if (first == NULL)
10144 first = newElmt;
10145 }
10146 else
10147 {
10148 newElmt->prev = curr;
10149 newElmt->next = curr->next;
10150 curr->next = newElmt;
10151 if (curr == last)
10152 last = newElmt;
10153 else
10154 newElmt->next->prev = newElmt;
10155 }
10156 count++;
10157 return (curr = newElmt)->elmt;
10158 } // UserKeyingMaterials::InsertAfter
10159
10160
10161 UserKeyingMaterials &UserKeyingMaterials::AppendCopy (UserKeyingMaterial &elmt)
10162 {
10163 AsnListElmt *newElmt;
10164 newElmt = new AsnListElmt;
10165 newElmt->elmt = new UserKeyingMaterial;
10166 *newElmt->elmt = elmt;
10167 newElmt->next = NULL;
10168 if (last == NULL)
10169 {
10170 newElmt->prev = NULL;
10171 first = last = newElmt;
10172 }
10173 else
10174 {
10175 newElmt->prev = last;
10176 last->next = newElmt;
10177 last = newElmt;
10178 }
10179 count++;
10180 return *this;
10181 } // AppendCopy
10182
10183
10184 UserKeyingMaterials &UserKeyingMaterials::PrependCopy (UserKeyingMaterial &elmt)
10185 {
10186 AsnListElmt *newElmt;
10187 newElmt = new AsnListElmt;
10188 newElmt->elmt = new UserKeyingMaterial;
10189 *newElmt->elmt = elmt;
10190 newElmt->prev = NULL;
10191 if (first == NULL)
10192 {
10193 newElmt->next = NULL;
10194 first = last = newElmt;
10195 }
10196 else
10197 {
10198 newElmt->next = first;
10199 first->prev = newElmt;
10200 first = newElmt;
10201 }
10202 count++;
10203 return *this;
10204 } // UserKeyingMaterials::PrependCopy
10205
10206
10207 // alloc new list elmt, insert it before the
10208 // current element, copy the given elmt into the new elmt
10209 // and return the component type.
10210 // if the current element is null, the new element
10211 // is placed at the beginning of the list.
10212 UserKeyingMaterials &UserKeyingMaterials::InsertBeforeAndCopy (UserKeyingMaterial &elmt)
10213 {
10214 AsnListElmt *newElmt;
10215
10216 newElmt = new AsnListElmt;
10217 newElmt->elmt = new UserKeyingMaterial;
10218 *newElmt->elmt = elmt;
10219
10220 if (curr == NULL)
10221 {
10222 newElmt->next = first;
10223 newElmt->prev = NULL;
10224 first = newElmt;
10225 if (last == NULL)
10226 last = newElmt;
10227 }
10228 else
10229 {
10230 newElmt->next = curr;
10231 newElmt->prev = curr->prev;
10232 curr->prev = newElmt;
10233 if (curr == first)
10234 first = newElmt;
10235 else
10236 newElmt->prev->next = newElmt;
10237 }
10238 count++;
10239 return *this;
10240 } // UserKeyingMaterials::InsertBeforeAndCopy
10241
10242
10243 // alloc new list elmt, insert it after the
10244 // current element, copy given elmt in to new elmt
10245 // and return the component type
10246 // if the current element is null, the new element
10247 // is placed at the end of the list.
10248 UserKeyingMaterials &UserKeyingMaterials::InsertAfterAndCopy (UserKeyingMaterial &elmt)
10249 {
10250 AsnListElmt *newElmt;
10251
10252 newElmt = new AsnListElmt;
10253 newElmt->elmt = new UserKeyingMaterial;
10254 *newElmt->elmt = elmt;
10255 if (curr == NULL)
10256 {
10257 newElmt->prev = last;
10258 newElmt->next = NULL;
10259 last = newElmt;
10260 if (first == NULL)
10261 first = newElmt;
10262 }
10263 else
10264 {
10265 newElmt->prev = curr;
10266 newElmt->next = curr->next;
10267 curr->next = newElmt;
10268 if (curr == last)
10269 last = newElmt;
10270 else
10271 newElmt->next->prev = newElmt;
10272 }
10273 count++;
10274 return *this;
10275 } // UserKeyingMaterials::InsertAfterAndCopy
10276
10277
10278 // remove current element from list if current element is not NULL
10279 // The new current element will be the next element.
10280 // If the current element is the last element in the list
10281 // the second but last element will become the new current element.
10282 void UserKeyingMaterials::RemoveCurrFromList()
10283 {
10284 AsnListElmt *del_elmt;
10285
10286 if (curr != NULL)
10287 {
10288 del_elmt = curr;
10289 count--;
10290
10291 if (count == 0)
10292 first = last = curr = NULL;
10293 else if (curr == first)
10294 {
10295 curr = first= first->next;
10296 first->prev = NULL;
10297 }
10298 else if (curr == last)
10299 {
10300 curr = last = last->prev;
10301 last->next = NULL;
10302 }
10303 else
10304 {
10305 curr->prev->next = curr->next;
10306 curr->next->prev = curr->prev;
10307 }
10308
10309 delete del_elmt->elmt;
10310 delete del_elmt;
10311 }
10312 }
10313
10314
10315 AsnLen UserKeyingMaterials::BEncContent (BUF_TYPE b)
10316 {
10317 AsnListElmt *currElmt;
10318 AsnLen elmtLen;
10319 AsnLen totalLen = 0;
10320 {
10321 int iii,icount;
10322 CSM_Buffer **tmpEnc=NULL;
10323 for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);
10324 tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);
10325 for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)
10326 {
10327 ENCODE_BUF1(currElmt->elmt->BEncContent, elmtLen);
10328 elmtLen += BEncDefLen (outputBuf, elmtLen);
10329
10330 elmtLen += BEncTag1 (outputBuf, UNIV, PRIM, OCTETSTRING_TAG_CODE);
10331 ENCODE_BUF2(tmpEnc[iii]);
10332 }
10333 vdasnacc_sortSetOf(tmpEnc, icount);
10334 for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())
10335 SM_WriteToAsnBuf(tmpEnc[iii], b);
10336 for (iii=0; iii < icount; iii++) delete tmpEnc[iii];
10337 free(tmpEnc);
10338 }
10339 totalLen += elmtLen;
10340 return totalLen;
10341 } // UserKeyingMaterials::BEncContent
10342
10343
10344 void UserKeyingMaterials::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0,
10345 AsnLen &bytesDecoded, ENV_TYPE env)
10346 {
10347 UserKeyingMaterial *listElmt;
10348 AsnTag tag1;
10349 AsnLen listBytesDecoded = 0;
10350 AsnLen elmtLen1;
10351
10352 while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))
10353 {
10354 tag1 = BDecTag (b, listBytesDecoded, env);
10355 if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))
10356 {
10357 BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);
10358 break;
10359 }
10360 if ((tag1 != MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
10361 && (tag1 != MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
10362 {
10363 Asn1Error << "Unexpected Tag" << endl;
10364 longjmp (env, -218);
10365 }
10366
10367 elmtLen1 = BDecLen (b, listBytesDecoded, env);
10368 listElmt = Append();
10369 listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env);
10370 }
10371
10372 bytesDecoded += listBytesDecoded;
10373 } // UserKeyingMaterials::BDecContent
10374
10375
10376 RC2CBCParameter::RC2CBCParameter()
10377 {
10378 }
10379
10380 RC2CBCParameter::RC2CBCParameter (const RC2CBCParameter &)
10381 {
10382 Asn1Error << "use of incompletely defined RC2CBCParameter::RC2CBCParameter (const RC2CBCParameter &)" << endl;
10383 abort();
10384 }
10385
10386 RC2CBCParameter::~RC2CBCParameter()
10387 {
10388 }
10389
10390 AsnType *RC2CBCParameter::Clone() const
10391 {
10392 return new RC2CBCParameter;
10393 }
10394
10395 AsnType *RC2CBCParameter::Copy() const
10396 {
10397 return new RC2CBCParameter (*this);
10398 }
10399
10400 #if SNACC_DEEP_COPY
10401 RC2CBCParameter &RC2CBCParameter::operator = (const RC2CBCParameter &that)
10402 #else // SNACC_DEEP_COPY
10403 RC2CBCParameter &RC2CBCParameter::operator = (const RC2CBCParameter &)
10404 #endif // SNACC_DEEP_COPY
10405 {
10406 #if SNACC_DEEP_COPY
10407 if (this != &that)
10408 {
10409 rc2ParameterVersion = that.rc2ParameterVersion;
10410 iv = that.iv;
10411 }
10412
10413 return *this;
10414 #else // SNACC_DEEP_COPY
10415 Asn1Error << "use of incompletely defined RC2CBCParameter &RC2CBCParameter::operator = (const RC2CBCParameter &)" << endl;
10416 abort();
10417 // if your compiler complains here, check the -novolat option
10418 #endif // SNACC_DEEP_COPY
10419 }
10420
10421 AsnLen
10422 RC2CBCParameter::BEncContent (BUF_TYPE b)
10423 {
10424 AsnLen totalLen = 0;
10425 AsnLen l;
10426
10427 l = iv.BEncContent (b);
10428 l += BEncDefLen (b, l);
10429
10430 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
10431 totalLen += l;
10432
10433 l = rc2ParameterVersion.BEncContent (b);
10434 BEncDefLenTo127 (b, l);
10435 l++;
10436
10437 l += BEncTag1 (b, UNIV, PRIM, INTEGER_TAG_CODE);
10438 totalLen += l;
10439
10440 return totalLen;
10441 } // RC2CBCParameter::BEncContent
10442
10443
10444 void RC2CBCParameter::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
10445 {
10446 AsnTag tag1;
10447 AsnLen seqBytesDecoded = 0;
10448 AsnLen elmtLen1;
10449 tag1 = BDecTag (b, seqBytesDecoded, env);
10450
10451 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))
10452 {
10453 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
10454 rc2ParameterVersion.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
10455 tag1 = BDecTag (b, seqBytesDecoded, env);
10456 }
10457 else
10458 {
10459 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
10460 longjmp (env, -219);
10461 }
10462
10463 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
10464 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
10465 {
10466 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
10467 iv.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
10468 }
10469 else
10470 {
10471 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
10472 longjmp (env, -220);
10473 }
10474
10475 bytesDecoded += seqBytesDecoded;
10476 if (elmtLen0 == INDEFINITE_LEN)
10477 {
10478 BDecEoc (b, bytesDecoded, env);
10479 return;
10480 }
10481 else if (seqBytesDecoded != elmtLen0)
10482 {
10483 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
10484 longjmp (env, -221);
10485 }
10486 else
10487 return;
10488 } // RC2CBCParameter::BDecContent
10489
10490 AsnLen RC2CBCParameter::BEnc (BUF_TYPE b)
10491 {
10492 AsnLen l;
10493 l = BEncContent (b);
10494 l += BEncConsLen (b, l);
10495 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
10496 return l;
10497 }
10498
10499 void RC2CBCParameter::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
10500 {
10501 AsnTag tag;
10502 AsnLen elmtLen1;
10503
10504 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
10505 {
10506 Asn1Error << "RC2CBCParameter::BDec: ERROR - wrong tag" << endl;
10507 longjmp (env, -222);
10508 }
10509 elmtLen1 = BDecLen (b, bytesDecoded, env);
10510 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
10511 }
10512
10513 int RC2CBCParameter::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
10514 {
10515 bytesEncoded = BEnc (b);
10516 return !b.WriteError();
10517 }
10518
10519 int RC2CBCParameter::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
10520 {
10521 ENV_TYPE env;
10522 int val;
10523
10524 bytesDecoded = 0;
10525 if ((val = setjmp (env)) == 0)
10526 {
10527 BDec (b, bytesDecoded, env);
10528 return !b.ReadError();
10529 }
10530 else
10531 return false;
10532 }
10533
10534 void RC2CBCParameter::Print (ostream &os) const
10535 {
10536 #ifndef NDEBUG
10537 os << "{ -- SEQUENCE --" << endl;
10538 indentG += stdIndentG;
10539
10540 {
10541 Indent (os, indentG);
10542 os << "rc2ParameterVersion ";
10543 os << rc2ParameterVersion;
10544 os << "," << endl;
10545 }
10546
10547 {
10548 Indent (os, indentG);
10549 os << "iv ";
10550 os << iv;
10551 }
10552
10553 os << endl;
10554 indentG -= stdIndentG;
10555 Indent (os, indentG);
10556 os << "}";
10557 #endif /* NDEBUG */
10558 } // RC2CBCParameter::Print
10559
10560
10561 ExtendedCertificateOrCertificate::ExtendedCertificateOrCertificate()
10562 {
10563 choiceId = certificateCid;
10564 #if TCL
10565 certificate = new Certificate;
10566 #else
10567 certificate = NULL; // incomplete initialization of mandatory element!
10568 #endif // TCL
10569 }
10570
10571 ExtendedCertificateOrCertificate::ExtendedCertificateOrCertificate (const ExtendedCertificateOrCertificate &)
10572 {
10573 Asn1Error << "use of incompletely defined ExtendedCertificateOrCertificate::ExtendedCertificateOrCertificate (const ExtendedCertificateOrCertificate &)" << endl;
10574 abort();
10575 }
10576
10577 ExtendedCertificateOrCertificate::~ExtendedCertificateOrCertificate()
10578 {
10579 switch (choiceId)
10580 {
10581 case certificateCid:
10582 delete certificate;
10583 break;
10584 case extendedCertificateCid:
10585 delete extendedCertificate;
10586 break;
10587 } // end of switch
10588 } // end of destructor
10589
10590 AsnType *ExtendedCertificateOrCertificate::Clone() const
10591 {
10592 return new ExtendedCertificateOrCertificate;
10593 }
10594
10595 AsnType *ExtendedCertificateOrCertificate::Copy() const
10596 {
10597 return new ExtendedCertificateOrCertificate (*this);
10598 }
10599
10600 #if SNACC_DEEP_COPY
10601 ExtendedCertificateOrCertificate &ExtendedCertificateOrCertificate::operator = (const ExtendedCertificateOrCertificate &that)
10602 #else // SNACC_DEEP_COPY
10603 ExtendedCertificateOrCertificate &ExtendedCertificateOrCertificate::operator = (const ExtendedCertificateOrCertificate &)
10604 #endif // SNACC_DEEP_COPY
10605 {
10606 #if SNACC_DEEP_COPY
10607 if (this != &that)
10608 {
10609 switch (choiceId)
10610 {
10611 case certificateCid:
10612 delete certificate;
10613 break;
10614 case extendedCertificateCid:
10615 delete extendedCertificate;
10616 break;
10617 }
10618 switch (choiceId = that.choiceId)
10619 {
10620 case certificateCid:
10621 certificate = new Certificate;
10622 *certificate = *that.certificate;
10623 break;
10624 case extendedCertificateCid:
10625 extendedCertificate = new ExtendedCertificate;
10626 *extendedCertificate = *that.extendedCertificate;
10627 break;
10628 }
10629 }
10630
10631 return *this;
10632 #else // SNACC_DEEP_COPY
10633 Asn1Error << "use of incompletely defined ExtendedCertificateOrCertificate &ExtendedCertificateOrCertificate::operator = (const ExtendedCertificateOrCertificate &)" << endl;
10634 abort();
10635 // if your compiler complains here, check the -novolat option
10636 #endif // SNACC_DEEP_COPY
10637 }
10638
10639 AsnLen
10640 ExtendedCertificateOrCertificate::BEncContent (BUF_TYPE b)
10641 {
10642 AsnLen l;
10643 switch (choiceId)
10644 {
10645 case certificateCid:
10646 BEncEocIfNec (b);
10647 l = certificate->BEncContent (b);
10648 l += BEncConsLen (b, l);
10649
10650 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
10651 break;
10652
10653 case extendedCertificateCid:
10654 BEncEocIfNec (b);
10655 l = extendedCertificate->BEncContent (b);
10656 l += BEncConsLen (b, l);
10657
10658 l += BEncTag1 (b, CNTX, CONS, 0);
10659 break;
10660
10661 } // end switch
10662 return l;
10663 } // ExtendedCertificateOrCertificate::BEncContent
10664
10665
10666 void ExtendedCertificateOrCertificate::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
10667 {
10668 switch (tag)
10669 {
10670 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE):
10671 choiceId = certificateCid;
10672 certificate = new Certificate;
10673 certificate->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
10674 break;
10675
10676 case MAKE_TAG_ID (CNTX, CONS, 0):
10677 choiceId = extendedCertificateCid;
10678 extendedCertificate = new ExtendedCertificate;
10679 extendedCertificate->BDecContent (b, tag, elmtLen0, bytesDecoded, env);
10680 break;
10681
10682 default:
10683 Asn1Error << "ERROR - unexpected tag in CHOICE" << endl;
10684 longjmp (env, -223);
10685 break;
10686 } // end switch
10687 } // ExtendedCertificateOrCertificate::BDecContent
10688
10689
10690 AsnLen ExtendedCertificateOrCertificate::BEnc (BUF_TYPE b)
10691 {
10692 AsnLen l;
10693 l = BEncContent (b);
10694 return l;
10695 }
10696
10697 void ExtendedCertificateOrCertificate::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
10698 {
10699 AsnLen elmtLen;
10700 AsnTag tag;
10701
10702 /* CHOICEs are a special case - grab identifying tag */
10703 /* this allows easier handling of nested CHOICEs */
10704 tag = BDecTag (b, bytesDecoded, env);
10705 elmtLen = BDecLen (b, bytesDecoded, env);
10706 BDecContent (b, tag, elmtLen, bytesDecoded, env);
10707 }
10708
10709 int ExtendedCertificateOrCertificate::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
10710 {
10711 bytesEncoded = BEnc (b);
10712 return !b.WriteError();
10713 }
10714
10715 int ExtendedCertificateOrCertificate::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
10716 {
10717 ENV_TYPE env;
10718 int val;
10719
10720 bytesDecoded = 0;
10721 if ((val = setjmp (env)) == 0)
10722 {
10723 BDec (b, bytesDecoded, env);
10724 return !b.ReadError();
10725 }
10726 else
10727 return false;
10728 }
10729
10730 void ExtendedCertificateOrCertificate::Print (ostream &os) const
10731 {
10732 #ifndef NDEBUG
10733 switch (choiceId)
10734 {
10735 case certificateCid:
10736 os << "certificate ";
10737 if (certificate)
10738 os << *certificate;
10739 else
10740 os << "-- void3 --\n";
10741 break;
10742
10743 case extendedCertificateCid:
10744 os << "extendedCertificate ";
10745 if (extendedCertificate)
10746 os << *extendedCertificate;
10747 else
10748 os << "-- void3 --\n";
10749 break;
10750
10751 } // end of switch
10752 #endif /* NDEBUG */
10753 } // ExtendedCertificateOrCertificate::Print
10754
10755 DigestInfo::DigestInfo()
10756 {
10757 #if TCL
10758 digestAlgorithm = new DigestAlgorithmIdentifier;
10759 #else
10760 digestAlgorithm = NULL; // incomplete initialization of mandatory element!
10761 #endif // TCL
10762 }
10763
10764 DigestInfo::DigestInfo (const DigestInfo &)
10765 {
10766 Asn1Error << "use of incompletely defined DigestInfo::DigestInfo (const DigestInfo &)" << endl;
10767 abort();
10768 }
10769
10770 DigestInfo::~DigestInfo()
10771 {
10772 delete digestAlgorithm;
10773 }
10774
10775 AsnType *DigestInfo::Clone() const
10776 {
10777 return new DigestInfo;
10778 }
10779
10780 AsnType *DigestInfo::Copy() const
10781 {
10782 return new DigestInfo (*this);
10783 }
10784
10785 #if SNACC_DEEP_COPY
10786 DigestInfo &DigestInfo::operator = (const DigestInfo &that)
10787 #else // SNACC_DEEP_COPY
10788 DigestInfo &DigestInfo::operator = (const DigestInfo &)
10789 #endif // SNACC_DEEP_COPY
10790 {
10791 #if SNACC_DEEP_COPY
10792 if (this != &that)
10793 {
10794 if (that.digestAlgorithm)
10795 {
10796 if (!digestAlgorithm)
10797 digestAlgorithm = new DigestAlgorithmIdentifier;
10798 *digestAlgorithm = *that.digestAlgorithm;
10799 }
10800 else
10801 {
10802 delete digestAlgorithm;
10803 digestAlgorithm = NULL;
10804 }
10805 digest = that.digest;
10806 }
10807
10808 return *this;
10809 #else // SNACC_DEEP_COPY
10810 Asn1Error << "use of incompletely defined DigestInfo &DigestInfo::operator = (const DigestInfo &)" << endl;
10811 abort();
10812 // if your compiler complains here, check the -novolat option
10813 #endif // SNACC_DEEP_COPY
10814 }
10815
10816 AsnLen
10817 DigestInfo::BEncContent (BUF_TYPE b)
10818 {
10819 AsnLen totalLen = 0;
10820 AsnLen l;
10821
10822 l = digest.BEncContent (b);
10823 l += BEncDefLen (b, l);
10824
10825 l += BEncTag1 (b, UNIV, PRIM, OCTETSTRING_TAG_CODE);
10826 totalLen += l;
10827
10828 BEncEocIfNec (b);
10829 l = digestAlgorithm->BEncContent (b);
10830 l += BEncConsLen (b, l);
10831
10832 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
10833 totalLen += l;
10834
10835 return totalLen;
10836 } // DigestInfo::BEncContent
10837
10838
10839 void DigestInfo::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env)
10840 {
10841 AsnTag tag1;
10842 AsnLen seqBytesDecoded = 0;
10843 AsnLen elmtLen1;
10844 tag1 = BDecTag (b, seqBytesDecoded, env);
10845
10846 if ((tag1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))
10847 {
10848 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
10849 digestAlgorithm = new DigestAlgorithmIdentifier;
10850 digestAlgorithm->BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
10851 tag1 = BDecTag (b, seqBytesDecoded, env);
10852 }
10853 else
10854 {
10855 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
10856 longjmp (env, -224);
10857 }
10858
10859 if ((tag1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE))
10860 || (tag1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))
10861 {
10862 elmtLen1 = BDecLen (b, seqBytesDecoded, env);
10863 digest.BDecContent (b, tag1, elmtLen1, seqBytesDecoded, env);
10864 }
10865 else
10866 {
10867 Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl;
10868 longjmp (env, -225);
10869 }
10870
10871 bytesDecoded += seqBytesDecoded;
10872 if (elmtLen0 == INDEFINITE_LEN)
10873 {
10874 BDecEoc (b, bytesDecoded, env);
10875 return;
10876 }
10877 else if (seqBytesDecoded != elmtLen0)
10878 {
10879 Asn1Error << "ERROR - Length discrepancy on sequence." << endl;
10880 longjmp (env, -226);
10881 }
10882 else
10883 return;
10884 } // DigestInfo::BDecContent
10885
10886 AsnLen DigestInfo::BEnc (BUF_TYPE b)
10887 {
10888 AsnLen l;
10889 l = BEncContent (b);
10890 l += BEncConsLen (b, l);
10891 l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE);
10892 return l;
10893 }
10894
10895 void DigestInfo::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env)
10896 {
10897 AsnTag tag;
10898 AsnLen elmtLen1;
10899
10900 if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))
10901 {
10902 Asn1Error << "DigestInfo::BDec: ERROR - wrong tag" << endl;
10903 longjmp (env, -227);
10904 }
10905 elmtLen1 = BDecLen (b, bytesDecoded, env);
10906 BDecContent (b, tag, elmtLen1, bytesDecoded, env);
10907 }
10908
10909 int DigestInfo::BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)
10910 {
10911 bytesEncoded = BEnc (b);
10912 return !b.WriteError();
10913 }
10914
10915 int DigestInfo::BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)
10916 {
10917 ENV_TYPE env;
10918 int val;
10919
10920 bytesDecoded = 0;
10921 if ((val = setjmp (env)) == 0)
10922 {
10923 BDec (b, bytesDecoded, env);
10924 return !b.ReadError();
10925 }
10926 else
10927 return false;
10928 }
10929
10930 void DigestInfo::Print (ostream &os) const
10931 {
10932 #ifndef NDEBUG
10933 os << "{ -- SEQUENCE --" << endl;
10934 indentG += stdIndentG;
10935
10936 if (NOT_NULL (digestAlgorithm))
10937 {
10938 Indent (os, indentG);
10939 os << "digestAlgorithm ";
10940 os << *digestAlgorithm;
10941 }
10942 else
10943 {
10944 Indent (os, indentG);
10945 os << "digestAlgorithm ";
10946 os << "-- void --";
10947 os << "," << endl;
10948 }
10949
10950 {
10951 Indent (os, indentG);
10952 os << "digest ";
10953 os << digest;
10954 }
10955
10956 os << endl;
10957 indentG -= stdIndentG;
10958 Indent (os, indentG);
10959 os << "}";
10960 #endif /* NDEBUG */
10961 } // DigestInfo::Print
10962
10963