1 package org.bouncycastle.asn1.pkcs; 2 3 import org.bouncycastle.asn1.ASN1EncodableVector; 4 import org.bouncycastle.asn1.ASN1Object; 5 import org.bouncycastle.asn1.ASN1Primitive; 6 import org.bouncycastle.asn1.ASN1Sequence; 7 import org.bouncycastle.asn1.DERBitString; 8 import org.bouncycastle.asn1.DERSequence; 9 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 10 11 /** 12 * PKCS10 Certification request object. 13 * <pre> 14 * CertificationRequest ::= SEQUENCE { 15 * certificationRequestInfo CertificationRequestInfo, 16 * signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, 17 * signature BIT STRING 18 * } 19 * </pre> 20 */ 21 public class CertificationRequest 22 extends ASN1Object 23 { 24 protected CertificationRequestInfo reqInfo = null; 25 protected AlgorithmIdentifier sigAlgId = null; 26 protected DERBitString sigBits = null; 27 getInstance(Object o)28 public static CertificationRequest getInstance(Object o) 29 { 30 if (o instanceof CertificationRequest) 31 { 32 return (CertificationRequest)o; 33 } 34 35 if (o != null) 36 { 37 return new CertificationRequest(ASN1Sequence.getInstance(o)); 38 } 39 40 return null; 41 } 42 CertificationRequest()43 protected CertificationRequest() 44 { 45 } 46 CertificationRequest( CertificationRequestInfo requestInfo, AlgorithmIdentifier algorithm, DERBitString signature)47 public CertificationRequest( 48 CertificationRequestInfo requestInfo, 49 AlgorithmIdentifier algorithm, 50 DERBitString signature) 51 { 52 this.reqInfo = requestInfo; 53 this.sigAlgId = algorithm; 54 this.sigBits = signature; 55 } 56 CertificationRequest( ASN1Sequence seq)57 public CertificationRequest( 58 ASN1Sequence seq) 59 { 60 reqInfo = CertificationRequestInfo.getInstance(seq.getObjectAt(0)); 61 sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 62 sigBits = (DERBitString)seq.getObjectAt(2); 63 } 64 getCertificationRequestInfo()65 public CertificationRequestInfo getCertificationRequestInfo() 66 { 67 return reqInfo; 68 } 69 getSignatureAlgorithm()70 public AlgorithmIdentifier getSignatureAlgorithm() 71 { 72 return sigAlgId; 73 } 74 getSignature()75 public DERBitString getSignature() 76 { 77 return sigBits; 78 } 79 toASN1Primitive()80 public ASN1Primitive toASN1Primitive() 81 { 82 // Construct the CertificateRequest 83 ASN1EncodableVector v = new ASN1EncodableVector(); 84 85 v.add(reqInfo); 86 v.add(sigAlgId); 87 v.add(sigBits); 88 89 return new DERSequence(v); 90 } 91 } 92