You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2003/11/03 05:06:07 UTC

cvs commit: jakarta-commons/codec/src/java/org/apache/commons/codec/digest DigestUtils.java

ggregory    2003/11/02 20:06:07

  Modified:    codec/src/java/org/apache/commons/codec/digest
                        DigestUtils.java
  Log:
  Refactor common code and complete test coverage (100%, see clover report).
  
  Revision  Changes    Path
  1.6       +26 -19    jakarta-commons/codec/src/java/org/apache/commons/codec/digest/DigestUtils.java
  
  Index: DigestUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/digest/DigestUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DigestUtils.java	15 Oct 2003 02:10:28 -0000	1.5
  +++ DigestUtils.java	3 Nov 2003 04:06:07 -0000	1.6
  @@ -63,40 +63,47 @@
   import org.apache.commons.codec.binary.Hex;
   
   /**
  - * Operations to simplifiy common <code>MessageDigest</code> tasks.  This
  + * Operations to simplifiy common {@link java.security.MessageDigest} tasks.  This
    * class is thread safe.
    *
    * @author Dave Dribin
    * @author David Graham
  + * @author Gary Gregory
    */
   public class DigestUtils {
   
  -	/**
  -	 * Returns an MD5 MessageDigest.
  -	 *
  -	 * @return An MD5 digest instance.
  -	 */
  -	private static MessageDigest getMd5Digest() {
  -		try {
  -			return MessageDigest.getInstance("MD5");
  +    /**
  +     * Returns a MessageDigest for the given <code>algorithm</code>.
  +     *
  +     * @return An MD5 digest instance.
  +     * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
  +     */
  +    protected static MessageDigest getDigest(String algorithm) {
  +        try {
  +            return MessageDigest.getInstance(algorithm);
  +        } catch (NoSuchAlgorithmException e) {
  +            throw new RuntimeException(e.getMessage());
  +        }
  +    }
   
  -		} catch (NoSuchAlgorithmException e) {
  -			throw new RuntimeException(e.getMessage());
  -		}
  -	}
  +    /**
  +     * Returns an MD5 MessageDigest.
  +     *
  +     * @return An MD5 digest instance.
  +     * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
  +     */
  +    private static MessageDigest getMd5Digest() {
  +        return getDigest("MD5");
  +    }
   
   	/**
   	 * Returns an SHA digest.
   	 *
   	 * @return An SHA digest instance.
  +     * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
   	 */
   	private static MessageDigest getShaDigest() {
  -		try {
  -			return MessageDigest.getInstance("SHA");
  -
  -		} catch (NoSuchAlgorithmException e) {
  -			throw new RuntimeException(e.getMessage());
  -		}
  +        return getDigest("SHA");
   	}
   
   	/**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org