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

com.nimbusds.jose.crypto.impl.ECDSAProvider Maven / Gradle / Ivy

Go to download

Java library for Javascript Object Signing and Encryption (JOSE) and JSON Web Tokens (JWT)

There is a newer version: 9.47
Show newest version
/*
 * nimbus-jose-jwt
 *
 * Copyright 2012-2016, Connect2id Ltd and contributors.
 *
 * 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
 *
 *    http://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.nimbusds.jose.crypto.impl;


import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.jwk.Curve;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;


/**
 * The base abstract class for Elliptic Curve Digital Signature Algorithm 
 * (ECDSA) signers and validators of {@link com.nimbusds.jose.JWSObject JWS 
 * objects}.
 *
 * 

Supports the following algorithms: * *

    *
  • {@link com.nimbusds.jose.JWSAlgorithm#ES256} *
  • {@link com.nimbusds.jose.JWSAlgorithm#ES256K} *
  • {@link com.nimbusds.jose.JWSAlgorithm#ES384} *
  • {@link com.nimbusds.jose.JWSAlgorithm#ES512} *
* * @author Axel Nennker * @author Vladimir Dzhuvinov * @version 2024-05-07 */ public abstract class ECDSAProvider extends BaseJWSProvider { /** * The supported JWS algorithms by the EC-DSA provider class. */ public static final Set SUPPORTED_ALGORITHMS; /** * The supported curves by the EC-DSA provider class. */ public static final Set SUPPORTED_CURVES; static { Set algs = new LinkedHashSet<>(); algs.add(JWSAlgorithm.ES256); algs.add(JWSAlgorithm.ES256K); algs.add(JWSAlgorithm.ES384); algs.add(JWSAlgorithm.ES512); SUPPORTED_ALGORITHMS = Collections.unmodifiableSet(algs); Set curves = new LinkedHashSet<>(); curves.add(Curve.P_256); curves.add(Curve.SECP256K1); curves.add(Curve.P_384); curves.add(Curve.P_521); SUPPORTED_CURVES = Collections.unmodifiableSet(curves); } /** * Creates a new Elliptic Curve Digital Signature Algorithm (ECDSA) * provider. * * @param alg The EC-DSA algorithm. Must be supported and not * {@code null}. * * @throws JOSEException If JWS algorithm is not supported. */ protected ECDSAProvider(final JWSAlgorithm alg) throws JOSEException { super(Collections.singleton(alg)); if (! SUPPORTED_ALGORITHMS.contains(alg)) { throw new JOSEException("Unsupported EC DSA algorithm: " + alg); } } /** * Returns the supported ECDSA algorithm. * * @see #supportedJWSAlgorithms() * * @return The supported ECDSA algorithm. */ public JWSAlgorithm supportedECDSAAlgorithm() { return supportedJWSAlgorithms().iterator().next(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy