01: package org.bouncycastle.asn1.ess;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERSequence;
08: import org.bouncycastle.asn1.x509.PolicyInformation;
09:
10: public class SigningCertificate extends ASN1Encodable {
11: ASN1Sequence certs;
12: ASN1Sequence policies;
13:
14: public static SigningCertificate getInstance(Object o) {
15: if (o == null || o instanceof SigningCertificate) {
16: return (SigningCertificate) o;
17: } else if (o instanceof ASN1Sequence) {
18: return new SigningCertificate((ASN1Sequence) o);
19: }
20:
21: throw new IllegalArgumentException(
22: "unknown object in 'SigningCertificate' factory : "
23: + o.getClass().getName() + ".");
24: }
25:
26: /**
27: * constructeurs
28: */
29: public SigningCertificate(ASN1Sequence seq) {
30: if (seq.size() < 1 || seq.size() > 2) {
31: throw new IllegalArgumentException("Bad sequence size: "
32: + seq.size());
33: }
34: this .certs = ASN1Sequence.getInstance(seq.getObjectAt(0));
35:
36: if (seq.size() > 1) {
37: this .policies = ASN1Sequence
38: .getInstance(seq.getObjectAt(1));
39: }
40: }
41:
42: public SigningCertificate(ESSCertID essCertID) {
43: certs = new DERSequence(essCertID);
44: }
45:
46: public ESSCertID[] getCerts() {
47: ESSCertID[] cs = new ESSCertID[certs.size()];
48:
49: for (int i = 0; i != certs.size(); i++) {
50: cs[i] = ESSCertID.getInstance(certs.getObjectAt(i));
51: }
52:
53: return cs;
54: }
55:
56: public PolicyInformation[] getPolicies() {
57: if (policies == null) {
58: return null;
59: }
60:
61: PolicyInformation[] ps = new PolicyInformation[policies.size()];
62:
63: for (int i = 0; i != policies.size(); i++) {
64: ps[i] = PolicyInformation.getInstance(policies
65: .getObjectAt(i));
66: }
67:
68: return ps;
69: }
70:
71: /**
72: * The definition of SigningCertificate is
73: * <pre>
74: * SigningCertificate ::= SEQUENCE {
75: * certs SEQUENCE OF ESSCertID,
76: * policies SEQUENCE OF PolicyInformation OPTIONAL
77: * }
78: * </pre>
79: * id-aa-signingCertificate OBJECT IDENTIFIER ::= { iso(1)
80: * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9)
81: * smime(16) id-aa(2) 12 }
82: */
83: public DERObject toASN1Object() {
84: ASN1EncodableVector v = new ASN1EncodableVector();
85:
86: v.add(certs);
87:
88: if (policies != null) {
89: v.add(policies);
90: }
91:
92: return new DERSequence(v);
93: }
94: }
|