1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.security.keystore;
18
19import java.security.interfaces.ECPublicKey;
20import java.security.spec.ECParameterSpec;
21import java.security.spec.ECPoint;
22
23/**
24 * {@link ECPublicKey} backed by keystore.
25 *
26 * @hide
27 */
28public class AndroidKeyStoreECPublicKey extends AndroidKeyStorePublicKey implements ECPublicKey {
29
30    private final ECParameterSpec mParams;
31    private final ECPoint mW;
32
33    public AndroidKeyStoreECPublicKey(String alias, int uid, byte[] x509EncodedForm, ECParameterSpec params,
34            ECPoint w) {
35        super(alias, uid, KeyProperties.KEY_ALGORITHM_EC, x509EncodedForm);
36        mParams = params;
37        mW = w;
38    }
39
40    public AndroidKeyStoreECPublicKey(String alias, int uid, ECPublicKey info) {
41        this(alias, uid, info.getEncoded(), info.getParams(), info.getW());
42        if (!"X.509".equalsIgnoreCase(info.getFormat())) {
43            throw new IllegalArgumentException(
44                    "Unsupported key export format: " + info.getFormat());
45        }
46    }
47
48    @Override
49    public ECParameterSpec getParams() {
50        return mParams;
51    }
52
53    @Override
54    public ECPoint getW() {
55        return mW;
56    }
57}