Skip to content

Commit 09db9da

Browse files
committed
Check for algorithm availability
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1745171 13f79535-47bb-0310-9956-ffa450edef68
1 parent b5955f5 commit 09db9da

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/main/java/org/apache/commons/codec/digest/HmacUtils.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ public final class HmacUtils {
5858

5959
private static final int STREAM_BUFFER_LENGTH = 1024;
6060

61+
/**
62+
* Returns whether this algorithm is available
63+
*
64+
*@param name the name to check
65+
* @return whether this algorithm is available
66+
* @since 1.11
67+
*/
68+
public static boolean isAvailable(String name) {
69+
try {
70+
Mac.getInstance(name);
71+
return true;
72+
} catch (NoSuchAlgorithmException e) {
73+
return false;
74+
}
75+
}
76+
77+
/**
78+
* Returns whether this algorithm is available
79+
*
80+
*@param name the name to check
81+
* @return whether this algorithm is available
82+
* @since 1.11
83+
*/
84+
public static boolean isAvailable(HmacAlgorithms name) {
85+
try {
86+
Mac.getInstance(name.getName());
87+
return true;
88+
} catch (NoSuchAlgorithmException e) {
89+
return false;
90+
}
91+
}
92+
6193
/**
6294
* Returns an initialized <code>Mac</code> for the HmacMD5 algorithm.
6395
* <p>

0 commit comments

Comments
 (0)