001: package org.bouncycastle.asn1.ess;
002:
003: import org.bouncycastle.asn1.*;
004: import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
005: import org.bouncycastle.asn1.x509.IssuerSerial;
006: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
007:
008: public class ESSCertIDv2 extends ASN1Encodable {
009: private AlgorithmIdentifier hashAlgorithm;
010: private byte[] certHash;
011: private IssuerSerial issuerSerial;
012:
013: public static ESSCertIDv2 getInstance(Object o) {
014: if (o == null || o instanceof ESSCertIDv2) {
015: return (ESSCertIDv2) o;
016: } else if (o instanceof ASN1Sequence) {
017: return new ESSCertIDv2((ASN1Sequence) o);
018: }
019:
020: throw new IllegalArgumentException(
021: "unknown object in 'ESSCertIDv2' factory : "
022: + o.getClass().getName() + ".");
023: }
024:
025: public ESSCertIDv2(ASN1Sequence seq) {
026: if (seq.size() != 2 && seq.size() != 3) {
027: throw new IllegalArgumentException("Bad sequence size: "
028: + seq.size());
029: }
030:
031: this .hashAlgorithm = AlgorithmIdentifier.getInstance(seq
032: .getObjectAt(0).getDERObject());
033: this .certHash = ASN1OctetString.getInstance(
034: seq.getObjectAt(1).getDERObject()).getOctets();
035:
036: if (seq.size() > 2) {
037: this .issuerSerial = new IssuerSerial(ASN1Sequence
038: .getInstance(seq.getObjectAt(2).getDERObject()));
039: }
040: }
041:
042: public ESSCertIDv2(AlgorithmIdentifier algId, byte[] certHash) {
043: this (algId, certHash, null);
044: }
045:
046: public ESSCertIDv2(AlgorithmIdentifier algId, byte[] certHash,
047: IssuerSerial issuerSerial) {
048: if (algId == null) {
049: // Default value
050: this .hashAlgorithm = new AlgorithmIdentifier(
051: NISTObjectIdentifiers.dsa_with_sha256);
052: } else {
053: this .hashAlgorithm = algId;
054: }
055:
056: this .certHash = certHash;
057: this .issuerSerial = issuerSerial;
058: }
059:
060: public AlgorithmIdentifier getHashAlgorithm() {
061: return this .hashAlgorithm;
062: }
063:
064: public byte[] getCertHash() {
065: return certHash;
066: }
067:
068: public IssuerSerial getIssuerSerial() {
069: return issuerSerial;
070: }
071:
072: /**
073: * <pre>
074: * ESSCertIDv2 ::= SEQUENCE {
075: * hashAlgorithm AlgorithmIdentifier
076: * DEFAULT {algorithm id-sha256 parameters NULL},
077: * certHash Hash,
078: * issuerSerial IssuerSerial OPTIONAL
079: * }
080: *
081: * Hash ::= OCTET STRING
082: *
083: * IssuerSerial ::= SEQUENCE {
084: * issuer GeneralNames,
085: * serialNumber CertificateSerialNumber
086: * }
087: * </pre>
088: */
089: public DERObject toASN1Object() {
090: ASN1EncodableVector v = new ASN1EncodableVector();
091:
092: v.add(hashAlgorithm);
093:
094: v.add(new DEROctetString(certHash).toASN1Object());
095:
096: if (issuerSerial != null) {
097: v.add(issuerSerial);
098: }
099:
100: return new DERSequence(v);
101: }
102:
103: }
|