1 20 package com.novosec.pkix.asn1.crmf; 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 32 43 public class CertReqMsg implements DEREncodable 44 { 45 CertRequest certReq; 46 ProofOfPossession pop; 47 Vector regInfos = new Vector (); 48 49 public static CertReqMsg getInstance( ASN1TaggedObject obj, boolean explicit ) 50 { 51 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 52 } 53 54 public static CertReqMsg getInstance( Object obj ) 55 { 56 if (obj instanceof CertReqMsg) 57 { 58 return (CertReqMsg)obj; 59 } 60 else if (obj instanceof ASN1Sequence) 61 { 62 return new CertReqMsg((ASN1Sequence)obj); 63 } 64 65 throw new IllegalArgumentException ("unknown object in factory"); 66 } 67 68 public CertReqMsg( ASN1Sequence seq ) 69 { 70 Enumeration e = seq.getObjects(); 71 this.certReq = CertRequest.getInstance(e.nextElement()); 72 73 Object obj = null; 74 75 if( e.hasMoreElements() ) 76 obj = e.nextElement(); 77 78 if( obj instanceof ASN1TaggedObject ) 79 { 80 this.pop = ProofOfPossession.getInstance((ASN1TaggedObject)obj); 81 82 if( e.hasMoreElements() ) 83 obj = e.nextElement(); 84 } 85 86 if( obj instanceof ASN1Sequence ) 87 { 88 ASN1Sequence s = (ASN1Sequence)obj; 89 for( int i=0; i<s.size(); i++ ) 90 regInfos.addElement( AttributeTypeAndValue.getInstance(s.getObjectAt(i)) ); 91 } 92 } 93 94 public CertReqMsg( CertRequest certReq ) 95 { 96 this.certReq = certReq; 97 } 98 99 public CertRequest getCertReq() 100 { 101 return certReq; 102 } 103 104 public ProofOfPossession getPop() 105 { 106 return pop; 107 } 108 109 public void setPop( ProofOfPossession pop ) 110 { 111 this.pop = pop; 112 } 113 114 public AttributeTypeAndValue getRegInfo(int nr) 115 { 116 if( regInfos.size() > nr ) 117 return (AttributeTypeAndValue)regInfos.elementAt(nr); 118 119 return null; 120 } 121 122 public void addRegInfo(AttributeTypeAndValue regInfo) 123 { 124 regInfos.addElement( regInfo ); 125 } 126 127 public DERObject getDERObject() 128 { 129 ASN1EncodableVector v = new ASN1EncodableVector(); 130 131 v.add( certReq ); 132 133 if( pop != null ) 134 v.add( pop ); 135 136 if( regInfos.size() > 0 ) 137 { 138 ASN1EncodableVector regiv = new ASN1EncodableVector(); 139 for (int i=0;i<regInfos.size();i++) 140 regiv.add( (AttributeTypeAndValue)regInfos.elementAt(i) ); 141 142 v.add( new DERSequence( regiv ) ); 143 } 144 145 return new DERSequence(v); 146 } 147 148 public String toString() 149 { 150 String s = "CertReqMsg: (certReq = " + this.getCertReq() + ", "; 151 152 if( this.getPop() != null ) 153 s += "pop: " + this.getPop() + ", "; 154 155 if( regInfos.size() > 0 ) 156 { 157 s += "regInfo : ("; 158 159 for (int i=0;i<regInfos.size();i++) 160 s += (AttributeTypeAndValue)regInfos.elementAt(i); 161 162 s += ")"; 163 } 164 165 s += ")"; 166 167 return s; 168 } 169 } 170 | Popular Tags |