1 20 package com.novosec.pkix.asn1.cmp; 21 22 import java.util.Enumeration ; 23 24 import org.bouncycastle.asn1.ASN1EncodableVector; 25 import org.bouncycastle.asn1.ASN1Sequence; 26 import org.bouncycastle.asn1.ASN1TaggedObject; 27 import org.bouncycastle.asn1.DERBitString; 28 import org.bouncycastle.asn1.DEREncodable; 29 import org.bouncycastle.asn1.DERObject; 30 import org.bouncycastle.asn1.DERSequence; 31 import org.bouncycastle.asn1.DERTaggedObject; 32 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 33 import com.novosec.pkix.asn1.crmf.CertId; 34 35 47 public class OOBCertHash implements DEREncodable 48 { 49 AlgorithmIdentifier hashAlg; 50 CertId certId; 51 DERBitString hashVal; 52 53 public static OOBCertHash getInstance( ASN1TaggedObject obj, boolean explicit ) 54 { 55 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 56 } 57 58 public static OOBCertHash getInstance( Object obj ) 59 { 60 if (obj instanceof OOBCertHash) 61 { 62 return (OOBCertHash)obj; 63 } 64 else if (obj instanceof ASN1Sequence) 65 { 66 return new OOBCertHash((ASN1Sequence)obj); 67 } 68 69 throw new IllegalArgumentException ("unknown object in factory"); 70 } 71 72 public OOBCertHash( ASN1Sequence seq ) 73 { 74 Enumeration e = seq.getObjects(); 75 76 while( e.hasMoreElements() ) 77 { 78 Object obj = e.nextElement(); 79 80 if( obj instanceof ASN1TaggedObject ) 81 { 82 ASN1TaggedObject tagObj = (ASN1TaggedObject)obj; 83 84 switch( tagObj.getTagNo() ) 85 { 86 case 0: hashAlg = AlgorithmIdentifier.getInstance(tagObj.getObject()); break; 87 case 1: certId = CertId.getInstance(tagObj.getObject()); break; 88 } 89 } 90 else 91 { 92 hashVal = DERBitString.getInstance( obj ); 93 94 break; 95 } 96 } 97 } 98 99 public OOBCertHash( DERBitString hashVal ) 100 { 101 this.hashVal = hashVal; 102 } 103 104 public DERBitString getHashVal() 105 { 106 return hashVal; 107 } 108 109 public void setHashAlg( AlgorithmIdentifier hashAlg ) 110 { 111 this.hashAlg = hashAlg; 112 } 113 114 public AlgorithmIdentifier getHashAlg() 115 { 116 return hashAlg; 117 } 118 119 public void setCertId( CertId certId ) 120 { 121 this.certId = certId; 122 } 123 124 public CertId getCertId() 125 { 126 return certId; 127 } 128 129 public DERObject getDERObject() 130 { 131 ASN1EncodableVector v = new ASN1EncodableVector(); 132 133 if( hashAlg != null ) 134 v.add( new DERTaggedObject( true, 0, hashAlg ) ); 135 136 if( certId != null ) 137 v.add( new DERTaggedObject( true, 1, certId ) ); 138 139 v.add( hashVal ); 140 141 return new DERSequence(v); 142 } 143 144 public String toString() 145 { 146 String s = "OOBCertHash: ( "; 147 148 if( this.getHashAlg() != null ) 149 s += "hashAlg: " + this.getHashAlg() + ", "; 150 151 if( this.getCertId() != null ) 152 s += "certId: " + this.getCertId() + ", "; 153 154 s += "hashVal: " + this.getHashVal(); 155 156 s += ")"; 157 158 return s; 159 } 160 } 161 | Popular Tags |