1 // Copyright 2020 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 package com.google.crypto.tink.jwt; 17 18 import static com.google.common.truth.Truth.assertThat; 19 import static org.junit.Assert.assertTrue; 20 21 import com.google.crypto.tink.KeyTemplate; 22 import com.google.crypto.tink.KeyTemplates; 23 import com.google.crypto.tink.KeysetHandle; 24 import com.google.crypto.tink.TinkProtoKeysetFormat; 25 import com.google.crypto.tink.internal.KeyManagerRegistry; 26 import org.junit.BeforeClass; 27 import org.junit.Test; 28 import org.junit.experimental.theories.Theories; 29 import org.junit.runner.RunWith; 30 31 /** Unit tests for RsaSsaPssVerifyKeyManager. */ 32 @RunWith(Theories.class) 33 public final class JwtRsaSsaPssVerifyKeyManagerTest { 34 @BeforeClass setUp()35 public static void setUp() throws Exception { 36 JwtSignatureConfig.register(); 37 } 38 39 @Test testKeyManagersRegistered()40 public void testKeyManagersRegistered() throws Exception { 41 assertThat( 42 KeyManagerRegistry.globalInstance() 43 .getUntypedKeyManager( 44 "type.googleapis.com/google.crypto.tink.JwtRsaSsaPssPublicKey")) 45 .isNotNull(); 46 } 47 48 @Test serializeAndDeserializeKeysets()49 public void serializeAndDeserializeKeysets() throws Exception { 50 KeyTemplate template = KeyTemplates.get("JWT_PS256_2048_F4"); 51 KeysetHandle handle = KeysetHandle.generateNew(template).getPublicKeysetHandle(); 52 53 byte[] serializedKeyset = TinkProtoKeysetFormat.serializeKeysetWithoutSecret(handle); 54 KeysetHandle parsed = TinkProtoKeysetFormat.parseKeysetWithoutSecret(serializedKeyset); 55 assertTrue(parsed.equalsKeyset(handle)); 56 } 57 } 58