01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.math.BigInteger;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.BERSequence;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11:
12: /**
13: * the infamous Pfx from PKCS12
14: */
15: public class Pfx extends ASN1Encodable implements PKCSObjectIdentifiers {
16: private ContentInfo contentInfo;
17: private MacData macData = null;
18:
19: public Pfx(ASN1Sequence seq) {
20: BigInteger version = ((DERInteger) seq.getObjectAt(0))
21: .getValue();
22: if (version.intValue() != 3) {
23: throw new IllegalArgumentException(
24: "wrong version for PFX PDU");
25: }
26:
27: contentInfo = ContentInfo.getInstance(seq.getObjectAt(1));
28:
29: if (seq.size() == 3) {
30: macData = MacData.getInstance(seq.getObjectAt(2));
31: }
32: }
33:
34: public Pfx(ContentInfo contentInfo, MacData macData) {
35: this .contentInfo = contentInfo;
36: this .macData = macData;
37: }
38:
39: public ContentInfo getAuthSafe() {
40: return contentInfo;
41: }
42:
43: public MacData getMacData() {
44: return macData;
45: }
46:
47: public DERObject toASN1Object() {
48: ASN1EncodableVector v = new ASN1EncodableVector();
49:
50: v.add(new DERInteger(3));
51: v.add(contentInfo);
52:
53: if (macData != null) {
54: v.add(macData);
55: }
56:
57: return new BERSequence(v);
58: }
59: }
|