01: package org.bouncycastle.asn1.ess;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1OctetString;
06: import org.bouncycastle.asn1.ASN1Sequence;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DEROctetString;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.x509.IssuerSerial;
11:
12: public class ESSCertID extends ASN1Encodable {
13: private ASN1OctetString certHash;
14:
15: private IssuerSerial issuerSerial;
16:
17: public static ESSCertID getInstance(Object o) {
18: if (o == null || o instanceof ESSCertID) {
19: return (ESSCertID) o;
20: } else if (o instanceof ASN1Sequence) {
21: return new ESSCertID((ASN1Sequence) o);
22: }
23:
24: throw new IllegalArgumentException(
25: "unknown object in 'ESSCertID' factory : "
26: + o.getClass().getName() + ".");
27: }
28:
29: /**
30: * constructor
31: */
32: public ESSCertID(ASN1Sequence seq) {
33: if (seq.size() < 1 || seq.size() > 2) {
34: throw new IllegalArgumentException("Bad sequence size: "
35: + seq.size());
36: }
37:
38: certHash = ASN1OctetString.getInstance(seq.getObjectAt(0));
39:
40: if (seq.size() > 1) {
41: issuerSerial = IssuerSerial.getInstance(seq.getObjectAt(1));
42: }
43: }
44:
45: public ESSCertID(byte[] hash) {
46: certHash = new DEROctetString(hash);
47: }
48:
49: public ESSCertID(byte[] hash, IssuerSerial issuerSerial) {
50: this .certHash = new DEROctetString(hash);
51: this .issuerSerial = issuerSerial;
52: }
53:
54: public byte[] getCertHash() {
55: return certHash.getOctets();
56: }
57:
58: public IssuerSerial getIssuerSerial() {
59: return issuerSerial;
60: }
61:
62: /**
63: * <pre>
64: * ESSCertID ::= SEQUENCE {
65: * certHash Hash,
66: * issuerSerial IssuerSerial OPTIONAL }
67: * </pre>
68: */
69: public DERObject toASN1Object() {
70: ASN1EncodableVector v = new ASN1EncodableVector();
71:
72: v.add(certHash);
73:
74: if (issuerSerial != null) {
75: v.add(issuerSerial);
76: }
77:
78: return new DERSequence(v);
79: }
80: }
|