All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.authlete.cose.constants.COSEEllipticCurves Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2023 Authlete, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.authlete.cose.constants;


import java.util.LinkedHashMap;
import java.util.Map;


/**
 * COSE Elliptic Curves
 *
 * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
NameValueKey TypeDescription
{@link #P_256 P-256}1{@link COSEKeyTypes#EC2 EC2}NIST P-256 also known as secp256r1
{@link #P_384 P-384}2{@link COSEKeyTypes#EC2 EC2}NIST P-384 also known as secp384r1
{@link #P_521 P-521}3{@link COSEKeyTypes#EC2 EC2}NIST P-521 also known as secp521r1
{@link #X25519 X25519}4{@link COSEKeyTypes#OKP OKP}X25519 for use w/ ECDH only
{@link #X448 X448}5{@link COSEKeyTypes#OKP OKP}X448 for use w/ ECDH only
{@link #Ed25519 Ed25519}6{@link COSEKeyTypes#OKP OKP}Ed25519 for use w/ EdDSA only
{@link #Ed448 Ed448}7{@link COSEKeyTypes#OKP OKP}Ed448 for use w/ EdDSA only
{@link #SECP256K1 secp256k1}8{@link COSEKeyTypes#EC2 EC2}Ed448 for use w/ EdDSA only
*
* * @since 1.1 * * @see IANA: COSE Elliptic Curves */ public final class COSEEllipticCurves { /** P-256 (1) */ public static final int P_256 = 1; /** P-384 (2) */ public static final int P_384 = 2; /** P-521 (3) */ public static final int P_521 = 3; /** X25519 (4) */ public static final int X25519 = 4; /** X448 (5) */ public static final int X448 = 5; /** Ed25519 (6) */ public static final int Ed25519 = 6; /** Ed448 (7) */ public static final int Ed448 = 7; /** secp256k1 (8) */ public static final int SECP256K1 = 8; /** * "P-256" * * @since 1.5 */ public static final String P_256_NAME = "P-256"; /** * "P-384" * * @since 1.5 */ public static final String P_384_NAME = "P-384"; /** * "P-521" * * @since 1.5 */ public static final String P_521_NAME = "P-521"; /** * "X25519" * * @since 1.5 */ public static final String X25519_NAME = "X25519"; /** * "X448" * * @since 1.5 */ public static final String X448_NAME = "X448"; /** * "Ed25519" * * @since 1.5 */ public static final String Ed25519_NAME = "Ed25519"; /** * "Ed448" * * @since 1.5 */ public static final String Ed448_NAME = "Ed448"; /** * "secp256k1" * * @since 1.5 */ public static final String SECP256K1_NAME = "secp256k1"; private static final int[] values = { P_256, P_384, P_521, X25519, X448, Ed25519, Ed448, SECP256K1, }; private static final String[] names = { P_256_NAME, P_384_NAME, P_521_NAME, X25519_NAME, X448_NAME, Ed25519_NAME, Ed448_NAME, SECP256K1_NAME }; private static final Map valueToNameMap = createValueToNameMap(); private static final Map nameToValueMap = createNameToValueMap(); private static Map createValueToNameMap() { Map map = new LinkedHashMap<>(); for (int i = 0; i < values.length; i++) { map.put(values[i], names[i]); } return map; } private static Map createNameToValueMap() { Map map = new LinkedHashMap<>(); for (int i = 0; i < names.length; i++) { map.put(names[i], values[i]); } return map; } /** * Get the integer identifier assigned to the elliptic curve. * * @param name * An elliptic curve name such as {@code "P-256"}. * If {@code null} is given, 0 is returned. * * @return * The integer identifier assigned to the elliptic curve. * If the given name is not recognized, 0 is returned. */ public static int getValueByName(String name) { if (name == null) { return 0; } return nameToValueMap.getOrDefault(name, 0); } /** * Get the name of the elliptic curve to which the integer identifier * has been assigned to. * * @param value * An integer identifier assigned to an elliptic curve. * * @return * The name of the elliptic curve to which the integer identifier * has been assigned to. If the given identifier is not recognized, * {@code null} is returned. */ public static String getNameByValue(int value) { return valueToNameMap.getOrDefault(value, null); } private COSEEllipticCurves() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy