• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.bouncycastle.asn1.x509;
2 
3 import java.util.Enumeration;
4 
5 import org.bouncycastle.asn1.ASN1EncodableVector;
6 import org.bouncycastle.asn1.ASN1Object;
7 import org.bouncycastle.asn1.ASN1OctetString;
8 import org.bouncycastle.asn1.ASN1Primitive;
9 import org.bouncycastle.asn1.ASN1Sequence;
10 import org.bouncycastle.asn1.ASN1TaggedObject;
11 import org.bouncycastle.asn1.DEROctetString;
12 import org.bouncycastle.asn1.DERSequence;
13 
14 /**
15  * The DigestInfo object.
16  * <pre>
17  * DigestInfo::=SEQUENCE{
18  *          digestAlgorithm  AlgorithmIdentifier,
19  *          digest OCTET STRING }
20  * </pre>
21  */
22 public class DigestInfo
23     extends ASN1Object
24 {
25     private byte[]                  digest;
26     private AlgorithmIdentifier     algId;
27 
getInstance( ASN1TaggedObject obj, boolean explicit)28     public static DigestInfo getInstance(
29         ASN1TaggedObject obj,
30         boolean          explicit)
31     {
32         return getInstance(ASN1Sequence.getInstance(obj, explicit));
33     }
34 
getInstance( Object obj)35     public static DigestInfo getInstance(
36         Object  obj)
37     {
38         if (obj instanceof DigestInfo)
39         {
40             return (DigestInfo)obj;
41         }
42         else if (obj != null)
43         {
44             return new DigestInfo(ASN1Sequence.getInstance(obj));
45         }
46 
47         return null;
48     }
49 
DigestInfo( AlgorithmIdentifier algId, byte[] digest)50     public DigestInfo(
51         AlgorithmIdentifier  algId,
52         byte[]               digest)
53     {
54         this.digest = digest;
55         this.algId = algId;
56     }
57 
DigestInfo( ASN1Sequence obj)58     public DigestInfo(
59         ASN1Sequence  obj)
60     {
61         Enumeration             e = obj.getObjects();
62 
63         algId = AlgorithmIdentifier.getInstance(e.nextElement());
64         digest = ASN1OctetString.getInstance(e.nextElement()).getOctets();
65     }
66 
getAlgorithmId()67     public AlgorithmIdentifier getAlgorithmId()
68     {
69         return algId;
70     }
71 
getDigest()72     public byte[] getDigest()
73     {
74         return digest;
75     }
76 
toASN1Primitive()77     public ASN1Primitive toASN1Primitive()
78     {
79         ASN1EncodableVector  v = new ASN1EncodableVector();
80 
81         v.add(algId);
82         v.add(new DEROctetString(digest));
83 
84         return new DERSequence(v);
85     }
86 }
87