01: package org.bouncycastle.asn1.tsp;
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.AlgorithmIdentifier;
11:
12: public class MessageImprint extends ASN1Encodable {
13: AlgorithmIdentifier hashAlgorithm;
14: byte[] hashedMessage;
15:
16: /**
17: * @param o
18: * @return a MessageImprint object.
19: */
20: public static MessageImprint getInstance(Object o) {
21: if (o == null || o instanceof MessageImprint) {
22: return (MessageImprint) o;
23: } else if (o instanceof ASN1Sequence) {
24: return new MessageImprint((ASN1Sequence) o);
25: }
26:
27: throw new IllegalArgumentException("Bad object in factory.");
28: }
29:
30: public MessageImprint(ASN1Sequence seq) {
31: this .hashAlgorithm = AlgorithmIdentifier.getInstance(seq
32: .getObjectAt(0));
33: this .hashedMessage = ASN1OctetString.getInstance(
34: seq.getObjectAt(1)).getOctets();
35: }
36:
37: public MessageImprint(AlgorithmIdentifier hashAlgorithm,
38: byte[] hashedMessage) {
39: this .hashAlgorithm = hashAlgorithm;
40: this .hashedMessage = hashedMessage;
41: }
42:
43: public AlgorithmIdentifier getHashAlgorithm() {
44: return hashAlgorithm;
45: }
46:
47: public byte[] getHashedMessage() {
48: return hashedMessage;
49: }
50:
51: /**
52: * <pre>
53: * MessageImprint ::= SEQUENCE {
54: * hashAlgorithm AlgorithmIdentifier,
55: * hashedMessage OCTET STRING }
56: * </pre>
57: */
58: public DERObject toASN1Object() {
59: ASN1EncodableVector v = new ASN1EncodableVector();
60:
61: v.add(hashAlgorithm);
62: v.add(new DEROctetString(hashedMessage));
63:
64: return new DERSequence(v);
65: }
66: }
|