1package org.bouncycastle.asn1.x9; 2 3import org.bouncycastle.asn1.ASN1Encodable; 4import org.bouncycastle.asn1.ASN1EncodableVector; 5import org.bouncycastle.asn1.ASN1Sequence; 6import org.bouncycastle.asn1.ASN1TaggedObject; 7import org.bouncycastle.asn1.DERBitString; 8import org.bouncycastle.asn1.DERInteger; 9import org.bouncycastle.asn1.DERObject; 10import org.bouncycastle.asn1.DERSequence; 11 12public class DHValidationParms extends ASN1Encodable 13{ 14 private DERBitString seed; 15 private DERInteger pgenCounter; 16 17 public static DHValidationParms getInstance(ASN1TaggedObject obj, boolean explicit) 18 { 19 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 20 } 21 22 public static DHValidationParms getInstance(Object obj) 23 { 24 if (obj == null || obj instanceof DHDomainParameters) 25 { 26 return (DHValidationParms)obj; 27 } 28 29 if (obj instanceof ASN1Sequence) 30 { 31 return new DHValidationParms((ASN1Sequence)obj); 32 } 33 34 throw new IllegalArgumentException("Invalid DHValidationParms: " + obj.getClass().getName()); 35 } 36 37 public DHValidationParms(DERBitString seed, DERInteger pgenCounter) 38 { 39 if (seed == null) 40 { 41 throw new IllegalArgumentException("'seed' cannot be null"); 42 } 43 if (pgenCounter == null) 44 { 45 throw new IllegalArgumentException("'pgenCounter' cannot be null"); 46 } 47 48 this.seed = seed; 49 this.pgenCounter = pgenCounter; 50 } 51 52 private DHValidationParms(ASN1Sequence seq) 53 { 54 if (seq.size() != 2) 55 { 56 throw new IllegalArgumentException("Bad sequence size: " + seq.size()); 57 } 58 59 this.seed = DERBitString.getInstance(seq.getObjectAt(0)); 60 this.pgenCounter = DERInteger.getInstance(seq.getObjectAt(1)); 61 } 62 63 public DERBitString getSeed() 64 { 65 return this.seed; 66 } 67 68 public DERInteger getPgenCounter() 69 { 70 return this.pgenCounter; 71 } 72 73 public DERObject toASN1Object() 74 { 75 ASN1EncodableVector v = new ASN1EncodableVector(); 76 v.add(this.seed); 77 v.add(this.pgenCounter); 78 return new DERSequence(v); 79 } 80} 81