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