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.hybrid; 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 PredefinedHybridParametersTest { 33 @BeforeClass setUp()34 public static void setUp() throws Exception { 35 HybridConfig.register(); 36 } 37 38 @DataPoints("AllParameters") 39 public static final HybridParameters[] TEMPLATES = 40 new HybridParameters[] { 41 PredefinedHybridParameters.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM, 42 PredefinedHybridParameters.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM_COMPRESSED_WITHOUT_PREFIX, 43 PredefinedHybridParameters.ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256, 44 }; 45 46 @Theory testInstantiation(@romDataPoints"AllParameters") HybridParameters parameters)47 public void testInstantiation(@FromDataPoints("AllParameters") HybridParameters parameters) 48 throws Exception { 49 Key key = KeysetHandle.generateNew(parameters).getAt(0).getKey(); 50 assertThat(key.getParameters()).isEqualTo(parameters); 51 } 52 53 @Test testTypes()54 public void testTypes() throws Exception { 55 assertThat(PredefinedHybridParameters.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM).isNotNull(); 56 assertThat( 57 PredefinedHybridParameters 58 .ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM_COMPRESSED_WITHOUT_PREFIX) 59 .isNotNull(); 60 assertThat(PredefinedHybridParameters.ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256) 61 .isNotNull(); 62 } 63 } 64