1 20 package com.novosec.pkix.asn1.cmp; 21 22 import org.bouncycastle.asn1.ASN1EncodableVector; 23 import org.bouncycastle.asn1.ASN1Sequence; 24 import org.bouncycastle.asn1.ASN1TaggedObject; 25 import org.bouncycastle.asn1.DEREncodable; 26 import org.bouncycastle.asn1.DERObject; 27 import org.bouncycastle.asn1.DERSequence; 28 29 40 public class ProtectedPart implements DEREncodable 41 { 42 PKIHeader header; 43 PKIBody body; 44 45 public static ProtectedPart getInstance( ASN1TaggedObject obj, boolean explicit ) 46 { 47 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 48 } 49 50 public static ProtectedPart getInstance( Object obj ) 51 { 52 if (obj instanceof ProtectedPart) 53 { 54 return (ProtectedPart)obj; 55 } 56 else if (obj instanceof ASN1Sequence) 57 { 58 return new ProtectedPart((ASN1Sequence)obj); 59 } 60 61 throw new IllegalArgumentException ("unknown object in factory"); 62 } 63 64 public ProtectedPart( ASN1Sequence seq ) 65 { 66 this.header = PKIHeader.getInstance(seq.getObjectAt(0)); 67 this.body = PKIBody.getInstance((ASN1TaggedObject)seq.getObjectAt(1)); 68 } 69 70 public ProtectedPart( PKIHeader header, PKIBody body ) 71 { 72 this.header = header; 73 this.body = body; 74 } 75 76 public PKIHeader getHeader() 77 { 78 return header; 79 } 80 81 public PKIBody getBody() 82 { 83 return body; 84 } 85 86 public DERObject getDERObject() 87 { 88 ASN1EncodableVector v = new ASN1EncodableVector(); 89 90 v.add( header ); 91 v.add( body ); 92 93 return new DERSequence(v); 94 } 95 96 public String toString() 97 { 98 return "ProtectedPart: (header = " + this.getHeader() + ", body = " + this.getBody() + ")"; 99 } 100 } 101 | Popular Tags |