1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.util.Enumeration ; 21 22 import org.apache.geronimo.util.asn1.ASN1Encodable; 23 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 24 import org.apache.geronimo.util.asn1.ASN1OctetString; 25 import org.apache.geronimo.util.asn1.ASN1Sequence; 26 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 27 import org.apache.geronimo.util.asn1.DERObject; 28 import org.apache.geronimo.util.asn1.DEROctetString; 29 import org.apache.geronimo.util.asn1.DERSequence; 30 31 39 public class DigestInfo 40 extends ASN1Encodable 41 { 42 private byte[] digest; 43 private AlgorithmIdentifier algId; 44 45 public static DigestInfo getInstance( 46 ASN1TaggedObject obj, 47 boolean explicit) 48 { 49 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 50 } 51 52 public static DigestInfo getInstance( 53 Object obj) 54 { 55 if (obj instanceof DigestInfo) 56 { 57 return (DigestInfo)obj; 58 } 59 else if (obj instanceof ASN1Sequence) 60 { 61 return new DigestInfo((ASN1Sequence)obj); 62 } 63 64 throw new IllegalArgumentException ("unknown object in factory"); 65 } 66 67 public DigestInfo( 68 AlgorithmIdentifier algId, 69 byte[] digest) 70 { 71 this.digest = digest; 72 this.algId = algId; 73 } 74 75 public DigestInfo( 76 ASN1Sequence obj) 77 { 78 Enumeration e = obj.getObjects(); 79 80 algId = AlgorithmIdentifier.getInstance(e.nextElement()); 81 digest = ((ASN1OctetString)e.nextElement()).getOctets(); 82 } 83 84 public AlgorithmIdentifier getAlgorithmId() 85 { 86 return algId; 87 } 88 89 public byte[] getDigest() 90 { 91 return digest; 92 } 93 94 public DERObject toASN1Object() 95 { 96 ASN1EncodableVector v = new ASN1EncodableVector(); 97 98 v.add(algId); 99 v.add(new DEROctetString(digest)); 100 101 return new DERSequence(v); 102 } 103 } 104 | Popular Tags |