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 17package aead_test 18 19import ( 20 "testing" 21 22 "google.golang.org/protobuf/proto" 23 "github.com/google/tink/go/keyset" 24 "github.com/google/tink/go/mac" 25 "github.com/google/tink/go/testing/fakekms" 26 "github.com/google/tink/go/testutil" 27 kmsenvpb "github.com/google/tink/go/proto/kms_envelope_go_proto" 28 tinkpb "github.com/google/tink/go/proto/tink_go_proto" 29) 30 31func TestNewKMSEnvelopeAEADKeyWithInvalidDEK(t *testing.T) { 32 keyURI, err := fakekms.NewKeyURI() 33 if err != nil { 34 t.Fatalf("fakekms.NewKeyURI() err = %v", err) 35 } 36 37 // Create a KmsEnvelopeAeadKeyFormat with a DekTemplate that is not supported. 38 format := &kmsenvpb.KmsEnvelopeAeadKeyFormat{ 39 KekUri: keyURI, 40 DekTemplate: mac.HMACSHA256Tag128KeyTemplate(), 41 } 42 serializedFormat, err := proto.Marshal(format) 43 if err != nil { 44 t.Fatalf("failed to marshal key format: %s", err) 45 } 46 keyTemplate := &tinkpb.KeyTemplate{ 47 Value: serializedFormat, 48 TypeUrl: testutil.KMSEnvelopeAEADTypeURL, 49 OutputPrefixType: tinkpb.OutputPrefixType_RAW, 50 } 51 52 _, err = keyset.NewHandle(keyTemplate) 53 if err == nil { 54 t.Errorf("keyset.NewHandle(keyTemplate) err = nil, want error") 55 } 56} 57