Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | // NOTE: this is a machine generated file--editing not recommended |
2 | // | |
3 | // sm_x509cmn.cpp - class member functions for ASN.1 module CommonX509Definitions | |
4 | // | |
29654253 | 5 | // This file was generated by snacc on Mon Apr 22 22:34:19 2002 |
bac41a7b A |
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" | |
29654253 | 27 | #include "pkcs10.h" |
bac41a7b A |
28 | |
29 | //------------------------------------------------------------------------------ | |
30 | // value defs | |
31 | ||
32 | ||
33 | //------------------------------------------------------------------------------ | |
34 | // class member definitions: | |
35 | ||
36 | EDIPartyName::EDIPartyName() | |
37 | { | |
38 | nameAssigner = NULL; | |
39 | #if TCL | |
40 | partyName = new DirectoryString; | |
41 | #else | |
42 | partyName = NULL; // incomplete initialization of mandatory element! | |
43 | #endif // TCL | |
44 | } | |
45 | ||
46 | EDIPartyName::EDIPartyName (const EDIPartyName &) | |
47 | { | |
48 | Asn1Error << "use of incompletely defined EDIPartyName::EDIPartyName (const EDIPartyName &)" << endl; | |
49 | abort(); | |
50 | } | |
51 | ||
52 | EDIPartyName::~EDIPartyName() | |
53 | { | |
54 | delete nameAssigner; | |
55 | delete partyName; | |
56 | } | |
57 | ||
58 | AsnType *EDIPartyName::Clone() const | |
59 | { | |
60 | return new EDIPartyName; | |
61 | } | |
62 | ||
63 | AsnType *EDIPartyName::Copy() const | |
64 | { | |
65 | return new EDIPartyName (*this); | |
66 | } | |
67 | ||
68 | #if SNACC_DEEP_COPY | |
69 | EDIPartyName &EDIPartyName::operator = (const EDIPartyName &that) | |
70 | #else // SNACC_DEEP_COPY | |
71 | EDIPartyName &EDIPartyName::operator = (const EDIPartyName &) | |
72 | #endif // SNACC_DEEP_COPY | |
73 | { | |
74 | #if SNACC_DEEP_COPY | |
75 | if (this != &that) | |
76 | { | |
77 | if (that.nameAssigner) | |
78 | { | |
79 | if (!nameAssigner) | |
80 | nameAssigner = new DirectoryString; | |
81 | *nameAssigner = *that.nameAssigner; | |
82 | } | |
83 | else | |
84 | { | |
85 | delete nameAssigner; | |
86 | nameAssigner = NULL; | |
87 | } | |
88 | if (that.partyName) | |
89 | { | |
90 | if (!partyName) | |
91 | partyName = new DirectoryString; | |
92 | *partyName = *that.partyName; | |
93 | } | |
94 | else | |
95 | { | |
96 | delete partyName; | |
97 | partyName = NULL; | |
98 | } | |
99 | } | |
100 | ||
101 | return *this; | |
102 | #else // SNACC_DEEP_COPY | |
103 | Asn1Error << "use of incompletely defined EDIPartyName &EDIPartyName::operator = (const EDIPartyName &)" << endl; | |
104 | abort(); | |
105 | // if your compiler complains here, check the -novolat option | |
106 | #endif // SNACC_DEEP_COPY | |
107 | } | |
108 | ||
109 | AsnLen | |
110 | EDIPartyName::BEncContent (BUF_TYPE b) | |
111 | { | |
112 | AsnLen totalLen = 0; | |
113 | AsnLen l; | |
114 | ||
115 | BEncEocIfNec (b); | |
116 | l = partyName->BEncContent (b); | |
117 | l += BEncConsLen (b, l); | |
118 | ||
119 | l += BEncTag1 (b, CNTX, CONS, 1); | |
120 | totalLen += l; | |
121 | ||
122 | if (NOT_NULL (nameAssigner)) | |
123 | { | |
124 | BEncEocIfNec (b); | |
125 | l = nameAssigner->BEncContent (b); | |
126 | l += BEncConsLen (b, l); | |
127 | ||
128 | l += BEncTag1 (b, CNTX, CONS, 0); | |
129 | totalLen += l; | |
130 | } | |
131 | ||
132 | return totalLen; | |
133 | } // EDIPartyName::BEncContent | |
134 | ||
135 | ||
136 | void EDIPartyName::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env) | |
137 | { | |
138 | AsnTag tag1; | |
139 | AsnLen seqBytesDecoded = 0; | |
140 | AsnLen elmtLen1; | |
141 | AsnLen elmtLen2; | |
142 | tag1 = BDecTag (b, seqBytesDecoded, env); | |
143 | ||
144 | if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 0))) | |
145 | { | |
146 | elmtLen1 = BDecLen (b, seqBytesDecoded, env); | |
147 | tag1 = BDecTag (b, seqBytesDecoded, env); | |
148 | elmtLen2 = BDecLen (b, seqBytesDecoded, env); | |
149 | nameAssigner = new DirectoryString; | |
150 | nameAssigner->BDecContent (b, tag1, elmtLen2, seqBytesDecoded, env); | |
151 | if (elmtLen1 == INDEFINITE_LEN) | |
152 | BDecEoc (b, seqBytesDecoded, env); | |
153 | ||
154 | tag1 = BDecTag (b, seqBytesDecoded, env); | |
155 | } | |
156 | ||
157 | if ((tag1 == MAKE_TAG_ID (CNTX, CONS, 1))) | |
158 | { | |
159 | elmtLen1 = BDecLen (b, seqBytesDecoded, env); | |
160 | tag1 = BDecTag (b, seqBytesDecoded, env); | |
161 | elmtLen2 = BDecLen (b, seqBytesDecoded, env); | |
162 | partyName = new DirectoryString; | |
163 | partyName->BDecContent (b, tag1, elmtLen2, seqBytesDecoded, env); | |
164 | if (elmtLen1 == INDEFINITE_LEN) | |
165 | BDecEoc (b, seqBytesDecoded, env); | |
166 | ||
167 | } | |
168 | else | |
169 | { | |
170 | Asn1Error << "ERROR - SEQUENCE is missing non-optional elmt." << endl; | |
29654253 | 171 | SnaccExcep::throwMe(-100); |
bac41a7b A |
172 | } |
173 | ||
174 | bytesDecoded += seqBytesDecoded; | |
175 | if (elmtLen0 == INDEFINITE_LEN) | |
176 | { | |
177 | BDecEoc (b, bytesDecoded, env); | |
178 | return; | |
179 | } | |
180 | else if (seqBytesDecoded != elmtLen0) | |
181 | { | |
182 | Asn1Error << "ERROR - Length discrepancy on sequence." << endl; | |
29654253 | 183 | SnaccExcep::throwMe(-101); |
bac41a7b A |
184 | } |
185 | else | |
186 | return; | |
187 | } // EDIPartyName::BDecContent | |
188 | ||
189 | AsnLen EDIPartyName::BEnc (BUF_TYPE b) | |
190 | { | |
191 | AsnLen l; | |
192 | l = BEncContent (b); | |
193 | l += BEncConsLen (b, l); | |
194 | l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE); | |
195 | return l; | |
196 | } | |
197 | ||
198 | void EDIPartyName::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env) | |
199 | { | |
200 | AsnTag tag; | |
201 | AsnLen elmtLen1; | |
202 | ||
203 | if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)) | |
204 | { | |
205 | Asn1Error << "EDIPartyName::BDec: ERROR - wrong tag" << endl; | |
29654253 | 206 | SnaccExcep::throwMe(-102); |
bac41a7b A |
207 | } |
208 | elmtLen1 = BDecLen (b, bytesDecoded, env); | |
209 | BDecContent (b, tag, elmtLen1, bytesDecoded, env); | |
210 | } | |
211 | ||
bac41a7b A |
212 | void EDIPartyName::Print (ostream &os) const |
213 | { | |
214 | #ifndef NDEBUG | |
215 | os << "{ -- SEQUENCE --" << endl; | |
216 | indentG += stdIndentG; | |
217 | ||
218 | if (NOT_NULL (nameAssigner)) | |
219 | { | |
220 | Indent (os, indentG); | |
221 | os << "nameAssigner "; | |
222 | os << *nameAssigner; | |
223 | } | |
224 | else | |
225 | { | |
226 | Indent (os, indentG); | |
227 | os << "nameAssigner "; | |
228 | os << "-- void --"; | |
229 | os << "," << endl; | |
230 | } | |
231 | ||
232 | if (NOT_NULL (partyName)) | |
233 | { | |
234 | Indent (os, indentG); | |
235 | os << "partyName "; | |
236 | os << *partyName; | |
237 | } | |
238 | else | |
239 | { | |
240 | Indent (os, indentG); | |
241 | os << "partyName "; | |
242 | os << "-- void --"; | |
243 | os << endl; | |
244 | } | |
245 | ||
246 | os << endl; | |
247 | indentG -= stdIndentG; | |
248 | Indent (os, indentG); | |
249 | os << "}"; | |
250 | #endif /* NDEBUG */ | |
251 | } // EDIPartyName::Print | |
252 | ||
253 | ||
254 | GeneralName::GeneralName() | |
255 | { | |
256 | choiceId = otherNameCid; | |
257 | #if TCL | |
258 | otherName = new OTHER_NAME; | |
259 | #else | |
260 | otherName = NULL; // incomplete initialization of mandatory element! | |
261 | #endif // TCL | |
262 | } | |
263 | ||
264 | GeneralName::GeneralName (const GeneralName &) | |
265 | { | |
266 | Asn1Error << "use of incompletely defined GeneralName::GeneralName (const GeneralName &)" << endl; | |
267 | abort(); | |
268 | } | |
269 | ||
270 | GeneralName::~GeneralName() | |
271 | { | |
272 | switch (choiceId) | |
273 | { | |
274 | case otherNameCid: | |
275 | delete otherName; | |
276 | break; | |
277 | case rfc822NameCid: | |
278 | delete rfc822Name; | |
279 | break; | |
280 | case dNSNameCid: | |
281 | delete dNSName; | |
282 | break; | |
283 | case x400AddressCid: | |
284 | delete x400Address; | |
285 | break; | |
286 | case directoryNameCid: | |
287 | delete directoryName; | |
288 | break; | |
289 | case ediPartyNameCid: | |
290 | delete ediPartyName; | |
291 | break; | |
292 | case uniformResourceIdentifierCid: | |
293 | delete uniformResourceIdentifier; | |
294 | break; | |
295 | case iPAddressCid: | |
296 | delete iPAddress; | |
297 | break; | |
298 | case registeredIDCid: | |
299 | delete registeredID; | |
300 | break; | |
301 | } // end of switch | |
302 | } // end of destructor | |
303 | ||
304 | AsnType *GeneralName::Clone() const | |
305 | { | |
306 | return new GeneralName; | |
307 | } | |
308 | ||
309 | AsnType *GeneralName::Copy() const | |
310 | { | |
311 | return new GeneralName (*this); | |
312 | } | |
313 | ||
314 | #if SNACC_DEEP_COPY | |
315 | GeneralName &GeneralName::operator = (const GeneralName &that) | |
316 | #else // SNACC_DEEP_COPY | |
317 | GeneralName &GeneralName::operator = (const GeneralName &) | |
318 | #endif // SNACC_DEEP_COPY | |
319 | { | |
320 | #if SNACC_DEEP_COPY | |
321 | if (this != &that) | |
322 | { | |
323 | switch (choiceId) | |
324 | { | |
325 | case otherNameCid: | |
326 | delete otherName; | |
327 | break; | |
328 | case rfc822NameCid: | |
329 | delete rfc822Name; | |
330 | break; | |
331 | case dNSNameCid: | |
332 | delete dNSName; | |
333 | break; | |
334 | case x400AddressCid: | |
335 | delete x400Address; | |
336 | break; | |
337 | case directoryNameCid: | |
338 | delete directoryName; | |
339 | break; | |
340 | case ediPartyNameCid: | |
341 | delete ediPartyName; | |
342 | break; | |
343 | case uniformResourceIdentifierCid: | |
344 | delete uniformResourceIdentifier; | |
345 | break; | |
346 | case iPAddressCid: | |
347 | delete iPAddress; | |
348 | break; | |
349 | case registeredIDCid: | |
350 | delete registeredID; | |
351 | break; | |
352 | } | |
353 | switch (choiceId = that.choiceId) | |
354 | { | |
355 | case otherNameCid: | |
356 | otherName = new OTHER_NAME; | |
357 | *otherName = *that.otherName; | |
358 | break; | |
359 | case rfc822NameCid: | |
360 | rfc822Name = new IA5String; | |
361 | *rfc822Name = *that.rfc822Name; | |
362 | break; | |
363 | case dNSNameCid: | |
364 | dNSName = new IA5String; | |
365 | *dNSName = *that.dNSName; | |
366 | break; | |
367 | case x400AddressCid: | |
368 | x400Address = new ORAddress; | |
369 | *x400Address = *that.x400Address; | |
370 | break; | |
371 | case directoryNameCid: | |
372 | directoryName = new Name; | |
373 | *directoryName = *that.directoryName; | |
374 | break; | |
375 | case ediPartyNameCid: | |
376 | ediPartyName = new EDIPartyName; | |
377 | *ediPartyName = *that.ediPartyName; | |
378 | break; | |
379 | case uniformResourceIdentifierCid: | |
380 | uniformResourceIdentifier = new IA5String; | |
381 | *uniformResourceIdentifier = *that.uniformResourceIdentifier; | |
382 | break; | |
383 | case iPAddressCid: | |
384 | iPAddress = new AsnOcts; | |
385 | *iPAddress = *that.iPAddress; | |
386 | break; | |
387 | case registeredIDCid: | |
388 | registeredID = new AsnOid; | |
389 | *registeredID = *that.registeredID; | |
390 | break; | |
391 | } | |
392 | } | |
393 | ||
394 | return *this; | |
395 | #else // SNACC_DEEP_COPY | |
396 | Asn1Error << "use of incompletely defined GeneralName &GeneralName::operator = (const GeneralName &)" << endl; | |
397 | abort(); | |
398 | // if your compiler complains here, check the -novolat option | |
399 | #endif // SNACC_DEEP_COPY | |
400 | } | |
401 | ||
402 | AsnLen | |
403 | GeneralName::BEncContent (BUF_TYPE b) | |
404 | { | |
405 | AsnLen l; | |
406 | switch (choiceId) | |
407 | { | |
408 | case otherNameCid: | |
409 | l = otherName->BEncContent (b); | |
410 | l += BEncDefLen (b, l); | |
411 | ||
412 | l += BEncTag1 (b, CNTX, PRIM, 0); | |
413 | break; | |
414 | ||
415 | case rfc822NameCid: | |
416 | l = rfc822Name->BEncContent (b); | |
417 | l += BEncDefLen (b, l); | |
418 | ||
419 | l += BEncTag1 (b, CNTX, PRIM, 1); | |
420 | break; | |
421 | ||
422 | case dNSNameCid: | |
423 | l = dNSName->BEncContent (b); | |
424 | l += BEncDefLen (b, l); | |
425 | ||
426 | l += BEncTag1 (b, CNTX, PRIM, 2); | |
427 | break; | |
428 | ||
429 | case x400AddressCid: | |
430 | BEncEocIfNec (b); | |
431 | l = x400Address->BEncContent (b); | |
432 | l += BEncConsLen (b, l); | |
433 | ||
434 | l += BEncTag1 (b, CNTX, CONS, 3); | |
435 | break; | |
436 | ||
437 | case directoryNameCid: | |
438 | BEncEocIfNec (b); | |
439 | l = directoryName->BEncContent (b); | |
440 | l += BEncConsLen (b, l); | |
441 | ||
442 | l += BEncTag1 (b, CNTX, CONS, 4); | |
443 | break; | |
444 | ||
445 | case ediPartyNameCid: | |
446 | BEncEocIfNec (b); | |
447 | l = ediPartyName->BEncContent (b); | |
448 | l += BEncConsLen (b, l); | |
449 | ||
450 | l += BEncTag1 (b, CNTX, CONS, 5); | |
451 | break; | |
452 | ||
453 | case uniformResourceIdentifierCid: | |
454 | l = uniformResourceIdentifier->BEncContent (b); | |
455 | l += BEncDefLen (b, l); | |
456 | ||
457 | l += BEncTag1 (b, CNTX, PRIM, 6); | |
458 | break; | |
459 | ||
460 | case iPAddressCid: | |
461 | l = iPAddress->BEncContent (b); | |
462 | l += BEncDefLen (b, l); | |
463 | ||
464 | l += BEncTag1 (b, CNTX, PRIM, 7); | |
465 | break; | |
466 | ||
467 | case registeredIDCid: | |
468 | l = registeredID->BEncContent (b); | |
469 | l += BEncDefLen (b, l); | |
470 | ||
471 | l += BEncTag1 (b, CNTX, PRIM, 8); | |
472 | break; | |
473 | ||
474 | } // end switch | |
475 | return l; | |
476 | } // GeneralName::BEncContent | |
477 | ||
478 | ||
479 | void GeneralName::BDecContent (BUF_TYPE b, AsnTag tag, AsnLen elmtLen0, AsnLen &bytesDecoded, ENV_TYPE env) | |
480 | { | |
481 | AsnLen elmtLen1; | |
482 | switch (tag) | |
483 | { | |
484 | case MAKE_TAG_ID (CNTX, PRIM, 0): | |
485 | choiceId = otherNameCid; | |
486 | otherName = new OTHER_NAME; | |
487 | otherName->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
488 | break; | |
489 | ||
490 | case MAKE_TAG_ID (CNTX, PRIM, 1): | |
491 | case MAKE_TAG_ID (CNTX, CONS, 1): | |
492 | choiceId = rfc822NameCid; | |
493 | rfc822Name = new IA5String; | |
494 | rfc822Name->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
495 | break; | |
496 | ||
497 | case MAKE_TAG_ID (CNTX, PRIM, 2): | |
498 | case MAKE_TAG_ID (CNTX, CONS, 2): | |
499 | choiceId = dNSNameCid; | |
500 | dNSName = new IA5String; | |
501 | dNSName->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
502 | break; | |
503 | ||
504 | case MAKE_TAG_ID (CNTX, CONS, 3): | |
505 | choiceId = x400AddressCid; | |
506 | x400Address = new ORAddress; | |
507 | x400Address->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
508 | break; | |
509 | ||
510 | case MAKE_TAG_ID (CNTX, CONS, 4): | |
511 | tag = BDecTag (b, bytesDecoded, env); | |
512 | elmtLen1 = BDecLen (b, bytesDecoded, env); | |
513 | choiceId = directoryNameCid; | |
514 | directoryName = new Name; | |
515 | directoryName->BDecContent (b, tag, elmtLen1, bytesDecoded, env); | |
516 | if (elmtLen0 == INDEFINITE_LEN) | |
517 | BDecEoc (b, bytesDecoded, env); | |
518 | break; | |
519 | ||
520 | case MAKE_TAG_ID (CNTX, CONS, 5): | |
521 | choiceId = ediPartyNameCid; | |
522 | ediPartyName = new EDIPartyName; | |
523 | ediPartyName->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
524 | break; | |
525 | ||
526 | case MAKE_TAG_ID (CNTX, PRIM, 6): | |
527 | case MAKE_TAG_ID (CNTX, CONS, 6): | |
528 | choiceId = uniformResourceIdentifierCid; | |
529 | uniformResourceIdentifier = new IA5String; | |
530 | uniformResourceIdentifier->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
531 | break; | |
532 | ||
533 | case MAKE_TAG_ID (CNTX, PRIM, 7): | |
534 | case MAKE_TAG_ID (CNTX, CONS, 7): | |
535 | choiceId = iPAddressCid; | |
536 | iPAddress = new AsnOcts; | |
537 | iPAddress->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
538 | break; | |
539 | ||
540 | case MAKE_TAG_ID (CNTX, PRIM, 8): | |
541 | choiceId = registeredIDCid; | |
542 | registeredID = new AsnOid; | |
543 | registeredID->BDecContent (b, tag, elmtLen0, bytesDecoded, env); | |
544 | break; | |
545 | ||
546 | default: | |
547 | Asn1Error << "ERROR - unexpected tag in CHOICE" << endl; | |
29654253 | 548 | SnaccExcep::throwMe(-103); |
bac41a7b A |
549 | break; |
550 | } // end switch | |
551 | } // GeneralName::BDecContent | |
552 | ||
553 | ||
554 | AsnLen GeneralName::BEnc (BUF_TYPE b) | |
555 | { | |
556 | AsnLen l; | |
557 | l = BEncContent (b); | |
558 | return l; | |
559 | } | |
560 | ||
561 | void GeneralName::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env) | |
562 | { | |
563 | AsnLen elmtLen; | |
564 | AsnTag tag; | |
565 | ||
566 | /* CHOICEs are a special case - grab identifying tag */ | |
567 | /* this allows easier handling of nested CHOICEs */ | |
568 | tag = BDecTag (b, bytesDecoded, env); | |
569 | elmtLen = BDecLen (b, bytesDecoded, env); | |
570 | BDecContent (b, tag, elmtLen, bytesDecoded, env); | |
571 | } | |
572 | ||
bac41a7b A |
573 | void GeneralName::Print (ostream &os) const |
574 | { | |
575 | #ifndef NDEBUG | |
576 | switch (choiceId) | |
577 | { | |
578 | case otherNameCid: | |
579 | os << "otherName "; | |
580 | if (otherName) | |
581 | os << *otherName; | |
582 | else | |
583 | os << "-- void3 --\n"; | |
584 | break; | |
585 | ||
586 | case rfc822NameCid: | |
587 | os << "rfc822Name "; | |
588 | if (rfc822Name) | |
589 | os << *rfc822Name; | |
590 | else | |
591 | os << "-- void3 --\n"; | |
592 | break; | |
593 | ||
594 | case dNSNameCid: | |
595 | os << "dNSName "; | |
596 | if (dNSName) | |
597 | os << *dNSName; | |
598 | else | |
599 | os << "-- void3 --\n"; | |
600 | break; | |
601 | ||
602 | case x400AddressCid: | |
603 | os << "x400Address "; | |
604 | if (x400Address) | |
605 | os << *x400Address; | |
606 | else | |
607 | os << "-- void3 --\n"; | |
608 | break; | |
609 | ||
610 | case directoryNameCid: | |
611 | os << "directoryName "; | |
612 | if (directoryName) | |
613 | os << *directoryName; | |
614 | else | |
615 | os << "-- void3 --\n"; | |
616 | break; | |
617 | ||
618 | case ediPartyNameCid: | |
619 | os << "ediPartyName "; | |
620 | if (ediPartyName) | |
621 | os << *ediPartyName; | |
622 | else | |
623 | os << "-- void3 --\n"; | |
624 | break; | |
625 | ||
626 | case uniformResourceIdentifierCid: | |
627 | os << "uniformResourceIdentifier "; | |
628 | if (uniformResourceIdentifier) | |
629 | os << *uniformResourceIdentifier; | |
630 | else | |
631 | os << "-- void3 --\n"; | |
632 | break; | |
633 | ||
634 | case iPAddressCid: | |
635 | os << "iPAddress "; | |
636 | if (iPAddress) | |
637 | os << *iPAddress; | |
638 | else | |
639 | os << "-- void3 --\n"; | |
640 | break; | |
641 | ||
642 | case registeredIDCid: | |
643 | os << "registeredID "; | |
644 | if (registeredID) | |
645 | os << *registeredID; | |
646 | else | |
647 | os << "-- void3 --\n"; | |
648 | break; | |
649 | ||
650 | } // end of switch | |
651 | #endif /* NDEBUG */ | |
652 | } // GeneralName::Print | |
653 | ||
654 | AsnType *GeneralNames::Clone() const | |
655 | { | |
656 | return new GeneralNames; | |
657 | } | |
658 | ||
659 | AsnType *GeneralNames::Copy() const | |
660 | { | |
661 | return new GeneralNames (*this); | |
662 | } | |
663 | ||
664 | AsnLen GeneralNames::BEnc (BUF_TYPE b) | |
665 | { | |
666 | AsnLen l; | |
667 | l = BEncContent (b); | |
668 | l += BEncConsLen (b, l); | |
669 | l += BEncTag1 (b, UNIV, CONS, SEQ_TAG_CODE); | |
670 | return l; | |
671 | } | |
672 | ||
673 | void GeneralNames::BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env) | |
674 | { | |
675 | AsnTag tag; | |
676 | AsnLen elmtLen1; | |
677 | ||
678 | if ((tag = BDecTag (b, bytesDecoded, env)) != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)) | |
679 | { | |
680 | Asn1Error << "GeneralNames::BDec: ERROR - wrong tag" << endl; | |
29654253 | 681 | SnaccExcep::throwMe(-104); |
bac41a7b A |
682 | } |
683 | elmtLen1 = BDecLen (b, bytesDecoded, env); | |
684 | BDecContent (b, tag, elmtLen1, bytesDecoded, env); | |
685 | } | |
686 | ||
687 | GeneralNames::GeneralNames (const GeneralNames &) | |
688 | { | |
689 | Asn1Error << "use of incompletely defined GeneralNames::GeneralNames (const GeneralNames &)" << endl; | |
690 | abort(); | |
691 | } | |
692 | ||
693 | GeneralNames::~GeneralNames() | |
694 | { | |
695 | SetCurrToFirst(); | |
696 | for (; Curr() != NULL; RemoveCurrFromList()) | |
697 | ; | |
698 | } // end of destructor | |
699 | ||
700 | #if SNACC_DEEP_COPY | |
701 | GeneralNames &GeneralNames::operator = (const GeneralNames &that) | |
702 | #else // SNACC_DEEP_COPY | |
703 | GeneralNames &GeneralNames::operator = (const GeneralNames &) | |
704 | #endif // SNACC_DEEP_COPY | |
705 | { | |
706 | #if SNACC_DEEP_COPY | |
707 | if (this != &that) | |
708 | { | |
709 | SetCurrToFirst(); | |
710 | for (; Curr(); RemoveCurrFromList()) | |
711 | ; | |
712 | ||
713 | //that.SetCurrToFirst(); | |
714 | //for (; that.Curr(); that.GoNext()) | |
715 | // AppendCopy (*that.Curr()); | |
716 | for (const AsnListElmt *run=that.first; run; run=run->next) | |
717 | AppendCopy (*run->elmt); | |
718 | } | |
719 | ||
720 | return *this; | |
721 | #else // SNACC_DEEP_COPY | |
722 | Asn1Error << "use of incompletely defined GeneralNames &GeneralNames::operator = (const GeneralNames &)" << endl; | |
723 | abort(); | |
724 | // if your compiler complains here, check the -novolat option | |
725 | #endif // SNACC_DEEP_COPY | |
726 | } | |
727 | ||
728 | void GeneralNames::Print (ostream &os) const | |
729 | { | |
730 | #ifndef NDEBUG | |
731 | os << "{ -- SEQUENCE/SET OF -- " << endl; | |
732 | indentG += stdIndentG; | |
733 | //SetCurrToFirst(); | |
734 | //for (; Curr() != NULL; GoNext()) | |
735 | for (const AsnListElmt *run=first; run; run=run->next) | |
736 | { | |
737 | Indent (os, indentG); | |
738 | //os << *Curr(); | |
739 | os << *run->elmt; | |
740 | //if (Curr() != Last()) | |
741 | if (run != last) | |
742 | os << ","; | |
743 | os << endl; | |
744 | } | |
745 | indentG -= stdIndentG; | |
746 | Indent (os, indentG); | |
747 | os << "}\n"; | |
748 | #endif /* NDEBUG */ | |
749 | ||
750 | ||
751 | ||
752 | ||
753 | ||
754 | void GeneralNames::SetCurrElmt (unsigned long int index) | |
755 | { | |
756 | unsigned long int i; | |
757 | curr = first; | |
758 | if (count) | |
759 | for (i = 0; (i < (count-1)) && (i < index); i++) | |
760 | curr = curr->next; | |
761 | } // GeneralNames::SetCurrElmt | |
762 | ||
763 | ||
764 | unsigned long int GeneralNames::GetCurrElmtIndex() | |
765 | { | |
766 | unsigned long int i; | |
767 | AsnListElmt *tmp; | |
768 | if (curr != NULL) | |
769 | { | |
770 | for (i = 0, tmp = first; tmp != NULL; i++) | |
771 | { | |
772 | if (tmp == curr) | |
773 | return i; | |
774 | else | |
775 | tmp = tmp->next; | |
776 | } | |
777 | } | |
778 | return count; | |
779 | } // GeneralNames::GetCurrElmtIndex | |
780 | ||
781 | ||
782 | // alloc new list elmt, put at end of list | |
783 | // and return the component type | |
784 | GeneralName *GeneralNames::Append() | |
785 | { | |
786 | AsnListElmt *newElmt; | |
787 | newElmt = new AsnListElmt; | |
788 | newElmt->elmt = new GeneralName; | |
789 | newElmt->next = NULL; | |
790 | if (last == NULL) | |
791 | { | |
792 | newElmt->prev = NULL; | |
793 | first = last = newElmt; | |
794 | } | |
795 | else | |
796 | { | |
797 | newElmt->prev = last; | |
798 | last->next = newElmt; | |
799 | last = newElmt; | |
800 | } | |
801 | count++; | |
802 | return (curr = newElmt)->elmt; | |
803 | } // GeneralNames::Append | |
804 | ||
805 | ||
806 | // alloc new list elmt, put at begining of list | |
807 | // and return the component type | |
808 | GeneralName *GeneralNames::Prepend() | |
809 | { | |
810 | AsnListElmt *newElmt; | |
811 | newElmt = new AsnListElmt; | |
812 | newElmt->elmt = new GeneralName; | |
813 | newElmt->prev = NULL; | |
814 | if (first == NULL) | |
815 | { | |
816 | newElmt->next = NULL; | |
817 | first = last = newElmt; | |
818 | } | |
819 | else | |
820 | { | |
821 | newElmt->next = first; | |
822 | first->prev = newElmt; | |
823 | first = newElmt; | |
824 | } | |
825 | count++; | |
826 | return (curr = newElmt)->elmt; | |
827 | } // GeneralNames::Prepend | |
828 | ||
829 | ||
830 | // alloc new list elmt, insert it before the | |
831 | // current element and return the component type | |
832 | // if the current element is null, the new element | |
833 | // is placed at the beginning of the list. | |
834 | GeneralName *GeneralNames::InsertBefore() | |
835 | { | |
836 | AsnListElmt *newElmt; | |
837 | newElmt = new AsnListElmt; | |
838 | newElmt->elmt = new GeneralName; | |
839 | if (curr == NULL) | |
840 | { | |
841 | newElmt->next = first; | |
842 | newElmt->prev = NULL; | |
843 | first = newElmt; | |
844 | if (last == NULL) | |
845 | last = newElmt; | |
846 | } | |
847 | else | |
848 | { | |
849 | newElmt->next = curr; | |
850 | newElmt->prev = curr->prev; | |
851 | curr->prev = newElmt; | |
852 | if (curr == first) | |
853 | first = newElmt; | |
854 | else | |
855 | newElmt->prev->next = newElmt; | |
856 | } | |
857 | count++; | |
858 | return (curr = newElmt)->elmt; | |
859 | } // GeneralNames::InsertBefore | |
860 | ||
861 | ||
862 | // alloc new list elmt, insert it after the | |
863 | // current element and return the component type | |
864 | // if the current element is null, the new element | |
865 | // is placed at the end of the list. | |
866 | GeneralName *GeneralNames::InsertAfter() | |
867 | { | |
868 | AsnListElmt *newElmt; | |
869 | newElmt = new AsnListElmt; | |
870 | newElmt->elmt = new GeneralName; | |
871 | if (curr == NULL) | |
872 | { | |
873 | newElmt->prev = last; | |
874 | newElmt->next = NULL; | |
875 | last = newElmt; | |
876 | if (first == NULL) | |
877 | first = newElmt; | |
878 | } | |
879 | else | |
880 | { | |
881 | newElmt->prev = curr; | |
882 | newElmt->next = curr->next; | |
883 | curr->next = newElmt; | |
884 | if (curr == last) | |
885 | last = newElmt; | |
886 | else | |
887 | newElmt->next->prev = newElmt; | |
888 | } | |
889 | count++; | |
890 | return (curr = newElmt)->elmt; | |
891 | } // GeneralNames::InsertAfter | |
892 | ||
893 | ||
894 | GeneralNames &GeneralNames::AppendCopy (GeneralName &elmt) | |
895 | { | |
896 | AsnListElmt *newElmt; | |
897 | newElmt = new AsnListElmt; | |
898 | newElmt->elmt = new GeneralName; | |
899 | *newElmt->elmt = elmt; | |
900 | newElmt->next = NULL; | |
901 | if (last == NULL) | |
902 | { | |
903 | newElmt->prev = NULL; | |
904 | first = last = newElmt; | |
905 | } | |
906 | else | |
907 | { | |
908 | newElmt->prev = last; | |
909 | last->next = newElmt; | |
910 | last = newElmt; | |
911 | } | |
912 | count++; | |
913 | return *this; | |
914 | } // AppendCopy | |
915 | ||
916 | ||
917 | GeneralNames &GeneralNames::PrependCopy (GeneralName &elmt) | |
918 | { | |
919 | AsnListElmt *newElmt; | |
920 | newElmt = new AsnListElmt; | |
921 | newElmt->elmt = new GeneralName; | |
922 | *newElmt->elmt = elmt; | |
923 | newElmt->prev = NULL; | |
924 | if (first == NULL) | |
925 | { | |
926 | newElmt->next = NULL; | |
927 | first = last = newElmt; | |
928 | } | |
929 | else | |
930 | { | |
931 | newElmt->next = first; | |
932 | first->prev = newElmt; | |
933 | first = newElmt; | |
934 | } | |
935 | count++; | |
936 | return *this; | |
937 | } // GeneralNames::PrependCopy | |
938 | ||
939 | ||
940 | // alloc new list elmt, insert it before the | |
941 | // current element, copy the given elmt into the new elmt | |
942 | // and return the component type. | |
943 | // if the current element is null, the new element | |
944 | // is placed at the beginning of the list. | |
945 | GeneralNames &GeneralNames::InsertBeforeAndCopy (GeneralName &elmt) | |
946 | { | |
947 | AsnListElmt *newElmt; | |
948 | ||
949 | newElmt = new AsnListElmt; | |
950 | newElmt->elmt = new GeneralName; | |
951 | *newElmt->elmt = elmt; | |
952 | ||
953 | if (curr == NULL) | |
954 | { | |
955 | newElmt->next = first; | |
956 | newElmt->prev = NULL; | |
957 | first = newElmt; | |
958 | if (last == NULL) | |
959 | last = newElmt; | |
960 | } | |
961 | else | |
962 | { | |
963 | newElmt->next = curr; | |
964 | newElmt->prev = curr->prev; | |
965 | curr->prev = newElmt; | |
966 | if (curr == first) | |
967 | first = newElmt; | |
968 | else | |
969 | newElmt->prev->next = newElmt; | |
970 | } | |
971 | count++; | |
972 | return *this; | |
973 | } // GeneralNames::InsertBeforeAndCopy | |
974 | ||
975 | ||
976 | // alloc new list elmt, insert it after the | |
977 | // current element, copy given elmt in to new elmt | |
978 | // and return the component type | |
979 | // if the current element is null, the new element | |
980 | // is placed at the end of the list. | |
981 | GeneralNames &GeneralNames::InsertAfterAndCopy (GeneralName &elmt) | |
982 | { | |
983 | AsnListElmt *newElmt; | |
984 | ||
985 | newElmt = new AsnListElmt; | |
986 | newElmt->elmt = new GeneralName; | |
987 | *newElmt->elmt = elmt; | |
988 | if (curr == NULL) | |
989 | { | |
990 | newElmt->prev = last; | |
991 | newElmt->next = NULL; | |
992 | last = newElmt; | |
993 | if (first == NULL) | |
994 | first = newElmt; | |
995 | } | |
996 | else | |
997 | { | |
998 | newElmt->prev = curr; | |
999 | newElmt->next = curr->next; | |
1000 | curr->next = newElmt; | |
1001 | if (curr == last) | |
1002 | last = newElmt; | |
1003 | else | |
1004 | newElmt->next->prev = newElmt; | |
1005 | } | |
1006 | count++; | |
1007 | return *this; | |
1008 | } // GeneralNames::InsertAfterAndCopy | |
1009 | ||
1010 | ||
1011 | // remove current element from list if current element is not NULL | |
1012 | // The new current element will be the next element. | |
1013 | // If the current element is the last element in the list | |
1014 | // the second but last element will become the new current element. | |
1015 | void GeneralNames::RemoveCurrFromList() | |
1016 | { | |
1017 | AsnListElmt *del_elmt; | |
1018 | ||
1019 | if (curr != NULL) | |
1020 | { | |
1021 | del_elmt = curr; | |
1022 | count--; | |
1023 | ||
1024 | if (count == 0) | |
1025 | first = last = curr = NULL; | |
1026 | else if (curr == first) | |
1027 | { | |
1028 | curr = first= first->next; | |
1029 | first->prev = NULL; | |
1030 | } | |
1031 | else if (curr == last) | |
1032 | { | |
1033 | curr = last = last->prev; | |
1034 | last->next = NULL; | |
1035 | } | |
1036 | else | |
1037 | { | |
1038 | curr->prev->next = curr->next; | |
1039 | curr->next->prev = curr->prev; | |
1040 | } | |
1041 | ||
1042 | delete del_elmt->elmt; | |
1043 | delete del_elmt; | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | ||
1048 | AsnLen GeneralNames::BEncContent (BUF_TYPE b) | |
1049 | { | |
1050 | AsnListElmt *currElmt; | |
1051 | AsnLen elmtLen; | |
1052 | AsnLen totalLen = 0; | |
1053 | for (currElmt = last; currElmt != NULL; currElmt = currElmt->prev) | |
1054 | { | |
1055 | elmtLen = currElmt->elmt->BEncContent (b); | |
1056 | totalLen += elmtLen; | |
1057 | } | |
1058 | return totalLen; | |
1059 | } // GeneralNames::BEncContent | |
1060 | ||
1061 | ||
1062 | void GeneralNames::BDecContent (BUF_TYPE b, AsnTag /*tag0*/, AsnLen elmtLen0, | |
1063 | AsnLen &bytesDecoded, ENV_TYPE env) | |
1064 | { | |
1065 | GeneralName *listElmt; | |
1066 | AsnTag tag1; | |
1067 | AsnLen listBytesDecoded = 0; | |
1068 | AsnLen elmtLen1; | |
1069 | ||
1070 | while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN)) | |
1071 | { | |
1072 | tag1 = BDecTag (b, listBytesDecoded, env); | |
1073 | if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) | |
1074 | { | |
1075 | BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env); | |
1076 | break; | |
1077 | } | |
1078 | if (!((tag1 == MAKE_TAG_ID (CNTX, PRIM, 0)) | |
1079 | || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 1)) | |
1080 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 1)) | |
1081 | ||
1082 | || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 2)) | |
1083 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 2)) | |
1084 | ||
1085 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 3)) | |
1086 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 4)) | |
1087 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 5)) | |
1088 | || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 6)) | |
1089 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 6)) | |
1090 | ||
1091 | || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 7)) | |
1092 | || (tag1 == MAKE_TAG_ID (CNTX, CONS, 7)) | |
1093 | ||
1094 | || (tag1 == MAKE_TAG_ID (CNTX, PRIM, 8)))) | |
1095 | { | |
1096 | Asn1Error << "Unexpected Tag" << endl; | |
29654253 | 1097 | SnaccExcep::throwMe(-105); |
bac41a7b A |
1098 | } |
1099 | ||
1100 | elmtLen1 = BDecLen (b, listBytesDecoded, env); | |
1101 | listElmt = Append(); | |
1102 | listElmt->BDecContent (b, tag1, elmtLen1, listBytesDecoded, env); | |
1103 | } | |
1104 | ||
1105 | bytesDecoded += listBytesDecoded; | |
1106 | } // GeneralNames::BDecContent | |
1107 | ||
1108 |