001: package org.bouncycastle.asn1.ess;
002:
003: import org.bouncycastle.asn1.*;
004: import org.bouncycastle.asn1.x509.PolicyInformation;
005:
006: public class SigningCertificateV2 extends ASN1Encodable {
007: ASN1Sequence certs;
008: ASN1Sequence policies;
009:
010: public static SigningCertificateV2 getInstance(Object o) {
011: if (o == null || o instanceof SigningCertificateV2) {
012: return (SigningCertificateV2) o;
013: } else if (o instanceof ASN1Sequence) {
014: return new SigningCertificateV2((ASN1Sequence) o);
015: }
016:
017: throw new IllegalArgumentException(
018: "unknown object in 'SigningCertificateV2' factory : "
019: + o.getClass().getName() + ".");
020: }
021:
022: public SigningCertificateV2(ASN1Sequence seq) {
023: if (seq.size() < 1 || seq.size() > 2) {
024: throw new IllegalArgumentException("Bad sequence size: "
025: + seq.size());
026: }
027:
028: this .certs = ASN1Sequence.getInstance(seq.getObjectAt(0));
029:
030: if (seq.size() > 1) {
031: this .policies = ASN1Sequence
032: .getInstance(seq.getObjectAt(1));
033: }
034: }
035:
036: public SigningCertificateV2(ESSCertIDv2[] certs) {
037: ASN1EncodableVector v = new ASN1EncodableVector();
038: for (int i = 0; i < certs.length; i++) {
039: v.add(certs[i]);
040: }
041: this .certs = new DERSequence(v);
042: }
043:
044: public SigningCertificateV2(ESSCertIDv2[] certs,
045: PolicyInformation[] policies) {
046: ASN1EncodableVector v = new ASN1EncodableVector();
047: for (int i = 0; i < certs.length; i++) {
048: v.add(certs[i]);
049: }
050: this .certs = new DERSequence(v);
051:
052: if (policies != null) {
053: v = new ASN1EncodableVector();
054: for (int i = 0; i < policies.length; i++) {
055: v.add(policies[i]);
056: }
057: this .policies = new DERSequence(v);
058: }
059: }
060:
061: public ESSCertIDv2[] getCerts() {
062: ESSCertIDv2[] certIds = new ESSCertIDv2[certs.size()];
063: for (int i = 0; i != certs.size(); i++) {
064: certIds[i] = ESSCertIDv2.getInstance(certs.getObjectAt(i));
065: }
066: return certIds;
067: }
068:
069: public PolicyInformation[] getPolicies() {
070: if (policies == null) {
071: return null;
072: }
073:
074: PolicyInformation[] policyInformations = new PolicyInformation[policies
075: .size()];
076: for (int i = 0; i != policies.size(); i++) {
077: policyInformations[i] = PolicyInformation
078: .getInstance(policies.getObjectAt(i));
079: }
080: return policyInformations;
081: }
082:
083: /**
084: * The definition of SigningCertificateV2 is
085: * <pre>
086: * SigningCertificateV2 ::= SEQUENCE {
087: * certs SEQUENCE OF ESSCertIDv2,
088: * policies SEQUENCE OF PolicyInformation OPTIONAL
089: * }
090: * </pre>
091: * id-aa-signingCertificateV2 OBJECT IDENTIFIER ::= { iso(1)
092: * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9)
093: * smime(16) id-aa(2) 47 }
094: */
095: public DERObject toASN1Object() {
096: ASN1EncodableVector v = new ASN1EncodableVector();
097:
098: v.add(certs);
099:
100: if (policies != null) {
101: v.add(policies);
102: }
103:
104: return new DERSequence(v);
105: }
106: }
|