1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import org.apache.geronimo.util.asn1.ASN1Encodable; 21 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 22 import org.apache.geronimo.util.asn1.ASN1Sequence; 23 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 24 import org.apache.geronimo.util.asn1.DERBitString; 25 import org.apache.geronimo.util.asn1.DEREnumerated; 26 import org.apache.geronimo.util.asn1.DERObject; 27 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 28 import org.apache.geronimo.util.asn1.DERSequence; 29 import org.apache.geronimo.util.asn1.x509.AlgorithmIdentifier; 30 31 32 public class ObjectDigestInfo 33 extends ASN1Encodable 34 { 35 DEREnumerated digestedObjectType; 36 37 DERObjectIdentifier otherObjectTypeID; 38 39 AlgorithmIdentifier digestAlgorithm; 40 41 DERBitString objectDigest; 42 43 public static ObjectDigestInfo getInstance( 44 Object obj) 45 { 46 if (obj == null || obj instanceof ObjectDigestInfo) 47 { 48 return (ObjectDigestInfo)obj; 49 } 50 51 if (obj instanceof ASN1Sequence) 52 { 53 return new ObjectDigestInfo((ASN1Sequence)obj); 54 } 55 56 throw new IllegalArgumentException ("illegal object in getInstance: " + obj.getClass().getName()); 57 } 58 59 public static ObjectDigestInfo getInstance( 60 ASN1TaggedObject obj, 61 boolean explicit) 62 { 63 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 64 } 65 66 public ObjectDigestInfo(ASN1Sequence seq) 67 { 68 digestedObjectType = DEREnumerated.getInstance(seq.getObjectAt(0)); 69 70 int offset = 0; 71 72 if (seq.size() == 4) 73 { 74 otherObjectTypeID = DERObjectIdentifier.getInstance(seq.getObjectAt(1)); 75 offset++; 76 } 77 78 digestAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1 + offset)); 79 80 objectDigest = new DERBitString(seq.getObjectAt(2 + offset)); 81 } 82 83 public DEREnumerated getDigestedObjectType() 84 { 85 return digestedObjectType; 86 } 87 88 public DERObjectIdentifier getOtherObjectTypeID() 89 { 90 return otherObjectTypeID; 91 } 92 93 public AlgorithmIdentifier getDigestAlgorithm() 94 { 95 return digestAlgorithm; 96 } 97 98 public DERBitString getObjectDigest() 99 { 100 return objectDigest; 101 } 102 103 122 public DERObject toASN1Object() 123 { 124 ASN1EncodableVector v = new ASN1EncodableVector(); 125 126 v.add(digestedObjectType); 127 128 if (otherObjectTypeID != null) 129 { 130 v.add(otherObjectTypeID); 131 } 132 133 v.add(digestAlgorithm); 134 v.add(objectDigest); 135 136 return new DERSequence(v); 137 } 138 } 139 | Popular Tags |