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