1 // Copyright 2017 Google Inc. 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.daead; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.junit.Assert.assertThrows; 21 22 import com.google.crypto.tink.KeysetHandle; 23 import com.google.crypto.tink.config.TinkFips; 24 import java.security.GeneralSecurityException; 25 import org.junit.Assume; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.junit.runners.JUnit4; 29 30 /** Tests for DeterministicAeadConfig. */ 31 @RunWith(JUnit4.class) 32 public class DeterministicAeadConfigTest { 33 34 @Test notOnlyFips_shouldRegisterAllKeyTypes()35 public void notOnlyFips_shouldRegisterAllKeyTypes() throws Exception { 36 Assume.assumeFalse(TinkFips.useOnlyFips()); 37 38 DeterministicAeadConfig.register(); 39 40 assertThat(KeysetHandle.generateNew(PredefinedDeterministicAeadParameters.AES256_SIV)) 41 .isNotNull(); 42 } 43 44 @Test onlyFips_shouldNotRegisterNonFipsKeyTypes()45 public void onlyFips_shouldNotRegisterNonFipsKeyTypes() throws Exception { 46 Assume.assumeTrue(TinkFips.useOnlyFips()); 47 48 DeterministicAeadConfig.register(); 49 50 assertThrows( 51 GeneralSecurityException.class, 52 () -> KeysetHandle.generateNew(PredefinedDeterministicAeadParameters.AES256_SIV)); 53 } 54 } 55