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.DERObject;
008: import org.bouncycastle.asn1.DERSequence;
009: import org.bouncycastle.asn1.DERTaggedObject;
010:
011: public class V2Form extends ASN1Encodable {
012: GeneralNames issuerName;
013: IssuerSerial baseCertificateID;
014: ObjectDigestInfo objectDigestInfo;
015:
016: public static V2Form getInstance(ASN1TaggedObject obj,
017: boolean explicit) {
018: return getInstance(ASN1Sequence.getInstance(obj, explicit));
019: }
020:
021: public static V2Form getInstance(Object obj) {
022: if (obj == null || obj instanceof V2Form) {
023: return (V2Form) obj;
024: } else if (obj instanceof ASN1Sequence) {
025: return new V2Form((ASN1Sequence) obj);
026: }
027:
028: throw new IllegalArgumentException("unknown object in factory");
029: }
030:
031: public V2Form(GeneralNames issuerName) {
032: this .issuerName = issuerName;
033: }
034:
035: public V2Form(ASN1Sequence seq) {
036: if (seq.size() > 3) {
037: throw new IllegalArgumentException("Bad sequence size: "
038: + seq.size());
039: }
040:
041: int index = 0;
042:
043: if (!(seq.getObjectAt(0) instanceof ASN1TaggedObject)) {
044: index++;
045: this .issuerName = GeneralNames.getInstance(seq
046: .getObjectAt(0));
047: }
048:
049: for (int i = index; i != seq.size(); i++) {
050: ASN1TaggedObject o = ASN1TaggedObject.getInstance(seq
051: .getObjectAt(i));
052: if (o.getTagNo() == 0) {
053: baseCertificateID = IssuerSerial.getInstance(o, false);
054: } else if (o.getTagNo() == 1) {
055: objectDigestInfo = ObjectDigestInfo.getInstance(o,
056: false);
057: } else {
058: throw new IllegalArgumentException("Bad tag number: "
059: + o.getTagNo());
060: }
061: }
062: }
063:
064: public GeneralNames getIssuerName() {
065: return issuerName;
066: }
067:
068: public IssuerSerial getBaseCertificateID() {
069: return baseCertificateID;
070: }
071:
072: public ObjectDigestInfo getObjectDigestInfo() {
073: return objectDigestInfo;
074: }
075:
076: /**
077: * Produce an object suitable for an ASN1OutputStream.
078: * <pre>
079: * V2Form ::= SEQUENCE {
080: * issuerName GeneralNames OPTIONAL,
081: * baseCertificateID [0] IssuerSerial OPTIONAL,
082: * objectDigestInfo [1] ObjectDigestInfo OPTIONAL
083: * -- issuerName MUST be present in this profile
084: * -- baseCertificateID and objectDigestInfo MUST NOT
085: * -- be present in this profile
086: * }
087: * </pre>
088: */
089: public DERObject toASN1Object() {
090: ASN1EncodableVector v = new ASN1EncodableVector();
091:
092: if (issuerName != null) {
093: v.add(issuerName);
094: }
095:
096: if (baseCertificateID != null) {
097: v.add(new DERTaggedObject(false, 0, baseCertificateID));
098: }
099:
100: if (objectDigestInfo != null) {
101: v.add(new DERTaggedObject(false, 1, objectDigestInfo));
102: }
103:
104: return new DERSequence(v);
105: }
106: }
|