2018-06-13 17:26:48 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-07-18 18:23:06 +02:00
|
|
|
package org.pgpainless.algorithm;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
import java.util.Map;
|
2020-01-09 20:49:12 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
|
|
|
|
|
|
|
|
public enum PublicKeyAlgorithm {
|
|
|
|
|
2020-12-11 22:52:28 +01:00
|
|
|
/**
|
|
|
|
* RSA capable of encryption and signatures.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
RSA_GENERAL (PublicKeyAlgorithmTags.RSA_GENERAL),
|
2020-12-11 18:15:54 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-11 22:52:28 +01:00
|
|
|
* RSA with usage encryption.
|
|
|
|
*
|
2020-12-11 18:15:54 +01:00
|
|
|
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
RSA_ENCRYPT (PublicKeyAlgorithmTags.RSA_ENCRYPT),
|
2020-12-11 18:15:54 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-11 22:52:28 +01:00
|
|
|
* RSA with usage of creating signatures.
|
|
|
|
*
|
2020-12-11 18:15:54 +01:00
|
|
|
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
RSA_SIGN (PublicKeyAlgorithmTags.RSA_SIGN),
|
2020-12-11 18:15:54 +01:00
|
|
|
|
2020-12-11 22:52:28 +01:00
|
|
|
/**
|
|
|
|
* ElGamal with usage encryption.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
ELGAMAL_ENCRYPT (PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT),
|
2020-12-11 18:15:54 +01:00
|
|
|
|
2020-12-11 22:52:28 +01:00
|
|
|
/**
|
|
|
|
* Digital Signature Algorithm.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
DSA (PublicKeyAlgorithmTags.DSA),
|
2020-12-11 22:52:28 +01:00
|
|
|
|
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),
|
2020-12-11 22:52:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Elliptic Curve Diffie-Hellman.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
ECDH (PublicKeyAlgorithmTags.ECDH),
|
2020-12-11 22:52:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Elliptic Curve Digital Signature Algorithm.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
ECDSA (PublicKeyAlgorithmTags.ECDSA),
|
2020-12-11 18:14:36 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-11 22:52:28 +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),
|
2020-12-11 22:52:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Diffie-Hellman key exchange algorithm.
|
|
|
|
*/
|
2018-07-02 21:40:59 +02:00
|
|
|
DIFFIE_HELLMAN (PublicKeyAlgorithmTags.DIFFIE_HELLMAN),
|
2020-12-11 22:52:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Digital Signature Algorithm based on twisted Edwards Curves.
|
|
|
|
*/
|
2020-12-06 18:04:14 +01:00
|
|
|
EDDSA (PublicKeyAlgorithmTags.EDDSA),
|
2018-06-02 21:21:35 +02:00
|
|
|
;
|
|
|
|
|
2020-01-09 20:49:12 +01: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;
|
|
|
|
}
|
|
|
|
}
|