01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.DERBitString;
08: import org.bouncycastle.asn1.DERInteger;
09: import org.bouncycastle.asn1.DERObject;
10: import org.bouncycastle.asn1.DERSequence;
11:
12: public class IssuerSerial extends ASN1Encodable {
13: GeneralNames issuer;
14: DERInteger serial;
15: DERBitString issuerUID;
16:
17: public static IssuerSerial getInstance(Object obj) {
18: if (obj == null || obj instanceof IssuerSerial) {
19: return (IssuerSerial) obj;
20: }
21:
22: if (obj instanceof ASN1Sequence) {
23: return new IssuerSerial((ASN1Sequence) obj);
24: }
25:
26: throw new IllegalArgumentException(
27: "illegal object in getInstance: "
28: + obj.getClass().getName());
29: }
30:
31: public static IssuerSerial getInstance(ASN1TaggedObject obj,
32: boolean explicit) {
33: return getInstance(ASN1Sequence.getInstance(obj, explicit));
34: }
35:
36: public IssuerSerial(ASN1Sequence seq) {
37: if (seq.size() != 2 && seq.size() != 3) {
38: throw new IllegalArgumentException("Bad sequence size: "
39: + seq.size());
40: }
41:
42: issuer = GeneralNames.getInstance(seq.getObjectAt(0));
43: serial = DERInteger.getInstance(seq.getObjectAt(1));
44:
45: if (seq.size() == 3) {
46: issuerUID = DERBitString.getInstance(seq.getObjectAt(2));
47: }
48: }
49:
50: public IssuerSerial(GeneralNames issuer, DERInteger serial) {
51: this .issuer = issuer;
52: this .serial = serial;
53: }
54:
55: public GeneralNames getIssuer() {
56: return issuer;
57: }
58:
59: public DERInteger getSerial() {
60: return serial;
61: }
62:
63: public DERBitString getIssuerUID() {
64: return issuerUID;
65: }
66:
67: /**
68: * Produce an object suitable for an ASN1OutputStream.
69: * <pre>
70: * IssuerSerial ::= SEQUENCE {
71: * issuer GeneralNames,
72: * serial CertificateSerialNumber,
73: * issuerUID UniqueIdentifier OPTIONAL
74: * }
75: * </pre>
76: */
77: public DERObject toASN1Object() {
78: ASN1EncodableVector v = new ASN1EncodableVector();
79:
80: v.add(issuer);
81: v.add(serial);
82:
83: if (issuerUID != null) {
84: v.add(issuerUID);
85: }
86:
87: return new DERSequence(v);
88: }
89: }
|