001package org.apache.commons.ssl.org.bouncycastle.asn1.cryptopro; 002 003import java.math.BigInteger; 004import java.util.Enumeration; 005 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 011import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 012import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 013 014public class GOST3410ParamSetParameters 015 extends ASN1Object 016{ 017 int keySize; 018 ASN1Integer p, q, a; 019 020 public static GOST3410ParamSetParameters getInstance( 021 ASN1TaggedObject obj, 022 boolean explicit) 023 { 024 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 025 } 026 027 public static GOST3410ParamSetParameters getInstance( 028 Object obj) 029 { 030 if(obj == null || obj instanceof GOST3410ParamSetParameters) 031 { 032 return (GOST3410ParamSetParameters)obj; 033 } 034 035 if(obj instanceof ASN1Sequence) 036 { 037 return new GOST3410ParamSetParameters((ASN1Sequence)obj); 038 } 039 040 throw new IllegalArgumentException("Invalid GOST3410Parameter: " + obj.getClass().getName()); 041 } 042 043 public GOST3410ParamSetParameters( 044 int keySize, 045 BigInteger p, 046 BigInteger q, 047 BigInteger a) 048 { 049 this.keySize = keySize; 050 this.p = new ASN1Integer(p); 051 this.q = new ASN1Integer(q); 052 this.a = new ASN1Integer(a); 053 } 054 055 public GOST3410ParamSetParameters( 056 ASN1Sequence seq) 057 { 058 Enumeration e = seq.getObjects(); 059 060 keySize = ((ASN1Integer)e.nextElement()).getValue().intValue(); 061 p = (ASN1Integer)e.nextElement(); 062 q = (ASN1Integer)e.nextElement(); 063 a = (ASN1Integer)e.nextElement(); 064 } 065 066 /** 067 * @deprecated use getKeySize 068 */ 069 public int getLKeySize() 070 { 071 return keySize; 072 } 073 074 public int getKeySize() 075 { 076 return keySize; 077 } 078 079 public BigInteger getP() 080 { 081 return p.getPositiveValue(); 082 } 083 084 public BigInteger getQ() 085 { 086 return q.getPositiveValue(); 087 } 088 089 public BigInteger getA() 090 { 091 return a.getPositiveValue(); 092 } 093 094 public ASN1Primitive toASN1Primitive() 095 { 096 ASN1EncodableVector v = new ASN1EncodableVector(); 097 098 v.add(new ASN1Integer(keySize)); 099 v.add(p); 100 v.add(q); 101 v.add(a); 102 103 return new DERSequence(v); 104 } 105}