1/*
2 * Copyright (C) 2016 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 */
16package libcore.tlswire.handshake;
17/**
18 * {@code EllipticCurve} enum from RFC 4492 section 5.1.1. Curves are assigned
19 * via the
20 * <a href="https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8">IANA registry</a>.
21 */
22public enum EllipticCurve {
23    SECT163K1(1, "sect163k1"),
24    SECT163R1(2, "sect163r1"),
25    SECT163R2(3, "sect163r2"),
26    SECT193R1(4, "sect193r1"),
27    SECT193R2(5, "sect193r2"),
28    SECT233K1(6, "sect233k1"),
29    SECT233R1(7, "sect233r1"),
30    SECT239K1(8, "sect239k1"),
31    SECT283K1(9, "sect283k1"),
32    SECT283R1(10, "sect283r1"),
33    SECT409K1(11, "sect409k1"),
34    SECT409R1(12, "sect409r1"),
35    SECT571K1(13, "sect571k1"),
36    SECT571R1(14, "sect571r1"),
37    SECP160K1(15, "secp160k1"),
38    SECP160R1(16, "secp160r1"),
39    SECP160R2(17, "secp160r2"),
40    SECP192K1(18, "secp192k1"),
41    SECP192R1(19, "secp192r1"),
42    SECP224K1(20, "secp224k1"),
43    SECP224R1(21, "secp224r1"),
44    SECP256K1(22, "secp256k1"),
45    SECP256R1(23, "secp256r1"),
46    SECP384R1(24, "secp384r1"),
47    SECP521R1(25, "secp521r1"),
48    BRAINPOOLP256R1(26, "brainpoolP256r1"),
49    BRAINPOOLP384R1(27, "brainpoolP384r1"),
50    BRAINPOOLP521R1(28, "brainpoolP521r1"),
51    X25519(29, "x25519"),
52    X448(30, "x448"),
53    ARBITRARY_PRIME(0xFF01, "arbitrary_explicit_prime_curves"),
54    ARBITRARY_CHAR2(0xFF02, "arbitrary_explicit_char2_curves");
55    public final int identifier;
56    public final String name;
57    private EllipticCurve(int identifier, String name) {
58        this.identifier = identifier;
59        this.name = name;
60    }
61    public static EllipticCurve fromIdentifier(int identifier) {
62        for (EllipticCurve curve : values()) {
63            if (curve.identifier == identifier) {
64                return curve;
65            }
66        }
67        throw new AssertionError("Unknown curve identifier " + identifier);
68    }
69    @Override
70    public String toString() {
71        StringBuilder sb = new StringBuilder(name);
72        sb.append(" (");
73        sb.append(identifier);
74        sb.append(')');
75        return sb.toString();
76    }
77}
78