1// Copyright 2018 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 17package signature_test 18 19import ( 20 "testing" 21 22 "google.golang.org/protobuf/proto" 23 "github.com/google/tink/go/core/registry" 24 "github.com/google/tink/go/testutil" 25) 26 27func TestED25519VerifyGetPrimitiveBasic(t *testing.T) { 28 km, err := registry.GetKeyManager(testutil.ED25519VerifierTypeURL) 29 if err != nil { 30 t.Errorf("cannot obtain ED25519Verifier key manager: %s", err) 31 } 32 serializedKey, _ := proto.Marshal(testutil.NewED25519PublicKey()) 33 _, err = km.Primitive(serializedKey) 34 if err != nil { 35 t.Errorf("unexpect error in test case: %s ", err) 36 } 37} 38 39func TestED25519VerifyGetPrimitiveWithInvalidInput(t *testing.T) { 40 km, err := registry.GetKeyManager(testutil.ED25519VerifierTypeURL) 41 if err != nil { 42 t.Errorf("cannot obtain ED25519Verifier key manager: %s", err) 43 } 44 45 // invalid version 46 key := testutil.NewED25519PublicKey() 47 key.Version = testutil.ED25519VerifierKeyVersion + 1 48 serializedKey, _ := proto.Marshal(key) 49 if _, err := km.Primitive(serializedKey); err == nil { 50 t.Errorf("expect an error when version is invalid") 51 } 52 // nil input 53 if _, err := km.Primitive(nil); err == nil { 54 t.Errorf("expect an error when input is nil") 55 } 56 if _, err := km.Primitive([]byte{}); err == nil { 57 t.Errorf("expect an error when input is empty slice") 58 } 59} 60