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