001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DERBitString;
008: import org.bouncycastle.asn1.DERInteger;
009: import org.bouncycastle.asn1.DERObject;
010: import org.bouncycastle.asn1.DERSequence;
011:
012: public class AttributeCertificateInfo extends ASN1Encodable {
013: private DERInteger version;
014: private Holder holder;
015: private AttCertIssuer issuer;
016: private AlgorithmIdentifier signature;
017: private DERInteger serialNumber;
018: private AttCertValidityPeriod attrCertValidityPeriod;
019: private ASN1Sequence attributes;
020: private DERBitString issuerUniqueID;
021: private X509Extensions extensions;
022:
023: public static AttributeCertificateInfo getInstance(
024: ASN1TaggedObject obj, boolean explicit) {
025: return getInstance(ASN1Sequence.getInstance(obj, explicit));
026: }
027:
028: public static AttributeCertificateInfo getInstance(Object obj) {
029: if (obj instanceof AttributeCertificateInfo) {
030: return (AttributeCertificateInfo) obj;
031: } else if (obj instanceof ASN1Sequence) {
032: return new AttributeCertificateInfo((ASN1Sequence) obj);
033: }
034:
035: throw new IllegalArgumentException("unknown object in factory");
036: }
037:
038: public AttributeCertificateInfo(ASN1Sequence seq) {
039: if (seq.size() < 7 || seq.size() > 9) {
040: throw new IllegalArgumentException("Bad sequence size: "
041: + seq.size());
042: }
043:
044: this .version = DERInteger.getInstance(seq.getObjectAt(0));
045: this .holder = Holder.getInstance(seq.getObjectAt(1));
046: this .issuer = AttCertIssuer.getInstance(seq.getObjectAt(2));
047: this .signature = AlgorithmIdentifier.getInstance(seq
048: .getObjectAt(3));
049: this .serialNumber = DERInteger.getInstance(seq.getObjectAt(4));
050: this .attrCertValidityPeriod = AttCertValidityPeriod
051: .getInstance(seq.getObjectAt(5));
052: this .attributes = ASN1Sequence.getInstance(seq.getObjectAt(6));
053:
054: for (int i = 7; i < seq.size(); i++) {
055: ASN1Encodable obj = (ASN1Encodable) seq.getObjectAt(i);
056:
057: if (obj instanceof DERBitString) {
058: this .issuerUniqueID = DERBitString.getInstance(seq
059: .getObjectAt(i));
060: } else if (obj instanceof ASN1Sequence
061: || obj instanceof X509Extensions) {
062: this .extensions = X509Extensions.getInstance(seq
063: .getObjectAt(i));
064: }
065: }
066: }
067:
068: public DERInteger getVersion() {
069: return version;
070: }
071:
072: public Holder getHolder() {
073: return holder;
074: }
075:
076: public AttCertIssuer getIssuer() {
077: return issuer;
078: }
079:
080: public AlgorithmIdentifier getSignature() {
081: return signature;
082: }
083:
084: public DERInteger getSerialNumber() {
085: return serialNumber;
086: }
087:
088: public AttCertValidityPeriod getAttrCertValidityPeriod() {
089: return attrCertValidityPeriod;
090: }
091:
092: public ASN1Sequence getAttributes() {
093: return attributes;
094: }
095:
096: public DERBitString getIssuerUniqueID() {
097: return issuerUniqueID;
098: }
099:
100: public X509Extensions getExtensions() {
101: return extensions;
102: }
103:
104: /**
105: * Produce an object suitable for an ASN1OutputStream.
106: * <pre>
107: * AttributeCertificateInfo ::= SEQUENCE {
108: * version AttCertVersion -- version is v2,
109: * holder Holder,
110: * issuer AttCertIssuer,
111: * signature AlgorithmIdentifier,
112: * serialNumber CertificateSerialNumber,
113: * attrCertValidityPeriod AttCertValidityPeriod,
114: * attributes SEQUENCE OF Attribute,
115: * issuerUniqueID UniqueIdentifier OPTIONAL,
116: * extensions Extensions OPTIONAL
117: * }
118: *
119: * AttCertVersion ::= INTEGER { v2(1) }
120: * </pre>
121: */
122: public DERObject toASN1Object() {
123: ASN1EncodableVector v = new ASN1EncodableVector();
124:
125: v.add(version);
126: v.add(holder);
127: v.add(issuer);
128: v.add(signature);
129: v.add(serialNumber);
130: v.add(attrCertValidityPeriod);
131: v.add(attributes);
132:
133: if (issuerUniqueID != null) {
134: v.add(issuerUniqueID);
135: }
136:
137: if (extensions != null) {
138: v.add(extensions);
139: }
140:
141: return new DERSequence(v);
142: }
143: }
|