You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2016/05/17 00:45:28 UTC
svn commit: r1744172 - in /commons/proper/codec/trunk/src: changes/
main/java/org/apache/commons/codec/digest/
test/java/org/apache/commons/codec/digest/
Author: sebb
Date: Tue May 17 00:45:28 2016
New Revision: 1744172
URL: http://svn.apache.org/viewvc?rev=1744172&view=rev
Log:
Revert CODEC-211
Removed:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/MessageDigestAlgorithm.java
Modified:
commons/proper/codec/trunk/src/changes/changes.xml
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Digest.java
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmTest.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=1744172&r1=1744171&r2=1744172&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/changes/changes.xml (original)
+++ commons/proper/codec/trunk/src/changes/changes.xml Tue May 17 00:45:28 2016
@@ -52,7 +52,6 @@ The <action> type attribute can be add,u
<action dev="ggregory" type="add" issue="CODEC-217" due-to="Gary Gregory">Add HmacAlgorithms.HMAC_SHA_224 (Java 8 only)</action>
<action dev="ggregory" type="add" issue="CODEC-213" due-to="Gary Gregory">Support JEP 287: SHA-3 Hash Algorithms</action>
<action dev="ggregory" type="add" issue="CODEC-212" due-to="Gary Gregory">Create a minimal Digest command line utility: org.apache.commons.codec.digest.Digest</action>
- <action dev="ggregory" type="add" issue="CODEC-211" due-to="Gary Gregory">Create enum MessageDigestAlgorithm and deprecate class MessageDigestAlgorithms</action>
<action dev="ggregory" type="add" issue="CODEC-210" due-to="Gary Gregory">Add DigestUtils.getDigest(String, MessageDigest)</action>
<action dev="ggregory" type="add" issue="CODEC-208" due-to="Gary Gregory">Make some DigestUtils APIs public</action>
<action dev="ggregory" type="add" issue="CODEC-206" due-to="Gary Gregory">Add java.io.File APIs to MessageDigestAlgorithm</action>
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Digest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Digest.java?rev=1744172&r1=1744171&r2=1744172&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Digest.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Digest.java Tue May 17 00:45:28 2016
@@ -76,21 +76,21 @@ public class Digest {
private void run() throws IOException {
if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
- run(MessageDigestAlgorithm.values());
+ run(MessageDigestAlgorithms.values());
return;
}
final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
if (messageDigest != null) {
run("", messageDigest);
} else {
- run("", MessageDigestAlgorithm.valueOf(algorithm.toUpperCase(Locale.ROOT)).getMessageDigest());
+ run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
}
}
- private void run(MessageDigestAlgorithm[] digestAlgorithms) throws IOException {
- for (MessageDigestAlgorithm messageDigestAlgorithm : digestAlgorithms) {
- if (messageDigestAlgorithm.isAvailable()) {
- run(messageDigestAlgorithm.getName() + " ", messageDigestAlgorithm);
+ private void run(String[] digestAlgorithms) throws IOException {
+ for (String messageDigestAlgorithm : digestAlgorithms) {
+ if (DigestUtils.isAvailable(messageDigestAlgorithm)) {
+ run(messageDigestAlgorithm + " ", messageDigestAlgorithm);
}
}
}
@@ -116,8 +116,8 @@ public class Digest {
}
}
- private void run(String prefix, final MessageDigestAlgorithm messageDigestAlgorithm) throws IOException {
- run(prefix, messageDigestAlgorithm.getMessageDigest());
+ private void run(String prefix, final String messageDigestAlgorithm) throws IOException {
+ run(prefix, DigestUtils.getDigest(messageDigestAlgorithm));
}
@Override
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=1744172&r1=1744171&r2=1744172&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 Tue May 17 00:45:28 2016
@@ -161,7 +161,7 @@ public class DigestUtils {
* @since 1.7
*/
public static MessageDigest getMd2Digest() {
- return MessageDigestAlgorithm.MD2.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.MD2);
}
/**
@@ -174,7 +174,7 @@ public class DigestUtils {
* @see MessageDigestAlgorithm#MD5
*/
public static MessageDigest getMd5Digest() {
- return MessageDigestAlgorithm.MD5.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.MD5);
}
/**
@@ -188,7 +188,7 @@ public class DigestUtils {
* @since 1.7
*/
public static MessageDigest getSha1Digest() {
- return MessageDigestAlgorithm.SHA_1.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.SHA_1);
}
/**
@@ -202,9 +202,10 @@ public class DigestUtils {
* when a {@link NoSuchAlgorithmException} is caught on Java 7 and older, SHA-224 is a built-in
* algorithm on Java 8
* @see MessageDigestAlgorithm#SHA_224
+ * @since 1.11
*/
public static MessageDigest getSha224Digest() {
- return MessageDigestAlgorithm.SHA_224.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.SHA_224);
}
/**
@@ -220,7 +221,7 @@ public class DigestUtils {
* @see MessageDigestAlgorithm#SHA_256
*/
public static MessageDigest getSha256Digest() {
- return MessageDigestAlgorithm.SHA_256.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.SHA_256);
}
/**
@@ -236,7 +237,7 @@ public class DigestUtils {
* @see MessageDigestAlgorithm#SHA_384
*/
public static MessageDigest getSha384Digest() {
- return MessageDigestAlgorithm.SHA_384.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.SHA_384);
}
/**
@@ -252,7 +253,7 @@ public class DigestUtils {
* @see MessageDigestAlgorithm#SHA_512
*/
public static MessageDigest getSha512Digest() {
- return MessageDigestAlgorithm.SHA_512.getMessageDigest();
+ return getDigest(MessageDigestAlgorithms.SHA_512);
}
/**
@@ -300,6 +301,20 @@ public class DigestUtils {
* @return MD2 digest
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] md2(final File data) throws IOException {
+ return digest(getMd2Digest(), data);
+ }
+
+ /**
+ * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
+ *
+ * @param data
+ * Data to digest
+ * @return MD2 digest
+ * @throws IOException
+ * On error reading from the stream
* @since 1.7
*/
public static byte[] md2(final InputStream data) throws IOException {
@@ -350,6 +365,20 @@ public class DigestUtils {
* @return MD2 digest as a hex string
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static String md2Hex(final File data) throws IOException {
+ return Hex.encodeHexString(md2(data));
+ }
+
+ /**
+ * Calculates the MD2 digest and returns the value as a 32 character hex string.
+ *
+ * @param data
+ * Data to digest
+ * @return MD2 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
* @since 1.7
*/
public static String md2Hex(final InputStream data) throws IOException {
@@ -399,6 +428,20 @@ public class DigestUtils {
* @return MD5 digest
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] md5(final File data) throws IOException {
+ return digest(getMd5Digest(), data);
+ }
+
+ /**
+ * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
+ *
+ * @param data
+ * Data to digest
+ * @return MD5 digest
+ * @throws IOException
+ * On error reading from the stream
* @since 1.4
*/
public static byte[] md5(final InputStream data) throws IOException {
@@ -447,6 +490,20 @@ public class DigestUtils {
* @return MD5 digest as a hex string
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static String md5Hex(final File data) throws IOException {
+ return Hex.encodeHexString(md5(data));
+ }
+
+ /**
+ * Calculates the MD5 digest and returns the value as a 32 character hex string.
+ *
+ * @param data
+ * Data to digest
+ * @return MD5 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
* @since 1.4
*/
public static String md5Hex(final InputStream data) throws IOException {
@@ -538,6 +595,20 @@ public static byte[] sha(final byte[] da
* @return SHA-1 digest
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] sha1(final File data) throws IOException {
+ return digest(getSha1Digest(), data);
+ }
+
+ /**
+ * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
+ *
+ * @param data
+ * Data to digest
+ * @return SHA-1 digest
+ * @throws IOException
+ * On error reading from the stream
* @since 1.7
*/
public static byte[] sha1(final InputStream data) throws IOException {
@@ -587,6 +658,20 @@ public static byte[] sha(final byte[] da
* @return SHA-1 digest as a hex string
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static String sha1Hex(final File data) throws IOException {
+ return Hex.encodeHexString(sha1(data));
+ }
+
+ /**
+ * Calculates the SHA-1 digest and returns the value as a hex string.
+ *
+ * @param data
+ * Data to digest
+ * @return SHA-1 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
* @since 1.7
*/
public static String sha1Hex(final InputStream data) throws IOException {
@@ -637,6 +722,24 @@ public static byte[] sha(final byte[] da
/**
* Calculates the SHA-224 digest and returns the value as a <code>byte[]</code>.
* <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.8.0.
+ * </p>
+ *
+ * @param data
+ * File to digest
+ * @return SHA-224 digest
+ * @throws IOException
+ * On error reading from the stream
+ * @throws IllegalArgumentException thrown on JRE versions prior to 1.8.0.
+ * @since 1.11
+ */
+ public static byte[] sha224(final File data) throws IOException {
+ return digest(getSha224Digest(), data);
+ }
+
+ /**
+ * Calculates the SHA-224 digest and returns the value as a <code>byte[]</code>.
+ * <p>
* Throws a {@link IllegalArgumentException} on JRE versions prior to 1.8.0.
* </p>
*
@@ -714,6 +817,24 @@ public static byte[] sha(final byte[] da
* @throws IllegalArgumentException thrown on JRE versions prior to 1.8.0.
* @since 1.11
*/
+ public static String sha224Hex(final File data) throws IOException {
+ return Hex.encodeHexString(sha224(data));
+ }
+
+ /**
+ * Calculates the SHA-224 digest and returns the value as a hex string.
+ * <p>
+ * Throws a {@link IllegalArgumentException} on JRE versions prior to 1.8.0.
+ * </p>
+ *
+ * @param data
+ * Data to digest
+ * @return SHA-224 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
+ * @throws IllegalArgumentException thrown on JRE versions prior to 1.8.0.
+ * @since 1.11
+ */
public static String sha224Hex(final InputStream data) throws IOException {
return Hex.encodeHexString(sha224(data));
}
@@ -768,6 +889,23 @@ public static byte[] sha(final byte[] da
* </p>
*
* @param data
+ * File to digest
+ * @return SHA-256 digest
+ * @throws IOException
+ * On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] sha256(final File data) throws IOException {
+ return digest(getSha256Digest(), data);
+ }
+
+ /**
+ * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
* Data to digest
* @return SHA-256 digest
* @throws IOException
@@ -831,6 +969,23 @@ public static byte[] sha(final byte[] da
* @return SHA-256 digest as a hex string
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static String sha256Hex(final File data) throws IOException {
+ return Hex.encodeHexString(sha256(data));
+ }
+
+ /**
+ * Calculates the SHA-256 digest and returns the value as a hex string.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
+ * Data to digest
+ * @return SHA-256 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
* @since 1.4
*/
public static String sha256Hex(final InputStream data) throws IOException {
@@ -886,6 +1041,23 @@ public static byte[] sha(final byte[] da
* </p>
*
* @param data
+ * File to digest
+ * @return SHA-384 digest
+ * @throws IOException
+ * On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] sha384(final File data) throws IOException {
+ return digest(getSha384Digest(), data);
+ }
+
+ /**
+ * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
* Data to digest
* @return SHA-384 digest
* @throws IOException
@@ -949,6 +1121,23 @@ public static byte[] sha(final byte[] da
* @return SHA-384 digest as a hex string
* @throws IOException
* On error reading from the stream
+ * @since 1.11
+ */
+ public static String sha384Hex(final File data) throws IOException {
+ return Hex.encodeHexString(sha384(data));
+ }
+
+ /**
+ * Calculates the SHA-384 digest and returns the value as a hex string.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
+ * Data to digest
+ * @return SHA-384 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
* @since 1.4
*/
public static String sha384Hex(final InputStream data) throws IOException {
@@ -1004,6 +1193,23 @@ public static byte[] sha(final byte[] da
* </p>
*
* @param data
+ * File to digest
+ * @return SHA-512 digest
+ * @throws IOException
+ * On error reading from the stream
+ * @since 1.11
+ */
+ public static byte[] sha512(final File data) throws IOException {
+ return digest(getSha512Digest(), data);
+ }
+
+ /**
+ * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
* Data to digest
* @return SHA-512 digest
* @throws IOException
@@ -1063,6 +1269,23 @@ public static byte[] sha(final byte[] da
* </p>
*
* @param data
+ * File to digest
+ * @return SHA-512 digest as a hex string
+ * @throws IOException
+ * On error reading from the stream
+ * @since 1.11
+ */
+ public static String sha512Hex(File data) throws IOException {
+ return Hex.encodeHexString(sha512(data));
+ }
+
+ /**
+ * Calculates the SHA-512 digest and returns the value as a hex string.
+ * <p>
+ * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
+ * </p>
+ *
+ * @param data
* Data to digest
* @return SHA-512 digest as a hex string
* @throws IOException
@@ -1206,7 +1429,12 @@ public static byte[] sha(final byte[] da
}
/**
- * Updates the given {@link MessageDigest}.
+ * Updates the given {@link MessageDigest} from a String (converted to bytes using UTF-8).
+ * <p>
+ * To update the digest using a different charset for the conversion,
+ * convert the String to a byte array using
+ * {@link String#getBytes(java.nio.charset.Charset)} and pass that
+ * to the {@link DigestUtils#updateDigest(MessageDigest, byte[])} method
*
* @param messageDigest
* the {@link MessageDigest} to update
@@ -1221,4 +1449,14 @@ public static byte[] sha(final byte[] da
return messageDigest;
}
+ /**
+ * Test whether the algorithm is supported.
+ * @param messageDigestAlgorithm the algorithm name
+ * @return {@code true} if the algorithm can be found
+ * @since 1.7
+ */
+ public static boolean isAvailable(String messageDigestAlgorithm) {
+ return getDigest(messageDigestAlgorithm, null) != null;
+ }
+
}
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmTest.java?rev=1744172&r1=1744171&r2=1744172&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmTest.java Tue May 17 00:45:28 2016
@@ -22,8 +22,6 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-
-import org.apache.commons.codec.binary.Hex;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
@@ -43,24 +41,19 @@ public class MessageDigestAlgorithmTest
@Parameters(name = "{0}")
public static Object[] data() {
- return MessageDigestAlgorithm.values();
+ return MessageDigestAlgorithms.values();
}
private DigestUtilsTest digestUtilsTest;
- private final MessageDigestAlgorithm messageDigestAlgorithm;
+ private final String messageDigestAlgorithm;
- public MessageDigestAlgorithmTest(MessageDigestAlgorithm messageDigestAlgorithm) {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ public MessageDigestAlgorithmTest(String messageDigestAlgorithm) {
this.messageDigestAlgorithm = messageDigestAlgorithm;
}
private byte[] digestTestData() throws IOException {
- return messageDigestAlgorithm.digest(getTestData());
- }
-
- private String digestTestDataHex() throws IOException {
- return Hex.encodeHexString(digestTestData());
+ return DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData());
}
private byte[] getTestData() {
@@ -85,76 +78,50 @@ public class MessageDigestAlgorithmTest
@Test
public void testAlgorithm() throws IOException, NoSuchAlgorithmException {
- final String algorithm = messageDigestAlgorithm.getName();
+ final String algorithm = messageDigestAlgorithm;
Assert.assertNotNull(algorithm);
Assert.assertFalse(algorithm.isEmpty());
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
MessageDigest.getInstance(algorithm);
}
@Test
public void testDigestByteArray() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
Assert.assertArrayEquals(digestTestData(),
- DigestUtils.digest(messageDigestAlgorithm.getMessageDigest(), getTestData()));
- Assert.assertArrayEquals(digestTestData(), messageDigestAlgorithm.digest(getTestData()));
- }
-
- @Test
- public void testDigestByteArrayHex() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
- Assert.assertEquals(digestTestDataHex(), messageDigestAlgorithm.digestHex(getTestData()));
+ DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData()));
+ Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData()));
}
@Test
public void testDigestByteBuffer() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
Assert.assertArrayEquals(digestTestData(),
- DigestUtils.digest(messageDigestAlgorithm.getMessageDigest(), ByteBuffer.wrap(getTestData())));
- Assert.assertArrayEquals(digestTestData(), messageDigestAlgorithm.digest(ByteBuffer.wrap(getTestData())));
- }
-
- @Test
- public void testDigestByteBufferHex() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
- Assert.assertEquals(digestTestDataHex(), messageDigestAlgorithm.digestHex(ByteBuffer.wrap(getTestData())));
+ DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), ByteBuffer.wrap(getTestData())));
+ Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),ByteBuffer.wrap(getTestData())));
}
@Test
public void testDigestFile() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
Assert.assertArrayEquals(digestTestData(),
- DigestUtils.digest(messageDigestAlgorithm.getMessageDigest(), getTestFile()));
- Assert.assertArrayEquals(digestTestData(), messageDigestAlgorithm.digest(getTestFile()));
- }
-
- @Test
- public void testDigestFileHex() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
- Assert.assertEquals(digestTestDataHex(), messageDigestAlgorithm.digestHex(getTestFile()));
+ DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestFile()));
+ Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestFile()));
}
@Test
public void testDigestInputStream() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
Assert.assertArrayEquals(digestTestData(),
- DigestUtils.digest(messageDigestAlgorithm.getMessageDigest(), new ByteArrayInputStream(getTestData())));
- Assert.assertArrayEquals(digestTestData(),
- messageDigestAlgorithm.digest(new ByteArrayInputStream(getTestData())));
- }
-
- @Test
- public void testDigestInputStreamHex() throws IOException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
- Assert.assertEquals(digestTestDataHex(),
- messageDigestAlgorithm.digestHex(new ByteArrayInputStream(getTestData())));
+ DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), new ByteArrayInputStream(getTestData())));
+ Assert.assertArrayEquals(digestTestData(), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),new ByteArrayInputStream(getTestData())));
}
@Test
public void testGetMessageDigest() throws IOException, NoSuchAlgorithmException {
- Assume.assumeTrue(messageDigestAlgorithm.isAvailable());
- final MessageDigest messageDigest = messageDigestAlgorithm.getMessageDigest();
- Assert.assertEquals(messageDigestAlgorithm.getName(), messageDigest.getAlgorithm());
+ Assume.assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
+ final MessageDigest messageDigest = DigestUtils.getDigest(messageDigestAlgorithm);
+ Assert.assertEquals(messageDigestAlgorithm, messageDigest.getAlgorithm());
}
}