01: package org.bouncycastle.asn1.esf;
02:
03: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
04: import org.bouncycastle.asn1.*;
05:
06: public class OtherHashAlgAndValue extends ASN1Encodable {
07: private AlgorithmIdentifier hashAlgorithm;
08: private ASN1OctetString hashValue;
09:
10: public static OtherHashAlgAndValue getInstance(Object obj) {
11: if (obj == null || obj instanceof OtherHashAlgAndValue) {
12: return (OtherHashAlgAndValue) obj;
13: } else if (obj instanceof ASN1Sequence) {
14: return new OtherHashAlgAndValue((ASN1Sequence) obj);
15: }
16:
17: throw new IllegalArgumentException(
18: "unknown object in 'OtherHashAlgAndValue' factory : "
19: + obj.getClass().getName() + ".");
20: }
21:
22: public OtherHashAlgAndValue(ASN1Sequence seq) {
23: if (seq.size() != 2) {
24: throw new IllegalArgumentException("Bad sequence size: "
25: + seq.size());
26: }
27:
28: hashAlgorithm = AlgorithmIdentifier.getInstance(seq
29: .getObjectAt(0));
30: hashValue = ASN1OctetString.getInstance(seq.getObjectAt(1));
31: }
32:
33: public OtherHashAlgAndValue(AlgorithmIdentifier hashAlgorithm,
34: ASN1OctetString hashValue) {
35: this .hashAlgorithm = hashAlgorithm;
36: this .hashValue = hashValue;
37: }
38:
39: public AlgorithmIdentifier getHashAlgorithm() {
40: return hashAlgorithm;
41: }
42:
43: public ASN1OctetString getHashValue() {
44: return hashValue;
45: }
46:
47: /**
48: * <pre>
49: * OtherHashAlgAndValue ::= SEQUENCE {
50: * hashAlgorithm AlgorithmIdentifier,
51: * hashValue OtherHashValue }
52: *
53: * OtherHashValue ::= OCTET STRING
54: * </pre>
55: */
56: public DERObject toASN1Object() {
57: ASN1EncodableVector v = new ASN1EncodableVector();
58:
59: v.add(hashAlgorithm);
60: v.add(hashValue);
61:
62: return new DERSequence(v);
63: }
64: }
|