Author: sebb
Date: Mon May 23 12:19:56 2016
New Revision: 1745171

URL: http://svn.apache.org/viewvc?rev=1745171&view=rev
Log:
Check for algorithm availability

Modified:
    
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/HmacUtils.java

Modified: 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/HmacUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/HmacUtils.java?rev=1745171&r1=1745170&r2=1745171&view=diff
==============================================================================
--- 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/HmacUtils.java
 (original)
+++ 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/HmacUtils.java
 Mon May 23 12:19:56 2016
@@ -59,6 +59,38 @@ public final class HmacUtils {
     private static final int STREAM_BUFFER_LENGTH = 1024;
 
     /**
+    * Returns whether this algorithm is available
+    *
+    *@param name the name to check
+    * @return whether this algorithm is available
+    * @since 1.11
+    */
+    public static boolean isAvailable(String name) {
+        try {
+            Mac.getInstance(name);
+            return true;
+        } catch (NoSuchAlgorithmException e) {
+            return false;
+        }
+    }
+
+    /**
+    * Returns whether this algorithm is available
+    *
+    *@param name the name to check
+    * @return whether this algorithm is available
+    * @since 1.11
+    */
+    public static boolean isAvailable(HmacAlgorithms name) {
+        try {
+            Mac.getInstance(name.getName());
+            return true;
+        } catch (NoSuchAlgorithmException e) {
+            return false;
+        }
+    }
+
+    /**
      * Returns an initialized <code>Mac</code> for the HmacMD5 algorithm.
      * <p>
      * Every implementation of the Java platform is required to support this 
standard Mac algorithm.


Reply via email to