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.HashAlgorithmTags; 022 023public enum HashAlgorithm { 024 025 MD5 (HashAlgorithmTags.MD5), 026 SHA1 (HashAlgorithmTags.SHA1), 027 RIPEMD160 (HashAlgorithmTags.RIPEMD160), 028 DOUBLE_SHA (HashAlgorithmTags.DOUBLE_SHA), 029 MD2 (HashAlgorithmTags.MD2), 030 TIGER_192 (HashAlgorithmTags.TIGER_192), 031 HAVAL_5_160(HashAlgorithmTags.HAVAL_5_160), 032 SHA256 (HashAlgorithmTags.SHA256), 033 SHA384 (HashAlgorithmTags.SHA384), 034 SHA512 (HashAlgorithmTags.SHA512), 035 SHA224 (HashAlgorithmTags.SHA224), 036 ; 037 // Coincidence? I don't this so... 038 private static final Map<Integer, HashAlgorithm> MAP = new HashMap<>(); 039 040 static { 041 for (HashAlgorithm h : HashAlgorithm.values()) { 042 MAP.put(h.algorithmId, h); 043 } 044 } 045 046 public static HashAlgorithm fromId(int id) { 047 return MAP.get(id); 048 } 049 050 private final int algorithmId; 051 052 HashAlgorithm(int id) { 053 this.algorithmId = id; 054 } 055 056 public int getAlgorithmId() { 057 return algorithmId; 058 } 059}