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.DERInteger; 29 import org.bouncycastle.asn1.DERObject; 30 import org.bouncycastle.asn1.DEROctetString; 31 import org.bouncycastle.asn1.DERSequence; 32 33 46 public class CertResponse implements DEREncodable 47 { 48 DERInteger certReqId; 49 PKIStatusInfo status; 50 CertifiedKeyPair certifiedKeyPair; 51 DEROctetString rspInfo; 52 53 public static CertResponse getInstance( ASN1TaggedObject obj, boolean explicit ) 54 { 55 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 56 } 57 58 public static CertResponse getInstance( Object obj ) 59 { 60 if (obj instanceof CertResponse) 61 { 62 return (CertResponse)obj; 63 } 64 else if (obj instanceof ASN1Sequence) 65 { 66 return new CertResponse((ASN1Sequence)obj); 67 } 68 69 throw new IllegalArgumentException ("unknown object in factory"); 70 } 71 72 public CertResponse( ASN1Sequence seq ) 73 { 74 Enumeration e = seq.getObjects(); 75 76 certReqId = DERInteger.getInstance( e.nextElement() ); 77 status = PKIStatusInfo.getInstance( e.nextElement() ); 78 79 Object obj = null; 80 81 if( e.hasMoreElements() ) 82 obj = e.nextElement(); 83 84 if ( obj instanceof ASN1Sequence ) 85 { 86 certifiedKeyPair = CertifiedKeyPair.getInstance( obj ); 87 88 if( e.hasMoreElements() ) 89 obj = e.nextElement(); 90 } 91 92 if( obj instanceof DEROctetString ) 93 rspInfo = (DEROctetString)obj; 94 } 95 96 public CertResponse( DERInteger certReqId, PKIStatusInfo status ) 97 { 98 this.certReqId = certReqId; 99 this.status = status; 100 } 101 102 public DERInteger getCertReqId() 103 { 104 return certReqId; 105 } 106 107 public PKIStatusInfo getStatus() 108 { 109 return status; 110 } 111 112 public void setCertifiedKeyPair( CertifiedKeyPair certifiedKeyPair ) 113 { 114 this.certifiedKeyPair = certifiedKeyPair; 115 } 116 117 public CertifiedKeyPair getCertifiedKeyPair() 118 { 119 return certifiedKeyPair; 120 } 121 122 public void setRspInfo( DEROctetString rspInfo ) 123 { 124 this.rspInfo = rspInfo; 125 } 126 127 public DEROctetString getRspInfo() 128 { 129 return rspInfo; 130 } 131 132 public DERObject getDERObject() 133 { 134 ASN1EncodableVector v = new ASN1EncodableVector(); 135 136 v.add( certReqId ); 137 v.add( status ); 138 139 if( certifiedKeyPair != null ) 140 v.add( certifiedKeyPair ); 141 142 if( rspInfo != null ) 143 v.add( rspInfo ); 144 145 return new DERSequence(v); 146 } 147 148 public String toString() 149 { 150 String s = "CertResponse: ( certReqId: " + this.getCertReqId() + ", status: "+ this.getStatus() + ", "; 151 152 if( this.getCertifiedKeyPair() != null ) 153 s += "certifiedKeyPair: "+ this.getCertifiedKeyPair() + ", "; 154 155 if( this.getRspInfo() != null ) 156 s += "rspInfo: "+ this.getRspInfo() + ", "; 157 158 s += ")"; 159 160 return s; 161 } 162 } 163 | Popular Tags |