01: package org.bouncycastle.asn1.ocsp;
02:
03: import org.bouncycastle.asn1.ASN1EncodableVector;
04: import org.bouncycastle.asn1.ASN1OctetString;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.ASN1Encodable;
08: import org.bouncycastle.asn1.DERInteger;
09: import org.bouncycastle.asn1.DERObject;
10: import org.bouncycastle.asn1.DERSequence;
11: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
12:
13: public class CertID extends ASN1Encodable {
14: AlgorithmIdentifier hashAlgorithm;
15: ASN1OctetString issuerNameHash;
16: ASN1OctetString issuerKeyHash;
17: DERInteger serialNumber;
18:
19: public CertID(AlgorithmIdentifier hashAlgorithm,
20: ASN1OctetString issuerNameHash,
21: ASN1OctetString issuerKeyHash, DERInteger serialNumber) {
22: this .hashAlgorithm = hashAlgorithm;
23: this .issuerNameHash = issuerNameHash;
24: this .issuerKeyHash = issuerKeyHash;
25: this .serialNumber = serialNumber;
26: }
27:
28: public CertID(ASN1Sequence seq) {
29: hashAlgorithm = AlgorithmIdentifier.getInstance(seq
30: .getObjectAt(0));
31: issuerNameHash = (ASN1OctetString) seq.getObjectAt(1);
32: issuerKeyHash = (ASN1OctetString) seq.getObjectAt(2);
33: serialNumber = (DERInteger) seq.getObjectAt(3);
34: }
35:
36: public static CertID getInstance(ASN1TaggedObject obj,
37: boolean explicit) {
38: return getInstance(ASN1Sequence.getInstance(obj, explicit));
39: }
40:
41: public static CertID getInstance(Object obj) {
42: if (obj == null || obj instanceof CertID) {
43: return (CertID) obj;
44: } else if (obj instanceof ASN1Sequence) {
45: return new CertID((ASN1Sequence) obj);
46: }
47:
48: throw new IllegalArgumentException("unknown object in factory");
49: }
50:
51: public AlgorithmIdentifier getHashAlgorithm() {
52: return hashAlgorithm;
53: }
54:
55: public ASN1OctetString getIssuerNameHash() {
56: return issuerNameHash;
57: }
58:
59: public ASN1OctetString getIssuerKeyHash() {
60: return issuerKeyHash;
61: }
62:
63: public DERInteger getSerialNumber() {
64: return serialNumber;
65: }
66:
67: /**
68: * Produce an object suitable for an ASN1OutputStream.
69: * <pre>
70: * CertID ::= SEQUENCE {
71: * hashAlgorithm AlgorithmIdentifier,
72: * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
73: * issuerKeyHash OCTET STRING, -- Hash of Issuers public key
74: * serialNumber CertificateSerialNumber }
75: * </pre>
76: */
77: public DERObject toASN1Object() {
78: ASN1EncodableVector v = new ASN1EncodableVector();
79:
80: v.add(hashAlgorithm);
81: v.add(issuerNameHash);
82: v.add(issuerKeyHash);
83: v.add(serialNumber);
84:
85: return new DERSequence(v);
86: }
87: }
|