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 instanceof DHValidationParms) 25 { 26 return (DHValidationParms)obj; 27 } 28 else if (obj != null) 29 { 30 return new DHValidationParms(ASN1Sequence.getInstance(obj)); 31 } 32 33 return null; 34 } 35 36 public DHValidationParms(DERBitString seed, ASN1Integer pgenCounter) 37 { 38 if (seed == null) 39 { 40 throw new IllegalArgumentException("'seed' cannot be null"); 41 } 42 if (pgenCounter == null) 43 { 44 throw new IllegalArgumentException("'pgenCounter' cannot be null"); 45 } 46 47 this.seed = seed; 48 this.pgenCounter = pgenCounter; 49 } 50 51 private DHValidationParms(ASN1Sequence seq) 52 { 53 if (seq.size() != 2) 54 { 55 throw new IllegalArgumentException("Bad sequence size: " + seq.size()); 56 } 57 58 this.seed = DERBitString.getInstance(seq.getObjectAt(0)); 59 this.pgenCounter = ASN1Integer.getInstance(seq.getObjectAt(1)); 60 } 61 62 public DERBitString getSeed() 63 { 64 return this.seed; 65 } 66 67 public ASN1Integer getPgenCounter() 68 { 69 return this.pgenCounter; 70 } 71 72 public ASN1Primitive toASN1Primitive() 73 { 74 ASN1EncodableVector v = new ASN1EncodableVector(); 75 v.add(this.seed); 76 v.add(this.pgenCounter); 77 return new DERSequence(v); 78 } 79} 80