Skip to content

Commit dbbb403

Browse files
committed
Add a HMAC_SHA_224 test on Java 8 only.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1811621 13f79535-47bb-0310-9956-ffa450edef68
1 parent c823576 commit dbbb403

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/test/java/org/apache/commons/codec/digest/HmacAlgorithmsTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
import java.io.ByteArrayInputStream;
2020
import java.io.IOException;
2121
import java.security.NoSuchAlgorithmException;
22+
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.Collection;
25+
import java.util.List;
2426

2527
import javax.crypto.Mac;
2628

29+
import org.apache.commons.lang3.JavaVersion;
30+
import org.apache.commons.lang3.SystemUtils;
2731
import org.junit.After;
2832
import org.junit.Assert;
2933
import org.junit.Assume;
@@ -59,6 +63,11 @@ public class HmacAlgorithmsTest {
5963

6064
static final String STANDARD_SHA1_RESULT_STRING = "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9";
6165

66+
static final byte[] STANDARD_SHA224_RESULT_BYTES = new byte[] { -120, -1, -117, 84, 103, 93, 57, -72, -9, 35, 34,
67+
-26, 95, -7, 69, -59, 45, -106, 55, -103, -120, -83, -94, 86, 57, 116, 126, 105 };
68+
69+
static final String STANDARD_SHA224_RESULT_STRING = "88ff8b54675d39b8f72322e65ff945c52d96379988ada25639747e69";
70+
6271
static final byte[] STANDARD_SHA256_RESULT_BYTES = new byte[] { -9, -68, -125, -12, 48, 83, -124, 36, -79, 50, -104,
6372
-26, -86, 111, -79, 67, -17, 77, 89, -95, 73, 70, 23, 89, -105, 71, -99, -68, 45, 26, 60, -40 };
6473

@@ -84,12 +93,19 @@ public class HmacAlgorithmsTest {
8493
// TODO HMAC_SHA_224
8594
@Parameters(name = "{0}")
8695
public static Collection<Object[]> data() {
87-
return Arrays.asList(
96+
List<Object[]> list = Arrays.asList(
97+
// @formatter:off
8898
new Object[][] { { HmacAlgorithms.HMAC_MD5, STANDARD_MD5_RESULT_BYTES, STANDARD_MD5_RESULT_STRING },
8999
{ HmacAlgorithms.HMAC_SHA_1, STANDARD_SHA1_RESULT_BYTES, STANDARD_SHA1_RESULT_STRING },
90100
{ HmacAlgorithms.HMAC_SHA_256, STANDARD_SHA256_RESULT_BYTES, STANDARD_SHA256_RESULT_STRING },
91101
{ HmacAlgorithms.HMAC_SHA_384, STANDARD_SHA384_RESULT_BYTES, STANDARD_SHA384_RESULT_STRING },
92102
{ HmacAlgorithms.HMAC_SHA_512, STANDARD_SHA512_RESULT_BYTES, STANDARD_SHA512_RESULT_STRING } });
103+
// @formatter:on
104+
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) {
105+
list = new ArrayList<Object[]>(list);
106+
list.add(new Object[] {HmacAlgorithms.HMAC_SHA_224, STANDARD_SHA224_RESULT_BYTES, STANDARD_SHA224_RESULT_STRING});
107+
}
108+
return list;
93109
}
94110

95111
private DigestUtilsTest digestUtilsTest;

0 commit comments

Comments
 (0)