1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.security.spec;
19
20import org.apache.harmony.security.internal.nls.Messages;
21
22/**
23 * The parameters specifying an Elliptic Curve (EC) public key.
24 */
25public class ECPublicKeySpec implements KeySpec {
26    // The public point
27    private final ECPoint w;
28    // The associated elliptic curve domain parameters
29    private final ECParameterSpec params;
30
31    /**
32     * Creates a new {@code ECPublicKey} with the specified public elliptic
33     * curve point and parameter specification.
34     *
35     * @param w
36     *            the public elliptic curve point {@code W}.
37     * @param params
38     *            the domain parameter specification.
39     * @throws IllegalArgumentException
40     *             if the specified point {@code W} is at infinity.
41     */
42    public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
43        this.w = w;
44        this.params = params;
45        // throw NullPointerException if w or params is null
46        if (this.w == null) {
47            throw new NullPointerException(Messages.getString("security.83", "w")); //$NON-NLS-1$ //$NON-NLS-2$
48        }
49        if (this.params == null) {
50            throw new NullPointerException(Messages.getString("security.83", "params")); //$NON-NLS-1$ //$NON-NLS-2$
51        }
52        // throw IllegalArgumentException if w is point at infinity
53        if (this.w.equals(ECPoint.POINT_INFINITY)) {
54            throw new IllegalArgumentException(
55                Messages.getString("security.84")); //$NON-NLS-1$
56        }
57    }
58
59    /**
60     * Returns the domain parameter specification.
61     *
62     * @return the domain parameter specification.
63     */
64    public ECParameterSpec getParams() {
65        return params;
66    }
67
68    /**
69     * Returns the public elliptic curve point {@code W}.
70     *
71     * @return the public elliptic curve point {@code W}.
72     */
73    public ECPoint getW() {
74        return w;
75    }
76}
77