• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.signature;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import com.google.crypto.tink.KeysetHandle;
22 import com.google.crypto.tink.PublicKeyVerify;
23 import com.google.crypto.tink.TinkProtoKeysetFormat;
24 import com.google.crypto.tink.internal.KeyManagerRegistry;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
29 
30 /** Unit tests for Ed25519PublicKeyManager. */
31 @RunWith(JUnit4.class)
32 public class Ed25519PublicKeyManagerTest {
33   @Before
register()34   public void register() throws Exception {
35     SignatureConfig.register();
36   }
37 
38   @Test
testKeyManagerRegistered()39   public void testKeyManagerRegistered() throws Exception {
40     assertThat(
41             KeyManagerRegistry.globalInstance()
42                 .getKeyManager(
43                     "type.googleapis.com/google.crypto.tink.Ed25519PublicKey",
44                     PublicKeyVerify.class))
45         .isNotNull();
46   }
47 
48   @Test
test_serializeAndParse_works()49   public void test_serializeAndParse_works() throws Exception {
50     KeysetHandle handle =
51         KeysetHandle.generateNew(Ed25519Parameters.create()).getPublicKeysetHandle();
52     byte[] serializedHandle = TinkProtoKeysetFormat.serializeKeysetWithoutSecret(handle);
53     KeysetHandle parsedHandle = TinkProtoKeysetFormat.parseKeysetWithoutSecret(serializedHandle);
54     assertThat(parsedHandle.equalsKeyset(handle)).isTrue();
55   }
56 }
57