1 20 package com.novosec.pkix.asn1.cmp; 21 22 import org.bouncycastle.asn1.ASN1TaggedObject; 23 import org.bouncycastle.asn1.DEREncodable; 24 import org.bouncycastle.asn1.DERObject; 25 import org.bouncycastle.asn1.DERTaggedObject; 26 import org.bouncycastle.asn1.x509.X509CertificateStructure; 27 28 import com.novosec.pkix.asn1.crmf.EncryptedValue; 29 30 41 public class CertOrEncCert implements DEREncodable 42 { 43 DEREncodable obj; 44 int tag; 45 46 public CertOrEncCert( DEREncodable obj, int tag ) 47 { 48 this.obj = obj; 49 this.tag = tag; 50 } 51 52 public X509CertificateStructure getCertificate() 53 { 54 if( this.tag != 0 ) 55 return null; 56 return (X509CertificateStructure)this.obj; 57 } 58 59 public EncryptedValue getEncryptedCert() 60 { 61 if( this.tag != 1 ) 62 return null; 63 return (EncryptedValue)this.obj; 64 } 65 66 public static CertOrEncCert getInstance( DERObject obj ) 67 { 68 return getInstance( (ASN1TaggedObject)obj, true ); 69 } 70 71 public static CertOrEncCert getInstance( ASN1TaggedObject tagObj, boolean explicit ) 72 { 73 int tag = tagObj.getTagNo(); 74 75 switch (tag) 76 { 77 case 0: return new CertOrEncCert(X509CertificateStructure.getInstance(tagObj.getObject()), 0); 78 case 1: return new CertOrEncCert(EncryptedValue.getInstance(tagObj.getObject()), 1); 79 } 80 81 throw new IllegalArgumentException ("unknown tag: " + tag); 82 } 83 84 public DERObject getDERObject() 85 { 86 return new DERTaggedObject(true, tag, obj); 87 } 88 89 public String toString() 90 { 91 return "CertOrEncCert: (" + obj + ")"; 92 } 93 } 94 | Popular Tags |