Debian Codegraph @

aead/aesgcm/protoserialization_test.go

raw symbols SCIP
1 // Copyright 2024 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 package aesgcmscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
19 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
20
21 "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.7.0 `github.com/google/go-cmp/cmp`/"
22 "google.golang.org/protobuf/protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/"
23 "google.golang.org/protobuf/testing/protocmpscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/testing/protocmp`/"
24 "github.com/tink-crypto/tink-go/v2/insecuresecretdataaccessscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/insecuresecretdataaccess`/"
25 "github.com/tink-crypto/tink-go/v2/internal/protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/"
26 "github.com/tink-crypto/tink-go/v2/keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/"
27 "github.com/tink-crypto/tink-go/v2/secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/"
28 aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/ "github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_protoscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/"
29 tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/ "github.com/tink-crypto/tink-go/v2/proto/tink_go_protoscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/"
30 )
31
32 func TestParseKeyFailsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestParseKeyFails().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
33 key := aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#{
34 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#Version.: 0,
35 KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.: []byte("1234567890123456"),
36 }
37 serializedKey, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(&key)
38 if err != nil {
39 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(key) err = %v, want nil", err)
40 }
41 keyWithInvalidSize := aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#{
42 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#Version.: 0,
43 KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.: []byte("0123"),
44 }
45 serializedKeyWithInvalidSize, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(&keyWithInvalidSize)
46 if err != nil {
47 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(keyWithInvalidSize) err = %v, want nil", err)
48 }
49 keyWithInvalidVersion := aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#{
50 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#Version.: 1,
51 KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.: []byte("1234567890123456"),
52 }
53 serializedKeyWithInvalidVersion, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(&keyWithInvalidVersion)
54 if err != nil {
55 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(keyWithInvalidVersion) err = %v, want nil", err)
56 }
57 for _, tc := range []struct {
58 name string
59 keyData *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#
60 outputPrefixType tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType#
61 keyID uint32
62 }{
63 {
64 name: "key data is nil",
65 keyData: nil,
66 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
67 keyID: 12345,
68 },
69 {
70 name: "wrong type URL",
71 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
72 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "invalid_type_url",
73 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
74 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
75 },
76 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
77 keyID: 12345,
78 },
79 {
80 name: "invalid AES GCM key size",
81 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
82 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
83 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKeyWithInvalidSize,
84 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
85 },
86 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
87 keyID: 12345,
88 },
89 {
90 name: "invalid AES GCM key proto serialization",
91 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
92 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
93 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: []byte("invalid proto"),
94 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
95 },
96 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
97 keyID: 12345,
98 },
99 {
100 name: "invalid AES GCM key version",
101 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
102 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
103 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKeyWithInvalidVersion,
104 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
105 },
106 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
107 keyID: 12345,
108 },
109 {
110 name: "invalid key material type",
111 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
112 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
113 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
114 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_ASYMMETRIC_PRIVATEscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_ASYMMETRIC_PRIVATE.,
115 },
116 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
117 keyID: 12345,
118 },
119 {
120 name: "invalid output prefix type",
121 keyData: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
122 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
123 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
124 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
125 },
126 outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_UNKNOWN_PREFIXscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_UNKNOWN_PREFIX.,
127 keyID: 12345,
128 },
129 } {
130 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
131 p := &keyParserscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keyParser#{}
132 keySerialization, err := protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.NewKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/NewKeySerialization().(tc.keyData, tc.outputPrefixType, tc.keyID)
133 if err != nil {
134 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("protoserialization.NewKeySerialization(%v, %v, %v) err = %v, want nil", tc.keyData, tc.outputPrefixType, tc.keyID, err)
135 }
136 if _, err := p.ParseKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keyParser#ParseKey().(keySerialization); err == nil {
137 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("p.ParseKey(%v) err = nil, want non-nil", keySerialization)
138 }
139 })
140 }
141 }
142
143 func mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, keyData *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#, outputPrefixType tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType#, idRequirement uint32) *protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.KeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/KeySerialization# {
144 t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().()
145 ks, err := protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.NewKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/NewKeySerialization().(keyData, outputPrefixType, idRequirement)
146 if err != nil {
147 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("protoserialization.NewKeySerialization(%v, %v, %v) err = %v, want nil", keyData, outputPrefixType, idRequirement, err)
148 }
149 return ks
150 }
151
152 func TestParseKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestParseKey().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
153 protoKey := aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#{
154 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#Version.: 0,
155 KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.: []byte("1234567890123456"),
156 }
157 serializedKey, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(&protoKey)
158 if err != nil {
159 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(protoKey) err = %v, want nil", err)
160 }
161
162 for _, tc := range []struct {
163 name string
164 keySerialization *protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.KeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/KeySerialization#
165 wantVariant Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#
166 }{
167 {
168 name: "key with TINK output prefix type",
169 keySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
170 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
171 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
172 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
173 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK., 12345),
174 wantVariant: VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink.,
175 },
176 {
177 name: "key with CRUNCHY output prefix type",
178 keySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
179 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
180 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
181 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
182 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_CRUNCHYscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_CRUNCHY., 12345),
183 wantVariant: VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy.,
184 },
185 {
186 name: "key with RAW output prefix type",
187 keySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
188 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
189 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedKey,
190 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
191 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_RAWscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_RAW., 0),
192 wantVariant: VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix.,
193 },
194 } {
195 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
196 opts := ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#{
197 KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes.: len(protoKey.GetKeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#GetKeyValue().()),
198 IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes.: 12,
199 TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes.: 16,
200 Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant.: tc.wantVariant,
201 }
202 wantParams, err := NewParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewParameters().(opts)
203 if err != nil {
204 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("NewParameters(%v) err = %v, want nil", opts, err)
205 }
206 keyMaterial := secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.NewBytesFromDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/NewBytesFromData().(protoKey.GetKeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#GetKeyValue().(), insecuresecretdataaccessscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/insecuresecretdataaccess`/.Tokenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/insecuresecretdataaccess`/Token#{})
207 keyID := uint32(0)
208 if tc.wantVariant != VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix. {
209 keyID = 12345
210 }
211 wantKey, err := NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewKey().(keyMaterial, keyID, wantParams)
212 if err != nil {
213 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("NewKey(keyMaterial, %v, wantParams) err = %v, want nil", keyID, err)
214 }
215 p := &keyParserscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keyParser#{}
216 gotKey, err := p.ParseKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keyParser#ParseKey().(tc.keySerialization)
217 if err != nil {
218 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.ParseKey(%v) err = %v, want nil", tc.keySerialization, err)
219 }
220 if !gotKey.Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key#Equal.(wantKey) {
221 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("key.Equal(wantKey) = false, want true")
222 }
223 })
224 }
225 }
226
227 type testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams# struct {
228 hasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#hasIDRequirement. bool
229 }
230
231 func (p *testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#) HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#HasIDRequirement().() bool { return p.hasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#hasIDRequirement. }
232
233 func (p *testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#) Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#Equal().(params keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#) bool {
234 _, ok := params.(*testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#)
235 return ok && p.hasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#hasIDRequirement. == params.HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#HasIDRequirement.()
236 }
237
238 type testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey# struct {
239 keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#keyBytes. []byte
240 idscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#id. uint32
241 paramsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#params. testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#
242 }
243
244 func (k *testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#) Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#Parameters().() keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters# { return &k.paramsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#params. }
245
246 func (k *testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#) Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#Equal().(other keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key#) bool {
247 fallbackProtoKey, ok := other.(*testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#)
248 if !ok {
249 return false
250 }
251 return k.paramsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#params..Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#Equal().(fallbackProtoKey.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#Parameters().())
252 }
253
254 func (k *testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#) IDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#IDRequirement().() (uint32, bool) { return k.idscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#id., k.paramsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#params..HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#HasIDRequirement().() }
255
256 func TestSerializeKeyFailsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestSerializeKeyFails().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
257 for _, tc := range []struct {
258 name string
259 key keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key#
260 }{
261 {
262 name: "key is nil",
263 key: nil,
264 },
265 {
266 name: "key is not an AES GCM key",
267 key: &testKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testKey#{},
268 },
269 } {
270 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
271 aesGCMSerializer := &keySerializerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keySerializer#{}
272 _, err := aesGCMSerializer.SerializeKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keySerializer#SerializeKey().(tc.key)
273 if err == nil {
274 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.SerializeKey(&testKey{}) err = nil, want non-nil")
275 }
276 })
277 }
278 }
279
280 func TestSerializeKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestSerializeKey().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
281 protoKey := aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#{
282 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#Version.: 0,
283 KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.: []byte("1234567890123456"),
284 }
285 serializedProtoKey, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(&protoKey)
286 if err != nil {
287 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(&protoKey) err = %v, want nil", err)
288 }
289 for _, tc := range []struct {
290 name string
291 variant Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#
292 wantKeySerialization *protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.KeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/KeySerialization#
293 }{
294 {
295 name: "key with TINK output prefix type",
296 variant: VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink.,
297 wantKeySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
298 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
299 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedProtoKey,
300 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
301 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK., 12345),
302 },
303 {
304 name: "key with CRUNCHY output prefix type",
305 variant: VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy.,
306 wantKeySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
307 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
308 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedProtoKey,
309 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
310 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_CRUNCHYscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_CRUNCHY., 12345),
311 },
312 {
313 // No key ID is set for keys with no prefix.
314 name: "key with RAW output prefix type",
315 variant: VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix.,
316 wantKeySerialization: mustCreateKeySerializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeySerialization().(t, &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#{
317 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
318 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value.: serializedProtoKey,
319 KeyMaterialTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#KeyMaterialType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyData_SYMMETRICscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData_SYMMETRIC.,
320 }, tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_RAWscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_RAW., 0),
321 },
322 } {
323 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
324 opts := ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#{
325 KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes.: 16,
326 IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes.: 12,
327 TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes.: 16,
328 Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant.: tc.variant,
329 }
330 params, err := NewParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewParameters().(opts)
331 if err != nil {
332 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("NewParameters(%v) err = %v, want nil", opts, err)
333 }
334 secretKey := secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.NewBytesFromDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/NewBytesFromData().([]byte("1234567890123456"), insecuresecretdataaccessscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/insecuresecretdataaccess`/.Tokenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/insecuresecretdataaccess`/Token#{})
335 keyID := uint32(0)
336 if tc.variant != VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix. {
337 keyID = 12345
338 }
339 key, err := NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewKey().(secretKey, keyID, params)
340 if err != nil {
341 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("NewKey(secretKey, %v, params) err = %v, want nil", keyID, err)
342 }
343 aesGCMSerializer := &keySerializerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keySerializer#{}
344 got, err := aesGCMSerializer.SerializeKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/keySerializer#SerializeKey().(key)
345 if err != nil {
346 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.SerializeKey(&testKey{}) err = %v, want nil", err)
347 }
348 if !got.Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/KeySerialization#Equal().(tc.wantKeySerialization) {
349 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("got.Equal(tc.wantKeySerialization) = false, want true")
350 }
351 })
352 }
353 }
354
355 func TestSerializeParametersFailsWithWrongParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestSerializeParametersFailsWithWrongParameters().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
356 for _, tc := range []struct {
357 name string
358 parameters keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#
359 }{
360 {
361 name: "struct literal",
362 parameters: &Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#{},
363 },
364 {
365 name: "nil",
366 parameters: nil,
367 },
368 {
369 name: "wrong type",
370 parameters: &testParamsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/testParams#{},
371 },
372 } {
373 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
374 serializer := &parametersSerializerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializer#{}
375 if _, err := serializer.Serializescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializer#Serialize().(tc.parameters); err == nil {
376 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("serializer.Serialize(%v) err = nil, want error", tc.parameters)
377 }
378 })
379 }
380 }
381
382 func mustCreateKeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeyTemplate().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, outputPrefixType tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType#, keySizeInBytes uint32) *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate# {
383 t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().()
384 format := &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{
385 KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize.: keySizeInBytes,
386 }
387 serializedFormat, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(format)
388 if err != nil {
389 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(%v) err = %v, want nil", format, err)
390 }
391 return &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
392 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
393 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: outputPrefixType,
394 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: serializedFormat,
395 }
396 }
397
398 type parametersSerializationTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase# struct {
399 namescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#name. string
400 parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters. *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#
401 keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate. *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#
402 }
403
404 func mustCreateParametersTestParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateParametersTestParameters().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) []parametersSerializationTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase# {
405 tcs := []parametersSerializationTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#{}
406 for _, keySize := range []int{16, 24, 32} {
407 for _, variantAndPrefix := range []struct {
408 variant Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#
409 outputPrefixType tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType#
410 }{
411 {variant: VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink., outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.},
412 {variant: VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy., outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_CRUNCHYscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_CRUNCHY.},
413 {variant: VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix., outputPrefixType: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_RAWscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_RAW.},
414 } {
415 tcs = append(tcs, parametersSerializationTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#{
416 namescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#name.: fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("AES%d-GCM-%s", keySize*8, variantAndPrefix.variant),
417 parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters.: &Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#{
418 keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes.: keySize,
419 ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes.: 12,
420 tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes.: 16,
421 variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant.: variantAndPrefix.variant,
422 },
423 keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate.: mustCreateKeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateKeyTemplate().(t, variantAndPrefix.outputPrefixType, uint32(keySize)),
424 })
425 }
426 }
427 return tcs
428 }
429
430 func TestSerializeParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestSerializeParameters().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
431 for _, tc := range mustCreateParametersTestParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateParametersTestParameters().(t) {
432 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.namescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#name., func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
433 got, err := protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.SerializeParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/SerializeParameters().(tc.parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters.)
434 if err != nil {
435 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("protoserialization.SerializeParameters(%v) err = %v, want nil", tc.parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters., err)
436 }
437 if diff := cmpscip-go gomod github.com/google/go-cmp v0.7.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.7.0 `github.com/google/go-cmp/cmp`/Diff().(tc.keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate., got, protocmpscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/testing/protocmp`/.Transformscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/testing/protocmp`/Transform().()); diff != "" {
438 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.SerializeParameters(%v) returned unexpected diff (-want +got):\n%s", tc.parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters., diff)
439 }
440 })
441 }
442 }
443
444 func TestParseParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestParseParameters().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
445 for _, tc := range mustCreateParametersTestParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustCreateParametersTestParameters().(t) {
446 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.namescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#name., func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
447 got, err := protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.ParseParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/ParseParameters().(tc.keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate.)
448 if err != nil {
449 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("protoserialization.ParseParameters(%v) err = %v, want nil", tc.keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate., err)
450 }
451 if diff := cmpscip-go gomod github.com/google/go-cmp v0.7.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.7.0 `github.com/google/go-cmp/cmp`/Diff().(tc.parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#parameters., got); diff != "" {
452 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.ParseParameters(%v) returned unexpected diff (-want +got):\n%s", tc.keyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/parametersSerializationTestCase#keyTemplate., diff)
453 }
454 })
455 }
456 }
457
458 func mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, message protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Messagescip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Message#) []byte {
459 t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().()
460 serializedMessage, err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Marshal().(message)
461 if err != nil {
462 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal(%v) err = %v, want nil", message, err)
463 }
464 return serializedMessage
465 }
466
467 func TestParseParametersFailsWithWrongKeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/TestParseParametersFailsWithWrongKeyTemplate().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
468 for _, tc := range []struct {
469 name string
470 keyTemplate *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#
471 }{
472 {
473 name: "empty",
474 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{},
475 },
476 {
477 name: "empty format",
478 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
479 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
480 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t, &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{}),
481 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
482 },
483 },
484 {
485 name: "invalid format type",
486 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
487 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
488 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: []byte("invalid format"),
489 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
490 },
491 },
492 {
493 name: "wrong type URL",
494 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
495 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey",
496 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t, &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{
497 KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize.: 16,
498 }),
499 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
500 },
501 },
502 {
503 name: "invalid version",
504 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
505 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
506 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t, &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{
507 KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize.: 16,
508 Versionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#Version.: 1,
509 }),
510 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
511 },
512 },
513 {
514 name: "invalid key size",
515 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
516 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
517 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t, &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{
518 KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize.: 10,
519 }),
520 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_TINKscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_TINK.,
521 },
522 },
523 {
524 name: "unknown output prefix type",
525 keyTemplate: &tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#{
526 TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "type.googleapis.com/google.crypto.tink.AesGcmKey",
527 Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: mustMarshalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/mustMarshal().(t, &aesgcmpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/.AesGcmKeyFormatscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#{
528 KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize.: 16,
529 }),
530 OutputPrefixTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#OutputPrefixType.: tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.OutputPrefixType_UNKNOWN_PREFIXscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/OutputPrefixType_UNKNOWN_PREFIX.,
531 },
532 },
533 } {
534 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
535 if _, err := protoserializationscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/.ParseParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/protoserialization`/ParseParameters().(tc.keyTemplate); err == nil {
536 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("protoserialization.ParseParameters(%v) err = nil, want error", tc.keyTemplate)
537 }
538 })
539 }
540 }