1 package org.bouncycastle.asn1.pkcs; 2 3 import java.math.BigInteger; 4 5 import org.bouncycastle.asn1.ASN1EncodableVector; 6 import org.bouncycastle.asn1.ASN1Integer; 7 import org.bouncycastle.asn1.ASN1Object; 8 import org.bouncycastle.asn1.ASN1Primitive; 9 import org.bouncycastle.asn1.ASN1Sequence; 10 import org.bouncycastle.asn1.BERSequence; 11 12 /** 13 * the infamous Pfx from PKCS12 14 */ 15 public class Pfx 16 extends ASN1Object 17 implements PKCSObjectIdentifiers 18 { 19 private ContentInfo contentInfo; 20 private MacData macData = null; 21 22 private Pfx( 23 ASN1Sequence seq) 24 { 25 BigInteger version = ((ASN1Integer)seq.getObjectAt(0)).getValue(); 26 if (version.intValue() != 3) 27 { 28 throw new IllegalArgumentException("wrong version for PFX PDU"); 29 } 30 31 contentInfo = ContentInfo.getInstance(seq.getObjectAt(1)); 32 33 if (seq.size() == 3) 34 { 35 macData = MacData.getInstance(seq.getObjectAt(2)); 36 } 37 } 38 39 public static Pfx getInstance( 40 Object obj) 41 { 42 if (obj instanceof Pfx) 43 { 44 return (Pfx)obj; 45 } 46 47 if (obj != null) 48 { 49 return new Pfx(ASN1Sequence.getInstance(obj)); 50 } 51 52 return null; 53 } 54 55 public Pfx( 56 ContentInfo contentInfo, 57 MacData macData) 58 { 59 this.contentInfo = contentInfo; 60 this.macData = macData; 61 } 62 63 public ContentInfo getAuthSafe() 64 { 65 return contentInfo; 66 } 67 68 public MacData getMacData() 69 { 70 return macData; 71 } 72 73 public ASN1Primitive toASN1Primitive() 74 { 75 ASN1EncodableVector v = new ASN1EncodableVector(); 76 77 v.add(new ASN1Integer(3)); 78 v.add(contentInfo); 79 80 if (macData != null) 81 { 82 v.add(macData); 83 } 84 85 return new BERSequence(v); 86 } 87 } 88