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