1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink.mac; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.crypto.tink.Key; 22 import com.google.crypto.tink.KeysetHandle; 23 import org.junit.BeforeClass; 24 import org.junit.Test; 25 import org.junit.experimental.theories.DataPoints; 26 import org.junit.experimental.theories.FromDataPoints; 27 import org.junit.experimental.theories.Theories; 28 import org.junit.experimental.theories.Theory; 29 import org.junit.runner.RunWith; 30 31 @RunWith(Theories.class) 32 public final class PredefinedMacParametersTest { 33 @BeforeClass setUp()34 public static void setUp() throws Exception { 35 MacConfig.register(); 36 } 37 38 @DataPoints("AllParameters") 39 public static final MacParameters[] TEMPLATES = 40 new MacParameters[] { 41 PredefinedMacParameters.HMAC_SHA256_128BITTAG, 42 PredefinedMacParameters.HMAC_SHA256_256BITTAG, 43 PredefinedMacParameters.HMAC_SHA512_256BITTAG, 44 PredefinedMacParameters.HMAC_SHA512_512BITTAG, 45 PredefinedMacParameters.AES_CMAC 46 }; 47 48 @Theory testInstantiation(@romDataPoints"AllParameters") MacParameters parameters)49 public void testInstantiation(@FromDataPoints("AllParameters") MacParameters parameters) 50 throws Exception { 51 Key key = KeysetHandle.generateNew(parameters).getAt(0).getKey(); 52 assertThat(key.getParameters()).isEqualTo(parameters); 53 } 54 55 @Test testTypes()56 public void testTypes() { 57 assertThat(PredefinedMacParameters.HMAC_SHA256_128BITTAG).isNotNull(); 58 assertThat(PredefinedMacParameters.HMAC_SHA256_256BITTAG).isNotNull(); 59 assertThat(PredefinedMacParameters.HMAC_SHA512_256BITTAG).isNotNull(); 60 assertThat(PredefinedMacParameters.HMAC_SHA512_512BITTAG).isNotNull(); 61 assertThat(PredefinedMacParameters.AES_CMAC).isNotNull(); 62 } 63 } 64