|
21 | 21 | import static org.junit.Assert.assertThrows;
|
22 | 22 |
|
23 | 23 | import com.google.crypto.tink.KeyTemplate;
|
| 24 | +import com.google.crypto.tink.KeyTemplates; |
| 25 | +import com.google.crypto.tink.KeysetHandle; |
24 | 26 | import com.google.crypto.tink.Mac;
|
25 | 27 | import com.google.crypto.tink.internal.KeyTypeManager;
|
26 | 28 | import com.google.crypto.tink.proto.HashType;
|
|
40 | 42 | import javax.crypto.spec.SecretKeySpec;
|
41 | 43 | import org.junit.Before;
|
42 | 44 | import org.junit.Test;
|
| 45 | +import org.junit.experimental.theories.DataPoints; |
| 46 | +import org.junit.experimental.theories.FromDataPoints; |
| 47 | +import org.junit.experimental.theories.Theories; |
| 48 | +import org.junit.experimental.theories.Theory; |
43 | 49 | import org.junit.runner.RunWith;
|
44 |
| -import org.junit.runners.JUnit4; |
45 | 50 |
|
46 | 51 | /** Unit tests for {@link HmacKeyManager}. */
|
47 |
| -@RunWith(JUnit4.class) |
| 52 | +@RunWith(Theories.class) |
48 | 53 | public class HmacKeyManagerTest {
|
49 | 54 | private final HmacKeyManager manager = new HmacKeyManager();
|
50 | 55 | private final KeyTypeManager.KeyFactory<HmacKeyFormat, HmacKey> factory = manager.keyFactory();
|
@@ -400,21 +405,26 @@ public void testKeyTemplateAndManagerCompatibility() throws Exception {
|
400 | 405 | testKeyTemplateCompatible(manager, HmacKeyManager.hmacSha512HalfDigestTemplate());
|
401 | 406 | }
|
402 | 407 |
|
403 |
| - @Test |
404 |
| - public void testKeyFormats() throws Exception { |
405 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA256_128BITTAG").keyFormat); |
406 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA256_128BITTAG_RAW").keyFormat); |
407 |
| - |
408 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA256_256BITTAG").keyFormat); |
409 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA256_256BITTAG_RAW").keyFormat); |
410 |
| - |
411 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_128BITTAG").keyFormat); |
412 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_128BITTAG_RAW").keyFormat); |
413 |
| - |
414 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_256BITTAG").keyFormat); |
415 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_256BITTAG_RAW").keyFormat); |
416 |
| - |
417 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_512BITTAG").keyFormat); |
418 |
| - factory.validateKeyFormat(factory.keyFormats().get("HMAC_SHA512_512BITTAG_RAW").keyFormat); |
| 408 | + @DataPoints("templateNames") |
| 409 | + public static final String[] KEY_TEMPLATES = |
| 410 | + new String[] { |
| 411 | + "HMAC_SHA256_128BITTAG", |
| 412 | + "HMAC_SHA256_128BITTAG_RAW", |
| 413 | + "HMAC_SHA256_256BITTAG", |
| 414 | + "HMAC_SHA256_256BITTAG_RAW", |
| 415 | + "HMAC_SHA512_128BITTAG", |
| 416 | + "HMAC_SHA512_128BITTAG_RAW", |
| 417 | + "HMAC_SHA512_256BITTAG", |
| 418 | + "HMAC_SHA512_256BITTAG_RAW", |
| 419 | + "HMAC_SHA512_512BITTAG", |
| 420 | + "HMAC_SHA512_512BITTAG_RAW" |
| 421 | + }; |
| 422 | + |
| 423 | + @Theory |
| 424 | + public void testTemplates(@FromDataPoints("templateNames") String templateName) throws Exception { |
| 425 | + KeysetHandle h = KeysetHandle.generateNew(KeyTemplates.get(templateName)); |
| 426 | + assertThat(h.size()).isEqualTo(1); |
| 427 | + assertThat(h.getAt(0).getKey().getParameters()) |
| 428 | + .isEqualTo(KeyTemplates.get(templateName).toParameters()); |
419 | 429 | }
|
420 | 430 | }
|
0 commit comments