001/* 002 * Copyright 2018 Paul Schaub. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.pgpainless.algorithm; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; 022 023public enum PublicKeyAlgorithm { 024 025 RSA_GENERAL (PublicKeyAlgorithmTags.RSA_GENERAL), 026 RSA_ENCRYPT (PublicKeyAlgorithmTags.RSA_ENCRYPT), 027 RSA_SIGN (PublicKeyAlgorithmTags.RSA_SIGN), 028 ELGAMAL_ENCRYPT (PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT), 029 DSA (PublicKeyAlgorithmTags.DSA), 030 /** 031 * EC is deprecated. 032 * @deprecated use {@link #ECDH} instead. 033 */ 034 EC (PublicKeyAlgorithmTags.EC), 035 ECDH (PublicKeyAlgorithmTags.ECDH), 036 ECDSA (PublicKeyAlgorithmTags.ECDSA), 037 ELGAMAL_GENERAL (PublicKeyAlgorithmTags.ELGAMAL_GENERAL), 038 DIFFIE_HELLMAN (PublicKeyAlgorithmTags.DIFFIE_HELLMAN), 039 ; 040 041 private static final Map<Integer, PublicKeyAlgorithm> MAP = new HashMap<>(); 042 043 static { 044 for (PublicKeyAlgorithm p : PublicKeyAlgorithm.values()) { 045 MAP.put(p.algorithmId, p); 046 } 047 } 048 049 public static PublicKeyAlgorithm fromId(int id) { 050 return MAP.get(id); 051 } 052 053 private final int algorithmId; 054 055 PublicKeyAlgorithm(int algorithmId) { 056 this.algorithmId = algorithmId; 057 } 058 059 public int getAlgorithmId() { 060 return algorithmId; 061 } 062}