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 ECGOST3410ParamSetParameters
015    extends ASN1Object
016{
017    ASN1Integer      p, q, a, b, x, y;
018
019    public static ECGOST3410ParamSetParameters getInstance(
020        ASN1TaggedObject obj,
021        boolean          explicit)
022    {
023        return getInstance(ASN1Sequence.getInstance(obj, explicit));
024    }
025
026    public static ECGOST3410ParamSetParameters getInstance(
027        Object obj)
028    {
029        if(obj == null || obj instanceof ECGOST3410ParamSetParameters)
030        {
031            return (ECGOST3410ParamSetParameters)obj;
032        }
033
034        if(obj instanceof ASN1Sequence)
035        {
036            return new ECGOST3410ParamSetParameters((ASN1Sequence)obj);
037        }
038
039        throw new IllegalArgumentException("Invalid GOST3410Parameter: " + obj.getClass().getName());
040    }
041
042    public ECGOST3410ParamSetParameters(
043        BigInteger a,
044        BigInteger b,
045        BigInteger p,
046        BigInteger q,
047        int        x,
048        BigInteger y)
049    {
050        this.a = new ASN1Integer(a);
051        this.b = new ASN1Integer(b);
052        this.p = new ASN1Integer(p);
053        this.q = new ASN1Integer(q);
054        this.x = new ASN1Integer(x);
055        this.y = new ASN1Integer(y);
056    }
057
058    public ECGOST3410ParamSetParameters(
059        ASN1Sequence  seq)
060    {
061        Enumeration     e = seq.getObjects();
062
063        a = (ASN1Integer)e.nextElement();
064        b = (ASN1Integer)e.nextElement();
065        p = (ASN1Integer)e.nextElement();
066        q = (ASN1Integer)e.nextElement();
067        x = (ASN1Integer)e.nextElement();
068        y = (ASN1Integer)e.nextElement();
069    }
070    
071    public BigInteger getP()
072    {
073        return p.getPositiveValue();
074    }
075
076    public BigInteger getQ()
077    {
078        return q.getPositiveValue();
079    }
080
081    public BigInteger getA()
082    {
083        return a.getPositiveValue();
084    }
085
086    public ASN1Primitive toASN1Primitive()
087    {
088        ASN1EncodableVector  v = new ASN1EncodableVector();
089
090        v.add(a);
091        v.add(b);
092        v.add(p);
093        v.add(q);
094        v.add(x);
095        v.add(y);
096
097        return new DERSequence(v);
098    }
099}