pgpainless/pgpainless-core/src/main/java/org/pgpainless/algorithm/PublicKeyAlgorithm.java

111 lines
2.8 KiB
Java
Raw Normal View History

/*
* Copyright 2018 Paul Schaub.
*
* 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 org.pgpainless.algorithm;
2018-06-02 21:21:35 +02:00
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
2018-06-02 21:21:35 +02:00
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
public enum PublicKeyAlgorithm {
/**
* RSA capable of encryption and signatures.
*/
2018-07-02 21:40:59 +02:00
RSA_GENERAL (PublicKeyAlgorithmTags.RSA_GENERAL),
/**
* RSA with usage encryption.
*
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
*/
2018-07-02 21:40:59 +02:00
RSA_ENCRYPT (PublicKeyAlgorithmTags.RSA_ENCRYPT),
/**
* RSA with usage of creating signatures.
*
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
*/
2018-07-02 21:40:59 +02:00
RSA_SIGN (PublicKeyAlgorithmTags.RSA_SIGN),
/**
* ElGamal with usage encryption.
*/
2018-07-02 21:40:59 +02:00
ELGAMAL_ENCRYPT (PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT),
/**
* Digital Signature Algorithm.
*/
2018-07-02 21:40:59 +02:00
DSA (PublicKeyAlgorithmTags.DSA),
2018-06-02 21:21:35 +02:00
/**
2018-07-02 21:40:59 +02:00
* EC is deprecated.
2018-06-02 21:21:35 +02:00
* @deprecated use {@link #ECDH} instead.
*/
2018-07-02 21:40:59 +02:00
EC (PublicKeyAlgorithmTags.EC),
/**
* Elliptic Curve Diffie-Hellman.
*/
2018-07-02 21:40:59 +02:00
ECDH (PublicKeyAlgorithmTags.ECDH),
/**
* Elliptic Curve Digital Signature Algorithm.
*/
2018-07-02 21:40:59 +02:00
ECDSA (PublicKeyAlgorithmTags.ECDSA),
2020-12-11 18:14:36 +01:00
/**
* ElGamal General.
*
2020-12-11 18:14:36 +01:00
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.8
*/
@Deprecated
2018-07-02 21:40:59 +02:00
ELGAMAL_GENERAL (PublicKeyAlgorithmTags.ELGAMAL_GENERAL),
/**
* Diffie-Hellman key exchange algorithm.
*/
2018-07-02 21:40:59 +02:00
DIFFIE_HELLMAN (PublicKeyAlgorithmTags.DIFFIE_HELLMAN),
/**
* Digital Signature Algorithm based on twisted Edwards Curves.
*/
EDDSA (PublicKeyAlgorithmTags.EDDSA),
2018-06-02 21:21:35 +02:00
;
private static final Map<Integer, PublicKeyAlgorithm> MAP = new ConcurrentHashMap<>();
2018-06-02 21:21:35 +02:00
static {
for (PublicKeyAlgorithm p : PublicKeyAlgorithm.values()) {
MAP.put(p.algorithmId, p);
}
}
public static PublicKeyAlgorithm fromId(int id) {
return MAP.get(id);
}
private final int algorithmId;
PublicKeyAlgorithm(int algorithmId) {
this.algorithmId = algorithmId;
}
public int getAlgorithmId() {
return algorithmId;
}
}