01: package org.bouncycastle.asn1.pkcs;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERBitString;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09: 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 extends ASN1Encodable {
22: protected CertificationRequestInfo reqInfo = null;
23: protected AlgorithmIdentifier sigAlgId = null;
24: protected DERBitString sigBits = null;
25:
26: public static CertificationRequest getInstance(Object o) {
27: if (o instanceof CertificationRequest) {
28: return (CertificationRequest) o;
29: }
30:
31: if (o instanceof ASN1Sequence) {
32: return new CertificationRequest((ASN1Sequence) o);
33: }
34:
35: throw new IllegalArgumentException("Invalid object: "
36: + o.getClass().getName());
37: }
38:
39: protected CertificationRequest() {
40: }
41:
42: public CertificationRequest(CertificationRequestInfo requestInfo,
43: AlgorithmIdentifier algorithm, DERBitString signature) {
44: this .reqInfo = requestInfo;
45: this .sigAlgId = algorithm;
46: this .sigBits = signature;
47: }
48:
49: public CertificationRequest(ASN1Sequence seq) {
50: reqInfo = CertificationRequestInfo.getInstance(seq
51: .getObjectAt(0));
52: sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
53: sigBits = (DERBitString) seq.getObjectAt(2);
54: }
55:
56: public CertificationRequestInfo getCertificationRequestInfo() {
57: return reqInfo;
58: }
59:
60: public AlgorithmIdentifier getSignatureAlgorithm() {
61: return sigAlgId;
62: }
63:
64: public DERBitString getSignature() {
65: return sigBits;
66: }
67:
68: public DERObject toASN1Object() {
69: // Construct the CertificateRequest
70: ASN1EncodableVector v = new ASN1EncodableVector();
71:
72: v.add(reqInfo);
73: v.add(sigAlgId);
74: v.add(sigBits);
75:
76: return new DERSequence(v);
77: }
78: }
|