]>
git.saurik.com Git - apple/security.git/blob - SecurityASN1/c++/pkcs8.cpp
fb9745166e307abcac4896d68d343d5842c159a5
1 // NOTE: this is a machine generated file--editing not recommended
3 // pkcs8.cpp - class member functions for ASN.1 module PrivateKeyInformationSyntax
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
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"
26 #include "appleoids.h"
29 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 // class member definitions:
36 PrivateKeyInfo::PrivateKeyInfo()
39 privateKeyAlgorithm
= new AlgorithmIdentifier
;
41 privateKeyAlgorithm
= NULL
; // incomplete initialization of mandatory element!
46 PrivateKeyInfo::PrivateKeyInfo (const PrivateKeyInfo
&)
48 Asn1Error
<< "use of incompletely defined PrivateKeyInfo::PrivateKeyInfo (const PrivateKeyInfo &)" << endl
;
52 PrivateKeyInfo::~PrivateKeyInfo()
54 delete privateKeyAlgorithm
;
58 AsnType
*PrivateKeyInfo::Clone() const
60 return new PrivateKeyInfo
;
63 AsnType
*PrivateKeyInfo::Copy() const
65 return new PrivateKeyInfo (*this);
69 PrivateKeyInfo
&PrivateKeyInfo::operator = (const PrivateKeyInfo
&that
)
70 #else // SNACC_DEEP_COPY
71 PrivateKeyInfo
&PrivateKeyInfo::operator = (const PrivateKeyInfo
&)
72 #endif // SNACC_DEEP_COPY
77 version
= that
.version
;
78 if (that
.privateKeyAlgorithm
)
80 if (!privateKeyAlgorithm
)
81 privateKeyAlgorithm
= new AlgorithmIdentifier
;
82 *privateKeyAlgorithm
= *that
.privateKeyAlgorithm
;
86 delete privateKeyAlgorithm
;
87 privateKeyAlgorithm
= NULL
;
89 privateKey
= that
.privateKey
;
93 attributes
= new Attributes
;
94 *attributes
= *that
.attributes
;
104 #else // SNACC_DEEP_COPY
105 Asn1Error
<< "use of incompletely defined PrivateKeyInfo &PrivateKeyInfo::operator = (const PrivateKeyInfo &)" << endl
;
107 // if your compiler complains here, check the -novolat option
108 #endif // SNACC_DEEP_COPY
112 PrivateKeyInfo::BEncContent (BUF_TYPE b
)
117 if (NOT_NULL (attributes
))
120 l
= attributes
->BEncContent (b
);
121 l
+= BEncConsLen (b
, l
);
123 l
+= BEncTag1 (b
, CNTX
, CONS
, 0);
127 l
= privateKey
.BEncContent (b
);
128 l
+= BEncDefLen (b
, l
);
130 l
+= BEncTag1 (b
, UNIV
, PRIM
, OCTETSTRING_TAG_CODE
);
134 l
= privateKeyAlgorithm
->BEncContent (b
);
135 l
+= BEncConsLen (b
, l
);
137 l
+= BEncTag1 (b
, UNIV
, CONS
, SEQ_TAG_CODE
);
140 l
= version
.BEncContent (b
);
141 BEncDefLenTo127 (b
, l
);
144 l
+= BEncTag1 (b
, UNIV
, PRIM
, INTEGER_TAG_CODE
);
148 } // PrivateKeyInfo::BEncContent
151 void PrivateKeyInfo::BDecContent (BUF_TYPE b
, AsnTag
/*tag0*/, AsnLen elmtLen0
, AsnLen
&bytesDecoded
, ENV_TYPE env
)
154 AsnLen seqBytesDecoded
= 0;
156 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
158 if ((tag1
== MAKE_TAG_ID (UNIV
, PRIM
, INTEGER_TAG_CODE
)))
160 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
161 version
.BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
162 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
166 Asn1Error
<< "ERROR - SEQUENCE is missing non-optional elmt." << endl
;
167 SnaccExcep::throwMe(-100);
170 if ((tag1
== MAKE_TAG_ID (UNIV
, CONS
, SEQ_TAG_CODE
)))
172 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
173 privateKeyAlgorithm
= new AlgorithmIdentifier
;
174 privateKeyAlgorithm
->BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
175 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
179 Asn1Error
<< "ERROR - SEQUENCE is missing non-optional elmt." << endl
;
180 SnaccExcep::throwMe(-101);
183 if ((tag1
== MAKE_TAG_ID (UNIV
, PRIM
, OCTETSTRING_TAG_CODE
))
184 || (tag1
== MAKE_TAG_ID (UNIV
, CONS
, OCTETSTRING_TAG_CODE
)))
186 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
187 privateKey
.BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
188 if (seqBytesDecoded
== elmtLen0
)
190 bytesDecoded
+= seqBytesDecoded
;
195 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
197 if ((elmtLen0
== INDEFINITE_LEN
) && (tag1
== EOC_TAG_ID
))
199 BDEC_2ND_EOC_OCTET (b
, seqBytesDecoded
, env
)
200 bytesDecoded
+= seqBytesDecoded
;
207 Asn1Error
<< "ERROR - SEQUENCE is missing non-optional elmt." << endl
;
208 SnaccExcep::throwMe(-102);
211 if ((tag1
== MAKE_TAG_ID (CNTX
, CONS
, 0)))
213 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
214 attributes
= new Attributes
;
215 attributes
->BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
218 bytesDecoded
+= seqBytesDecoded
;
219 if (elmtLen0
== INDEFINITE_LEN
)
221 BDecEoc (b
, bytesDecoded
, env
);
224 else if (seqBytesDecoded
!= elmtLen0
)
226 Asn1Error
<< "ERROR - Length discrepancy on sequence." << endl
;
227 SnaccExcep::throwMe(-103);
231 } // PrivateKeyInfo::BDecContent
233 AsnLen
PrivateKeyInfo::BEnc (BUF_TYPE b
)
237 l
+= BEncConsLen (b
, l
);
238 l
+= BEncTag1 (b
, UNIV
, CONS
, SEQ_TAG_CODE
);
242 void PrivateKeyInfo::BDec (BUF_TYPE b
, AsnLen
&bytesDecoded
, ENV_TYPE env
)
247 if ((tag
= BDecTag (b
, bytesDecoded
, env
)) != MAKE_TAG_ID (UNIV
, CONS
, SEQ_TAG_CODE
))
249 Asn1Error
<< "PrivateKeyInfo::BDec: ERROR - wrong tag" << endl
;
250 SnaccExcep::throwMe(-104);
252 elmtLen1
= BDecLen (b
, bytesDecoded
, env
);
253 BDecContent (b
, tag
, elmtLen1
, bytesDecoded
, env
);
256 void PrivateKeyInfo::Print (ostream
&os
) const
259 os
<< "{ -- SEQUENCE --" << endl
;
260 indentG
+= stdIndentG
;
263 Indent (os
, indentG
);
269 if (NOT_NULL (privateKeyAlgorithm
))
271 Indent (os
, indentG
);
272 os
<< "privateKeyAlgorithm ";
273 os
<< *privateKeyAlgorithm
;
277 Indent (os
, indentG
);
278 os
<< "privateKeyAlgorithm ";
284 Indent (os
, indentG
);
290 if (NOT_NULL (attributes
))
293 Indent (os
, indentG
);
299 Indent (os
, indentG
);
306 indentG
-= stdIndentG
;
307 Indent (os
, indentG
);
310 } // PrivateKeyInfo::Print
313 EncryptedPrivateKeyInfo::EncryptedPrivateKeyInfo()
316 encryptionAlgorithm
= new AlgorithmIdentifier
;
318 encryptionAlgorithm
= NULL
; // incomplete initialization of mandatory element!
322 EncryptedPrivateKeyInfo::EncryptedPrivateKeyInfo (const EncryptedPrivateKeyInfo
&)
324 Asn1Error
<< "use of incompletely defined EncryptedPrivateKeyInfo::EncryptedPrivateKeyInfo (const EncryptedPrivateKeyInfo &)" << endl
;
328 EncryptedPrivateKeyInfo::~EncryptedPrivateKeyInfo()
330 delete encryptionAlgorithm
;
333 AsnType
*EncryptedPrivateKeyInfo::Clone() const
335 return new EncryptedPrivateKeyInfo
;
338 AsnType
*EncryptedPrivateKeyInfo::Copy() const
340 return new EncryptedPrivateKeyInfo (*this);
344 EncryptedPrivateKeyInfo
&EncryptedPrivateKeyInfo::operator = (const EncryptedPrivateKeyInfo
&that
)
345 #else // SNACC_DEEP_COPY
346 EncryptedPrivateKeyInfo
&EncryptedPrivateKeyInfo::operator = (const EncryptedPrivateKeyInfo
&)
347 #endif // SNACC_DEEP_COPY
352 if (that
.encryptionAlgorithm
)
354 if (!encryptionAlgorithm
)
355 encryptionAlgorithm
= new AlgorithmIdentifier
;
356 *encryptionAlgorithm
= *that
.encryptionAlgorithm
;
360 delete encryptionAlgorithm
;
361 encryptionAlgorithm
= NULL
;
363 encryptedKey
= that
.encryptedKey
;
367 #else // SNACC_DEEP_COPY
368 Asn1Error
<< "use of incompletely defined EncryptedPrivateKeyInfo &EncryptedPrivateKeyInfo::operator = (const EncryptedPrivateKeyInfo &)" << endl
;
370 // if your compiler complains here, check the -novolat option
371 #endif // SNACC_DEEP_COPY
375 EncryptedPrivateKeyInfo::BEncContent (BUF_TYPE b
)
380 l
= encryptedKey
.BEncContent (b
);
381 l
+= BEncDefLen (b
, l
);
383 l
+= BEncTag1 (b
, UNIV
, PRIM
, OCTETSTRING_TAG_CODE
);
387 l
= encryptionAlgorithm
->BEncContent (b
);
388 l
+= BEncConsLen (b
, l
);
390 l
+= BEncTag1 (b
, UNIV
, CONS
, SEQ_TAG_CODE
);
394 } // EncryptedPrivateKeyInfo::BEncContent
397 void EncryptedPrivateKeyInfo::BDecContent (BUF_TYPE b
, AsnTag
/*tag0*/, AsnLen elmtLen0
, AsnLen
&bytesDecoded
, ENV_TYPE env
)
400 AsnLen seqBytesDecoded
= 0;
402 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
404 if ((tag1
== MAKE_TAG_ID (UNIV
, CONS
, SEQ_TAG_CODE
)))
406 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
407 encryptionAlgorithm
= new AlgorithmIdentifier
;
408 encryptionAlgorithm
->BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
409 tag1
= BDecTag (b
, seqBytesDecoded
, env
);
413 Asn1Error
<< "ERROR - SEQUENCE is missing non-optional elmt." << endl
;
414 SnaccExcep::throwMe(-105);
417 if ((tag1
== MAKE_TAG_ID (UNIV
, PRIM
, OCTETSTRING_TAG_CODE
))
418 || (tag1
== MAKE_TAG_ID (UNIV
, CONS
, OCTETSTRING_TAG_CODE
)))
420 elmtLen1
= BDecLen (b
, seqBytesDecoded
, env
);
421 encryptedKey
.BDecContent (b
, tag1
, elmtLen1
, seqBytesDecoded
, env
);
425 Asn1Error
<< "ERROR - SEQUENCE is missing non-optional elmt." << endl
;
426 SnaccExcep::throwMe(-106);
429 bytesDecoded
+= seqBytesDecoded
;
430 if (elmtLen0
== INDEFINITE_LEN
)
432 BDecEoc (b
, bytesDecoded
, env
);
435 else if (seqBytesDecoded
!= elmtLen0
)
437 Asn1Error
<< "ERROR - Length discrepancy on sequence." << endl
;
438 SnaccExcep::throwMe(-107);
442 } // EncryptedPrivateKeyInfo::BDecContent
444 AsnLen
EncryptedPrivateKeyInfo::BEnc (BUF_TYPE b
)
448 l
+= BEncConsLen (b
, l
);
449 l
+= BEncTag1 (b
, UNIV
, CONS
, SEQ_TAG_CODE
);
453 void EncryptedPrivateKeyInfo::BDec (BUF_TYPE b
, AsnLen
&bytesDecoded
, ENV_TYPE env
)
458 if ((tag
= BDecTag (b
, bytesDecoded
, env
)) != MAKE_TAG_ID (UNIV
, CONS
, SEQ_TAG_CODE
))
460 Asn1Error
<< "EncryptedPrivateKeyInfo::BDec: ERROR - wrong tag" << endl
;
461 SnaccExcep::throwMe(-108);
463 elmtLen1
= BDecLen (b
, bytesDecoded
, env
);
464 BDecContent (b
, tag
, elmtLen1
, bytesDecoded
, env
);
467 void EncryptedPrivateKeyInfo::Print (ostream
&os
) const
470 os
<< "{ -- SEQUENCE --" << endl
;
471 indentG
+= stdIndentG
;
473 if (NOT_NULL (encryptionAlgorithm
))
475 Indent (os
, indentG
);
476 os
<< "encryptionAlgorithm ";
477 os
<< *encryptionAlgorithm
;
481 Indent (os
, indentG
);
482 os
<< "encryptionAlgorithm ";
488 Indent (os
, indentG
);
489 os
<< "encryptedKey ";
494 indentG
-= stdIndentG
;
495 Indent (os
, indentG
);
498 } // EncryptedPrivateKeyInfo::Print