1 // Copyright 2021 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; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.crypto.tink.internal.MutableParametersRegistry; 22 import java.security.GeneralSecurityException; 23 import java.util.Collections; 24 import java.util.HashMap; 25 import java.util.Map; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.junit.runners.JUnit4; 29 30 /** Tests for KeyTemplates * */ 31 @RunWith(JUnit4.class) 32 public final class KeyTemplatesTest { namedParameters()33 private static Map<String, Parameters> namedParameters() throws GeneralSecurityException { 34 Map<String, Parameters> formats = new HashMap<>(); 35 formats.put( 36 "TINK", 37 new Parameters() { 38 @Override 39 public boolean hasIdRequirement() { 40 return true; 41 } 42 }); 43 formats.put( 44 "RAW", 45 new Parameters() { 46 @Override 47 public boolean hasIdRequirement() { 48 return false; 49 } 50 }); 51 return Collections.unmodifiableMap(formats); 52 } 53 54 @Test get()55 public void get() throws Exception { 56 MutableParametersRegistry.globalInstance().putAll(namedParameters()); 57 58 KeyTemplate template1 = KeyTemplates.get("TINK"); 59 assertThat(template1.toParameters().hasIdRequirement()).isEqualTo(true); 60 61 KeyTemplate template2 = KeyTemplates.get("RAW"); 62 assertThat(template2.toParameters().hasIdRequirement()).isEqualTo(false); 63 } 64 } 65