1package org.bouncycastle.crypto.params;
2
3import java.math.BigInteger;
4
5public class DSAPublicKeyParameters
6    extends DSAKeyParameters
7{
8    private static final BigInteger ONE = BigInteger.valueOf(1);
9    private static final BigInteger TWO = BigInteger.valueOf(2);
10
11    private BigInteger      y;
12
13    public DSAPublicKeyParameters(
14        BigInteger      y,
15        DSAParameters   params)
16    {
17        super(false, params);
18
19        this.y = validate(y, params);
20    }
21
22    private BigInteger validate(BigInteger y, DSAParameters params)
23    {
24        if (params != null)
25        {
26            if (TWO.compareTo(y) <= 0 && params.getP().subtract(TWO).compareTo(y) >= 0
27                && ONE.equals(y.modPow(params.getQ(), params.getP())))
28            {
29                return y;
30            }
31
32            throw new IllegalArgumentException("y value does not appear to be in correct group");
33        }
34        else
35        {
36            return y;         // we can't validate without params, fortunately we can't use the key either...
37        }
38    }
39
40    public BigInteger getY()
41    {
42        return y;
43    }
44}
45