1 20 package com.novosec.pkix.asn1.cmp; 21 22 import java.util.Enumeration ; 23 import java.util.Vector ; 24 25 import org.bouncycastle.asn1.ASN1EncodableVector; 26 import org.bouncycastle.asn1.ASN1Sequence; 27 import org.bouncycastle.asn1.ASN1TaggedObject; 28 import org.bouncycastle.asn1.DEREncodable; 29 import org.bouncycastle.asn1.DERObject; 30 import org.bouncycastle.asn1.DERSequence; 31 import org.bouncycastle.asn1.DERTaggedObject; 32 import org.bouncycastle.asn1.x509.X509CertificateStructure; 33 34 45 public class CertRepMessage implements DEREncodable 46 { 47 Vector caPubs = new Vector (); 48 Vector responses = new Vector (); 49 50 public static CertRepMessage getInstance( ASN1TaggedObject obj, boolean explicit ) 51 { 52 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 53 } 54 55 public static CertRepMessage getInstance( Object obj ) 56 { 57 if (obj instanceof CertRepMessage) 58 { 59 return (CertRepMessage)obj; 60 } 61 else if (obj instanceof ASN1Sequence) 62 { 63 return new CertRepMessage((ASN1Sequence)obj); 64 } 65 66 throw new IllegalArgumentException ("unknown object in factory"); 67 } 68 69 public CertRepMessage( ASN1Sequence seq ) 70 { 71 Enumeration e = seq.getObjects(); 72 73 Object obj = e.nextElement(); 74 75 if( obj instanceof ASN1TaggedObject ) 76 { 77 ASN1Sequence s = (ASN1Sequence)(((ASN1TaggedObject)obj).getObject()); 78 79 for (int i=0;i<s.size();i++) 80 caPubs.add(X509CertificateStructure.getInstance(s.getObjectAt(i))); 81 82 obj = e.nextElement(); 83 } 84 85 ASN1Sequence s = (ASN1Sequence)obj; 86 87 for (int i=0;i<s.size();i++) 88 responses.add(CertResponse.getInstance(s.getObjectAt(i))); 89 } 90 91 public CertRepMessage( CertResponse response ) 92 { 93 responses.addElement(response); 94 } 95 96 public void addCaPubs( X509CertificateStructure caPub ) 97 { 98 caPubs.addElement(caPub); 99 } 100 101 public X509CertificateStructure getCaPubs( int nr ) 102 { 103 if( nr<caPubs.size() ) 104 return (X509CertificateStructure)caPubs.elementAt(nr); 105 106 return null; 107 } 108 109 public void addResponse( CertResponse response ) 110 { 111 responses.addElement(response); 112 } 113 114 public CertResponse getResponse( int nr ) 115 { 116 if( nr<responses.size() ) 117 return (CertResponse)responses.elementAt(nr); 118 119 return null; 120 } 121 122 public DERObject getDERObject() 123 { 124 ASN1EncodableVector v = new ASN1EncodableVector(); 125 126 if( caPubs.size() > 0 ) 127 { 128 ASN1EncodableVector capv = new ASN1EncodableVector(); 129 130 for( int i=0; i<caPubs.size(); i++ ) 131 capv.add( (X509CertificateStructure)caPubs.elementAt(i) ); 132 133 v.add( new DERTaggedObject( true, 1, new DERSequence(capv) ) ); 134 } 135 136 ASN1EncodableVector resp = new ASN1EncodableVector(); 137 138 for( int i=0; i<responses.size(); i++ ) 139 resp.add( (CertResponse)responses.elementAt(i) ); 140 141 v.add( new DERSequence(resp) ); 142 143 return new DERSequence(v); 144 } 145 146 public String toString() 147 { 148 String s = "CertRepMessage: ( "; 149 150 if( caPubs.size() > 0 ) 151 { 152 s += "caPubs: ("; 153 154 for( int i=0; i<caPubs.size(); i++ ) 155 s += (X509CertificateStructure)caPubs.elementAt(i); 156 157 s += "), "; 158 } 159 160 s += "responses: ("; 161 162 for( int i=0; i<responses.size(); i++ ) 163 s += (CertResponse)responses.elementAt(i); 164 165 s += ")"; 166 167 return s; 168 } 169 } 170 | Popular Tags |