01: package org.bouncycastle.asn1.crmf;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERInteger;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09:
10: public class CertRequest extends ASN1Encodable {
11: private DERInteger certReqId;
12: private CertTemplate certTemplate;
13: private Controls controls;
14:
15: private CertRequest(ASN1Sequence seq) {
16: certReqId = DERInteger.getInstance(seq.getObjectAt(0));
17: certTemplate = CertTemplate.getInstance(seq.getObjectAt(1));
18: controls = Controls.getInstance(seq.getObjectAt(2));
19: }
20:
21: public static CertRequest getInstance(Object o) {
22: if (o instanceof CertRequest) {
23: return (CertRequest) o;
24: }
25:
26: if (o instanceof ASN1Sequence) {
27: return new CertRequest((ASN1Sequence) o);
28: }
29:
30: throw new IllegalArgumentException("Invalid object: "
31: + o.getClass().getName());
32: }
33:
34: public DERInteger getCertReqId() {
35: return certReqId;
36: }
37:
38: public CertTemplate getCertTemplate() {
39: return certTemplate;
40: }
41:
42: public Controls getControls() {
43: return controls;
44: }
45:
46: /**
47: * <pre>
48: * CertRequest ::= SEQUENCE {
49: * certReqId INTEGER, -- ID for matching request and reply
50: * certTemplate CertTemplate, -- Selected fields of cert to be issued
51: * controls Controls OPTIONAL } -- Attributes affecting issuance
52: * </pre>
53: * @return a basic ASN.1 object representation.
54: */
55: public DERObject toASN1Object() {
56: ASN1EncodableVector v = new ASN1EncodableVector();
57:
58: v.add(certReqId);
59: v.add(certTemplate);
60:
61: if (controls != null) {
62: v.add(controls);
63: }
64:
65: return new DERSequence(v);
66: }
67: }
|