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 47 public class KeyRecRepContent implements DEREncodable 48 { 49 PKIStatusInfo status; 50 X509CertificateStructure newSigCert; 51 Vector caCerts = new Vector (); 52 Vector keyPairHists = new Vector (); 53 54 public static KeyRecRepContent getInstance(ASN1TaggedObject obj, boolean explicit) 55 { 56 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 57 } 58 59 public static KeyRecRepContent getInstance(Object obj) 60 { 61 if (obj instanceof KeyRecRepContent) 62 { 63 return (KeyRecRepContent) obj; 64 } 65 else if (obj instanceof ASN1Sequence) 66 { 67 return new KeyRecRepContent((ASN1Sequence) obj); 68 } 69 70 throw new IllegalArgumentException ("unknown object in factory"); 71 } 72 73 public KeyRecRepContent(ASN1Sequence seq) 74 { 75 Enumeration e = seq.getObjects(); 76 77 status = PKIStatusInfo.getInstance(e.nextElement()); 78 79 while (e.hasMoreElements()) 80 { 81 ASN1TaggedObject tagObj = (ASN1TaggedObject) e.nextElement(); 82 83 switch (tagObj.getTagNo()) 84 { 85 case 0 : 86 newSigCert = X509CertificateStructure.getInstance(tagObj.getObject()); 87 break; 88 case 1 : 89 { 90 ASN1Sequence s = (ASN1Sequence) tagObj.getObject(); 91 for (int i = 0; i < s.size(); i++) 92 caCerts.addElement(X509CertificateStructure.getInstance(s.getObjectAt(i))); 93 } 94 break; 95 case 2 : 96 { 97 ASN1Sequence s = (ASN1Sequence) tagObj.getObject(); 98 for (int i = 0; i < s.size(); i++) 99 keyPairHists.addElement(CertifiedKeyPair.getInstance(s.getObjectAt(i))); 100 } 101 break; 102 } 103 } 104 } 105 106 public KeyRecRepContent(PKIStatusInfo status) 107 { 108 this.status = status; 109 } 110 111 public PKIStatusInfo getStatus() 112 { 113 return status; 114 } 115 116 public X509CertificateStructure getNewSigCert() 117 { 118 return newSigCert; 119 } 120 121 public void setNewSigCert(X509CertificateStructure newSigCert) 122 { 123 this.newSigCert = newSigCert; 124 } 125 126 public void addCaCerts(X509CertificateStructure caCert) 127 { 128 caCerts.addElement(caCert); 129 } 130 131 public X509CertificateStructure getCaCerts(int nr) 132 { 133 if (nr < caCerts.size()) 134 return (X509CertificateStructure) caCerts.elementAt(nr); 135 136 return null; 137 } 138 139 public void addKeyPairHist(CertifiedKeyPair keyPairHist) 140 { 141 keyPairHists.addElement(keyPairHist); 142 } 143 144 public CertifiedKeyPair getKeyPairHist(int nr) 145 { 146 if (nr < keyPairHists.size()) 147 return (CertifiedKeyPair) keyPairHists.elementAt(nr); 148 149 return null; 150 } 151 152 public DERObject getDERObject() 153 { 154 ASN1EncodableVector v = new ASN1EncodableVector(); 155 156 v.add(status); 157 158 if (newSigCert != null) 159 v.add(new DERTaggedObject(true, 0, newSigCert)); 160 161 if (caCerts.size() > 0) 162 { 163 ASN1EncodableVector cacv = new ASN1EncodableVector(); 164 165 for (int i = 0; i < caCerts.size(); i++) 166 cacv.add((X509CertificateStructure) caCerts.elementAt(i)); 167 168 v.add(new DERTaggedObject(true, 1, new DERSequence(cacv))); 169 } 170 171 if (keyPairHists.size() > 0) 172 { 173 ASN1EncodableVector keyphv = new ASN1EncodableVector(); 174 175 for (int i = 0; i < keyPairHists.size(); i++) 176 keyphv.add((CertifiedKeyPair) keyPairHists.elementAt(i)); 177 178 v.add(new DERTaggedObject(true, 2, new DERSequence(keyphv))); 179 } 180 181 return new DERSequence(v); 182 } 183 184 public String toString() 185 { 186 String s = "CertifiedKeyPair: ( status: " + this.getStatus() + ", "; 187 188 if( this.getNewSigCert() != null ) 189 s += "newSigCert: "+ this.getNewSigCert() + ", "; 190 191 if( caCerts.size() > 0 ) 192 { 193 s += "caCerts: ("; 194 195 for( int i=0; i<caCerts.size(); i++ ) 196 s += (X509CertificateStructure)caCerts.elementAt(i); 197 198 s += "), "; 199 } 200 201 if( keyPairHists.size() > 0 ) 202 { 203 s += "keyPairHist: ("; 204 205 for( int i=0; i<caCerts.size(); i++ ) 206 s += (CertifiedKeyPair)keyPairHists.elementAt(i); 207 208 s += ")"; 209 } 210 211 s += ")"; 212 213 return s; 214 } 215 } 216 | Popular Tags |