1 17 18 package org.apache.geronimo.util.asn1.pkcs; 19 20 import org.apache.geronimo.util.asn1.ASN1Encodable; 21 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 22 import org.apache.geronimo.util.asn1.ASN1Sequence; 23 import org.apache.geronimo.util.asn1.ASN1Set; 24 import org.apache.geronimo.util.asn1.DERInteger; 25 import org.apache.geronimo.util.asn1.DERObject; 26 import org.apache.geronimo.util.asn1.DERSequence; 27 import org.apache.geronimo.util.asn1.DERTaggedObject; 28 import org.apache.geronimo.util.asn1.x509.SubjectPublicKeyInfo; 29 import org.apache.geronimo.util.asn1.x509.X509Name; 30 31 49 public class CertificationRequestInfo 50 extends ASN1Encodable 51 { 52 DERInteger version = new DERInteger(0); 53 X509Name subject; 54 SubjectPublicKeyInfo subjectPKInfo; 55 ASN1Set attributes = null; 56 57 public static CertificationRequestInfo getInstance( 58 Object obj) 59 { 60 if (obj instanceof CertificationRequestInfo) 61 { 62 return (CertificationRequestInfo)obj; 63 } 64 else if (obj instanceof ASN1Sequence) 65 { 66 return new CertificationRequestInfo((ASN1Sequence)obj); 67 } 68 69 throw new IllegalArgumentException ("unknown object in factory"); 70 } 71 72 public CertificationRequestInfo( 73 X509Name subject, 74 SubjectPublicKeyInfo pkInfo, 75 ASN1Set attributes) 76 { 77 this.subject = subject; 78 this.subjectPKInfo = pkInfo; 79 this.attributes = attributes; 80 81 if ((subject == null) || (version == null) || (subjectPKInfo == null)) 82 { 83 throw new IllegalArgumentException ("Not all mandatory fields set in CertificationRequestInfo generator."); 84 } 85 } 86 87 public CertificationRequestInfo( 88 ASN1Sequence seq) 89 { 90 version = (DERInteger)seq.getObjectAt(0); 91 92 subject = X509Name.getInstance(seq.getObjectAt(1)); 93 subjectPKInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(2)); 94 95 if (seq.size() > 3) 100 { 101 DERTaggedObject tagobj = (DERTaggedObject)seq.getObjectAt(3); 102 attributes = ASN1Set.getInstance(tagobj, false); 103 } 104 105 if ((subject == null) || (version == null) || (subjectPKInfo == null)) 106 { 107 throw new IllegalArgumentException ("Not all mandatory fields set in CertificationRequestInfo generator."); 108 } 109 } 110 111 public DERInteger getVersion() 112 { 113 return version; 114 } 115 116 public X509Name getSubject() 117 { 118 return subject; 119 } 120 121 public SubjectPublicKeyInfo getSubjectPublicKeyInfo() 122 { 123 return subjectPKInfo; 124 } 125 126 public ASN1Set getAttributes() 127 { 128 return attributes; 129 } 130 131 public DERObject toASN1Object() 132 { 133 ASN1EncodableVector v = new ASN1EncodableVector(); 134 135 v.add(version); 136 v.add(subject); 137 v.add(subjectPKInfo); 138 139 if (attributes != null) 140 { 141 v.add(new DERTaggedObject(false, 0, attributes)); 142 } 143 144 return new DERSequence(v); 145 } 146 } 147 | Popular Tags |