Author: ggregory Date: Sun Sep 2 17:37:37 2012 New Revision: 1380010 URL: http://svn.apache.org/viewvc?rev=1380010&view=rev Log: [CODEC-155] DigestUtils.getDigest(String) should throw IllegalArgumentException instead of RuntimeException.
Modified: commons/proper/codec/trunk/src/changes/changes.xml commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java Modified: commons/proper/codec/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1380010&r1=1380009&r2=1380010&view=diff ============================================================================== --- commons/proper/codec/trunk/src/changes/changes.xml (original) +++ commons/proper/codec/trunk/src/changes/changes.xml Sun Sep 2 17:37:37 2012 @@ -51,6 +51,9 @@ The <action> type attribute can be add,u </release> --> <release version="1.7" date="TBD" description="Feature and fix release."> + <action issue="CODEC-155" dev="ggregory" type="add" due-to="ggregory"> + DigestUtils.getDigest(String) should throw IllegalArgumentException instead of RuntimeException. + </action> <action issue="CODEC-153" dev="ggregory" type="add" due-to="ggregory"> Create a class MessageDigestAlgorithms to define standard algorithm names. </action> Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java?rev=1380010&r1=1380009&r2=1380010&view=diff ============================================================================== --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java Sun Sep 2 17:37:37 2012 @@ -78,14 +78,14 @@ public class DigestUtils { * names. * @return An MD5 digest instance. * @see MessageDigest#getInstance(String) - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught. */ public static MessageDigest getDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } } @@ -93,8 +93,10 @@ public class DigestUtils { * Returns an MD5 MessageDigest. * * @return An MD5 digest instance. - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught, which should never happen because MD5 is a + * built-in algorithm + * @see MessageDigestAlgorithms#MD5 */ public static MessageDigest getMd5Digest() { return getDigest(MessageDigestAlgorithms.MD5); @@ -107,8 +109,10 @@ public class DigestUtils { * </p> * * @return An SHA-256 digest instance. - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught, which should never happen because SHA-256 is a + * built-in algorithm + * @see MessageDigestAlgorithms#SHA_256 */ public static MessageDigest getSha256Digest() { return getDigest(MessageDigestAlgorithms.SHA_256); @@ -121,8 +125,10 @@ public class DigestUtils { * </p> * * @return An SHA-384 digest instance. - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught, which should never happen because SHA-384 is a + * built-in algorithm + * @see MessageDigestAlgorithms#SHA_384 */ public static MessageDigest getSha384Digest() { return getDigest(MessageDigestAlgorithms.SHA_384); @@ -135,8 +141,10 @@ public class DigestUtils { * </p> * * @return An SHA-512 digest instance. - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught, which should never happen because SHA-512 is a + * built-in algorithm + * @see MessageDigestAlgorithms#SHA_512 */ public static MessageDigest getSha512Digest() { return getDigest(MessageDigestAlgorithms.SHA_512); @@ -146,8 +154,8 @@ public class DigestUtils { * Returns an SHA-1 digest. * * @return An SHA-1 digest instance. - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught */ public static MessageDigest getShaDigest() { return getDigest("SHA"); Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java?rev=1380010&r1=1380009&r2=1380010&view=diff ============================================================================== --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java Sun Sep 2 17:37:37 2012 @@ -17,6 +17,7 @@ package org.apache.commons.codec.digest; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -117,8 +118,9 @@ public class Sha2Crypt { * @return complete hash value including prefix and salt * @throws IllegalArgumentException * if the given salt is {@code null} or does not match the allowed pattern - * @throws RuntimeException - * when a {@link java.security.NoSuchAlgorithmException} is caught. + * @throws IllegalArgumentException + * when a {@link NoSuchAlgorithmException} is caught + * @see MessageDigestAlgorithms */ private static String sha2Crypt(byte[] keyBytes, String salt, String saltPrefix, int blocksize, String algorithm) {