1 20 package com.novosec.pkix.asn1.cmp; 21 22 import org.bouncycastle.asn1.ASN1EncodableVector; 23 import org.bouncycastle.asn1.ASN1Sequence; 24 import org.bouncycastle.asn1.ASN1TaggedObject; 25 import org.bouncycastle.asn1.DEREncodable; 26 import org.bouncycastle.asn1.DERObject; 27 import org.bouncycastle.asn1.DEROctetString; 28 import org.bouncycastle.asn1.DERSequence; 29 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 30 31 45 public class Challenge implements DEREncodable 46 { 47 AlgorithmIdentifier owf; 48 DEROctetString witness; 49 DEROctetString challenge; 50 51 public static Challenge getInstance(ASN1TaggedObject obj, boolean explicit) 52 { 53 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 54 } 55 56 public static Challenge getInstance(Object obj) 57 { 58 if (obj instanceof Challenge) 59 { 60 return (Challenge) obj; 61 } 62 else if (obj instanceof ASN1Sequence) 63 { 64 return new Challenge((ASN1Sequence) obj); 65 } 66 67 throw new IllegalArgumentException ("unknown object in factory"); 68 } 69 70 public Challenge(ASN1Sequence seq) 71 { 72 int idx = 0; 73 Object obj = seq.getObjectAt(idx); 74 75 if( !(obj instanceof DEROctetString) ) 76 { 77 owf = AlgorithmIdentifier.getInstance(obj); 78 idx++; 79 } 80 81 this.witness = (DEROctetString)seq.getObjectAt(idx++); 82 this.challenge = (DEROctetString)seq.getObjectAt(idx); 83 } 84 85 public Challenge( DEROctetString witness, DEROctetString challenge ) 86 { 87 this.witness = witness; 88 this.challenge = challenge; 89 } 90 91 public AlgorithmIdentifier getOwf() 92 { 93 return owf; 94 } 95 96 public void setOwf(AlgorithmIdentifier owf) 97 { 98 this.owf = owf; 99 } 100 101 public DEROctetString getWitness() 102 { 103 return witness; 104 } 105 106 public DEROctetString getChallenge() 107 { 108 return challenge; 109 } 110 111 public DERObject getDERObject() 112 { 113 ASN1EncodableVector v = new ASN1EncodableVector(); 114 115 if( owf != null ) 116 v.add(owf); 117 118 v.add(witness); 119 v.add(challenge); 120 121 return new DERSequence(v); 122 } 123 124 public String toString() 125 { 126 String s = "Challenge: ("; 127 128 if( this.getOwf() != null ) 129 s += "owf: "+ this.getOwf() + ", "; 130 131 s += "witness: " + this.getWitness(); 132 s += "challenge: " + this.getChallenge(); 133 134 s += ")"; 135 136 return s; 137 } 138 } 139 | Popular Tags |