1package org.bouncycastle.asn1.x9; 2 3import org.bouncycastle.asn1.ASN1EncodableVector; 4import org.bouncycastle.asn1.ASN1Integer; 5import org.bouncycastle.asn1.ASN1Object; 6import org.bouncycastle.asn1.ASN1Primitive; 7import org.bouncycastle.asn1.ASN1Sequence; 8import org.bouncycastle.asn1.ASN1TaggedObject; 9import org.bouncycastle.asn1.DERBitString; 10import org.bouncycastle.asn1.DERSequence; 11 12public class DHValidationParms extends ASN1Object 13{ 14 private DERBitString seed; 15 private ASN1Integer 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, ASN1Integer 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 = ASN1Integer.getInstance(seq.getObjectAt(1)); 61 } 62 63 public DERBitString getSeed() 64 { 65 return this.seed; 66 } 67 68 public ASN1Integer getPgenCounter() 69 { 70 return this.pgenCounter; 71 } 72 73 public ASN1Primitive toASN1Primitive() 74 { 75 ASN1EncodableVector v = new ASN1EncodableVector(); 76 v.add(this.seed); 77 v.add(this.pgenCounter); 78 return new DERSequence(v); 79 } 80} 81