1 /*- 2 * #%L 3 * io.earcam.instrumental.archive.sign 4 * %% 5 * Copyright (C) 2018 earcam 6 * %% 7 * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) 8 * 9 * You <b>must</b> choose to accept, in full - any individual or combination of 10 * the following licenses: 11 * <ul> 12 * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> 13 * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> 14 * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> 15 * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> 16 * </ul> 17 * #L% 18 */ 19 package io.earcam.instrumental.archive.sign; 20 21 import java.security.MessageDigest; 22 23 import io.earcam.unexceptional.Exceptional; 24 25 /** 26 * <p> 27 * Minimum supported, see § Algorithms in 28 * https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Notes_on_Manifest_and_Signature_Files 29 * </p> 30 */ 31 public enum StandardDigestAlgorithms { 32 33 // @formatter:off 34 /** 35 * Note: MD5 is slated for removal, JDK10 won't consider JAR as signed when using this as a Digest Algorithm 36 */ 37 MD5("MD5"), 38 SHA1("SHA1"), 39 SHA224("SHA-224"), 40 SHA256("SHA-256"), 41 SHA384("SHA-384"), 42 SHA512("SHA-512"), 43 ; 44 // @formatter:on 45 46 private final String algorithm; 47 48 49 StandardDigestAlgorithms(String algorithm) 50 { 51 this.algorithm = algorithm; 52 } 53 54 55 /** 56 * <p> 57 * algorithm. 58 * </p> 59 * 60 * @return a {@link java.lang.String} object. 61 */ 62 public String algorithm() 63 { 64 return algorithm; 65 } 66 67 68 /** 69 * @return a new MessageDigest instance for the given algorithm 70 * @throws io.earcam.unexceptional.UncheckedSecurityException if no such algorithm is available 71 */ 72 public MessageDigest create() 73 { 74 return Exceptional.apply(MessageDigest::getInstance, algorithm()); 75 } 76 }