1 20 package com.novosec.pkix.asn1.crmf; 21 22 import java.util.Vector ; 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.DERSequence; 31 32 43 public class CertRequest implements DEREncodable 44 { 45 DERInteger certReqId; 46 CertTemplate certTemplate; 47 Vector controls = new Vector (); 48 49 public static CertRequest getInstance( ASN1TaggedObject obj, boolean explicit ) 50 { 51 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 52 } 53 54 public static CertRequest getInstance( Object obj ) 55 { 56 if (obj instanceof CertRequest) 57 { 58 return (CertRequest)obj; 59 } 60 else if (obj instanceof ASN1Sequence) 61 { 62 return new CertRequest((ASN1Sequence)obj); 63 } 64 65 throw new IllegalArgumentException ("unknown object in factory"); 66 } 67 68 public CertRequest( ASN1Sequence seq ) 69 { 70 this.certReqId = DERInteger.getInstance(seq.getObjectAt(0)); 71 this.certTemplate = CertTemplate.getInstance(seq.getObjectAt(1)); 72 if( seq.size()>2 ) 73 { 74 ASN1Sequence s = (ASN1Sequence)seq.getObjectAt(2); 75 for( int i=0; i<s.size(); i++ ) 76 controls.addElement( AttributeTypeAndValue.getInstance(s.getObjectAt(i)) ); 77 } 78 } 79 80 public CertRequest( DERInteger certReqId, CertTemplate certTemplate ) 81 { 82 this.certReqId = certReqId; 83 this.certTemplate = certTemplate; 84 } 85 86 public DERInteger getCertReqId() 87 { 88 return certReqId; 89 } 90 91 public CertTemplate getCertTemplate() 92 { 93 return certTemplate; 94 } 95 96 public AttributeTypeAndValue getControls(int nr) 97 { 98 if( controls.size() > nr ) 99 return (AttributeTypeAndValue)controls.elementAt(nr); 100 101 return null; 102 } 103 104 public void addControls(AttributeTypeAndValue control) 105 { 106 controls.addElement( control ); 107 } 108 109 public DERObject getDERObject() 110 { 111 ASN1EncodableVector v = new ASN1EncodableVector(); 112 113 v.add( certReqId ); 114 v.add( certTemplate ); 115 116 if( controls.size() > 0 ) 117 { 118 ASN1EncodableVector pubiv = new ASN1EncodableVector(); 119 for (int i=0;i<controls.size();i++) 120 pubiv.add( (AttributeTypeAndValue)controls.elementAt(i) ); 121 122 v.add( new DERSequence( pubiv ) ); 123 } 124 125 return new DERSequence(v); 126 } 127 128 public String toString() 129 { 130 String s = "CertRequest: (certReqId = " + this.getCertReqId() + ", "; 131 132 s += "certTemplate: " + this.getCertTemplate() + ", "; 133 134 if( controls.size() > 0 ) 135 { 136 s += "controls : ("; 137 138 for (int i=0;i<controls.size();i++) 139 s += (AttributeTypeAndValue)controls.elementAt(i); 140 141 s += ")"; 142 } 143 144 s += ")"; 145 146 return s; 147 } 148 } 149 | Popular Tags |