1 20 package com.novosec.pkix.asn1.cmp; 21 22 import java.util.Enumeration ; 23 24 import org.bouncycastle.asn1.ASN1EncodableVector; 25 import org.bouncycastle.asn1.ASN1Sequence; 26 import org.bouncycastle.asn1.ASN1TaggedObject; 27 import org.bouncycastle.asn1.DEREncodable; 28 import org.bouncycastle.asn1.DERObject; 29 import org.bouncycastle.asn1.DERSequence; 30 import org.bouncycastle.asn1.DERTaggedObject; 31 32 import com.novosec.pkix.asn1.crmf.EncryptedValue; 33 import com.novosec.pkix.asn1.crmf.PKIPublicationInfo; 34 35 47 public class CertifiedKeyPair implements DEREncodable 48 { 49 CertOrEncCert certOrEncCert; 50 EncryptedValue privateKey; 51 PKIPublicationInfo publicationInfo; 52 53 public static CertifiedKeyPair getInstance( ASN1TaggedObject obj, boolean explicit ) 54 { 55 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 56 } 57 58 public static CertifiedKeyPair getInstance( Object obj ) 59 { 60 if (obj instanceof CertifiedKeyPair) 61 { 62 return (CertifiedKeyPair)obj; 63 } 64 else if (obj instanceof ASN1Sequence) 65 { 66 return new CertifiedKeyPair((ASN1Sequence)obj); 67 } 68 69 throw new IllegalArgumentException ("unknown object in factory"); 70 } 71 72 public CertifiedKeyPair( ASN1Sequence seq ) 73 { 74 Enumeration e = seq.getObjects(); 75 76 certOrEncCert = CertOrEncCert.getInstance( (DERObject)e.nextElement() ); 77 78 while (e.hasMoreElements()) 79 { 80 ASN1TaggedObject tagObj = (ASN1TaggedObject)e.nextElement(); 81 82 switch (tagObj.getTagNo()) 83 { 84 case 0: privateKey = EncryptedValue.getInstance( tagObj.getObject() ); break; 85 case 1: publicationInfo = PKIPublicationInfo.getInstance( tagObj.getObject() ); break; 86 } 87 } 88 } 89 90 public CertifiedKeyPair( CertOrEncCert certOrEncCert ) 91 { 92 this.certOrEncCert = certOrEncCert; 93 } 94 95 public CertOrEncCert getCertOrEncCert() 96 { 97 return certOrEncCert; 98 } 99 100 public void setPrivateKey( EncryptedValue privateKey ) 101 { 102 this.privateKey = privateKey; 103 } 104 105 public EncryptedValue getPrivateKey() 106 { 107 return privateKey; 108 } 109 110 public void setPublicationInfo( PKIPublicationInfo publicationInfo ) 111 { 112 this.publicationInfo = publicationInfo; 113 } 114 115 public PKIPublicationInfo getPublicationInfo() 116 { 117 return publicationInfo; 118 } 119 120 public DERObject getDERObject() 121 { 122 ASN1EncodableVector v = new ASN1EncodableVector(); 123 124 v.add( certOrEncCert ); 125 126 if( privateKey != null ) 127 v.add( new DERTaggedObject( true, 0, privateKey ) ); 128 129 if( publicationInfo != null ) 130 v.add( new DERTaggedObject( true, 1, publicationInfo ) ); 131 132 return new DERSequence(v); 133 } 134 135 public String toString() 136 { 137 String s = "CertifiedKeyPair: ( certOrEncCert: " + this.getCertOrEncCert() + ", "; 138 139 if( this.getPrivateKey() != null ) 140 s += "privateKey: "+ this.getPrivateKey() + ", "; 141 142 if( this.getPublicationInfo() != null ) 143 s += "publicationInfo: "+ this.getPublicationInfo() + ", "; 144 145 s += ")"; 146 147 return s; 148 } 149 } 150 | Popular Tags |