resolve darcs stupidity
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / DigestInfo.java
1 package org.bouncycastle.asn1.x509;
2
3 import java.util.Enumeration;
4
5 import org.bouncycastle.asn1.*;
6
7 /**
8  * <pre>
9  * DigestInfo::=SEQUENCE{
10  *          digestAlgorithm  AlgorithmIdentifier,
11  *          digest OCTET STRING }
12  * </pre>
13  */
14 public class DigestInfo
15     implements DEREncodable
16 {
17     private byte[]                  digest;
18     private AlgorithmIdentifier     algId;
19
20     public static DigestInfo getInstance(
21         ASN1TaggedObject obj,
22         boolean          explicit)
23     {
24         return getInstance(ASN1Sequence.getInstance(obj, explicit));
25     }
26
27     public static DigestInfo getInstance(
28         Object  obj)
29     {
30         if (obj instanceof DigestInfo)
31         {
32             return (DigestInfo)obj;
33         }
34         else if (obj instanceof ASN1Sequence)
35         {
36             return new DigestInfo((ASN1Sequence)obj);
37         }
38
39         throw new IllegalArgumentException("unknown object in factory");
40     }
41
42     public DigestInfo(
43         AlgorithmIdentifier  algId,
44         byte[]               digest)
45     {
46         this.digest = digest;
47         this.algId = algId;
48     }
49
50     public DigestInfo(
51         ASN1Sequence  obj)
52     {
53         Enumeration             e = obj.getObjects();
54
55         algId = AlgorithmIdentifier.getInstance(e.nextElement());
56         digest = ((ASN1OctetString)e.nextElement()).getOctets();
57     }
58
59     public AlgorithmIdentifier getAlgorithmId()
60     {
61         return algId;
62     }
63
64     public byte[] getDigest()
65     {
66         return digest;
67     }
68
69     public DERObject getDERObject()
70     {
71         DEREncodableVector  v = new DEREncodableVector();
72
73         v.add(algId);
74         v.add(new DEROctetString(digest));
75
76         return new DERSequence(v);
77     }
78 }