| 1 | // Copyright 2019 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 registry_testscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/ |
| 16 | |
| 17 | import ( |
| 18 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 19 | |
| 20 | "google.golang.org/protobuf/protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/" |
| 21 | "github.com/tink-crypto/tink-go/v2/aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead`/" |
| 22 | "github.com/tink-crypto/tink-go/v2/core/registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/" |
| 23 | "github.com/tink-crypto/tink-go/v2/macscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/mac`/" |
| 24 | "github.com/tink-crypto/tink-go/v2/testing/fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/" |
| 25 | "github.com/tink-crypto/tink-go/v2/testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/" |
| 26 | "github.com/tink-crypto/tink-go/v2/tinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/" |
| 27 | gcmpbscip-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`/" |
| 28 | commonpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/ "github.com/tink-crypto/tink-go/v2/proto/common_go_protoscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/" |
| 29 | hmacpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/hmac_go_proto`/ "github.com/tink-crypto/tink-go/v2/proto/hmac_go_protoscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/hmac_go_proto`/" |
| 30 | 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`/" |
| 31 | ) |
| 32 | |
| 33 | func TestRegisterKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestRegisterKeyManager().(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#) { |
| 34 | // get HMACKeyManager |
| 35 | _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKeyManager().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.HMACTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/HMACTypeURL.) |
| 36 | if err != nil { |
| 37 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 38 | } |
| 39 | // get AESGCMKeyManager |
| 40 | _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKeyManager().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL.) |
| 41 | if err != nil { |
| 42 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 43 | } |
| 44 | // some random typeurl |
| 45 | if _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKeyManager().("some url"); err == nil { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when a type url doesn't exist in the registry") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestRegisterKeyManagerWithCollisionscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestRegisterKeyManagerWithCollision().(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#) { |
| 51 | // dummyKeyManager's typeURL is equal to that of AESGCM |
| 52 | var dummyKeyManager = new(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.DummyAEADKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/DummyAEADKeyManager#) |
| 53 | // This should fail because overwriting is disallowed. |
| 54 | err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKeyManager().(dummyKeyManager) |
| 55 | if err == nil { |
| 56 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s shouldn't be registered again", testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL.) |
| 57 | } |
| 58 | |
| 59 | km, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKeyManager().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL.) |
| 60 | if err != nil { |
| 61 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 62 | } |
| 63 | // This should fail because overwriting is disallowed, even with the same key manager. |
| 64 | err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKeyManagerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKeyManager().(km) |
| 65 | if err == nil { |
| 66 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s shouldn't be registered again", testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL.) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestNewKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestNewKeyData().(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#) { |
| 71 | // new Keydata from a Hmac KeyTemplate |
| 72 | keyData, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKeyData().(macscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/mac`/.HMACSHA256Tag128KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/mac`/HMACSHA256Tag128KeyTemplate().()) |
| 73 | if err != nil { |
| 74 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 75 | } |
| 76 | if keyData.TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl. != testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.HMACTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/HMACTypeURL. { |
| 77 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("invalid key data") |
| 78 | } |
| 79 | key := new(hmacpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/hmac_go_proto`/.HmacKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/hmac_go_proto`/HmacKey#) |
| 80 | if err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Unmarshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Unmarshal().(keyData.Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#Value., key); err != nil { |
| 81 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error when unmarshal HmacKey: %s", err) |
| 82 | } |
| 83 | // nil |
| 84 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKeyData().(nil); err == nil { |
| 85 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key template is nil") |
| 86 | } |
| 87 | // unregistered type url |
| 88 | template := &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#{TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "some url", Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: []byte{0}} |
| 89 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKeyData().(template); err == nil { |
| 90 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key template contains unregistered typeURL") |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | func TestNewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestNewKey().(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#) { |
| 95 | // aead template |
| 96 | aesGcmTemplate := aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead`/.AES128GCMKeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead`/AES128GCMKeyTemplate().() |
| 97 | key, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKey().(aesGcmTemplate) |
| 98 | if err != nil { |
| 99 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 100 | } |
| 101 | var aesGcmKey = key.(*gcmpbscip-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#) |
| 102 | aesGcmFormat := new(gcmpbscip-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#) |
| 103 | if err := protoscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/.Unmarshalscip-go gomod google.golang.org/protobuf v1.36.8 `google.golang.org/protobuf/proto`/Unmarshal().(aesGcmTemplate.Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value., aesGcmFormat); err != nil { |
| 104 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 105 | } |
| 106 | if aesGcmFormat.KeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKeyFormat#KeySize. != uint32(len(aesGcmKey.KeyValuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/aes_gcm_go_proto`/AesGcmKey#KeyValue.)) { |
| 107 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("key doesn't match template") |
| 108 | } |
| 109 | //nil |
| 110 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKey().(nil); err == nil { |
| 111 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key template is nil") |
| 112 | } |
| 113 | // unregistered type url |
| 114 | template := &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#{TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#TypeUrl.: "some url", Valuescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#Value.: []byte{0}} |
| 115 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/NewKey().(template); err == nil { |
| 116 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key template is not registered") |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func TestPrimitiveFromKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestPrimitiveFromKeyData().(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#) { |
| 121 | // hmac keydata |
| 122 | keyData := testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.NewHMACKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/NewHMACKeyData().(commonpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/.HashType_SHA256scip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/HashType_SHA256., 16) |
| 123 | p, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.PrimitiveFromKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/PrimitiveFromKeyData().(keyData) |
| 124 | if err != nil { |
| 125 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("unexpected error: %s", err) |
| 126 | } |
| 127 | if _, ok := p.(tinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/.MACscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/MAC#); !ok { |
| 128 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.PrimitiveFromKeyData() e, _ = %T, want tink.MAC", p) |
| 129 | } |
| 130 | // unregistered url |
| 131 | keyData.TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl. = "some url" |
| 132 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.PrimitiveFromKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/PrimitiveFromKeyData().(keyData); err == nil { |
| 133 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when typeURL has not been registered") |
| 134 | } |
| 135 | // unmatched url |
| 136 | keyData.TypeUrlscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyData#TypeUrl. = testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL. |
| 137 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.PrimitiveFromKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/PrimitiveFromKeyData().(keyData); err == nil { |
| 138 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when typeURL doesn't match key") |
| 139 | } |
| 140 | // nil |
| 141 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.PrimitiveFromKeyDatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/PrimitiveFromKeyData().(nil); err == nil { |
| 142 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key data is nil") |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func TestPrimitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestPrimitive().(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#) { |
| 147 | // hmac key |
| 148 | key := testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.NewHMACKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/NewHMACKey().(commonpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/.HashType_SHA256scip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/common_go_proto`/HashType_SHA256., 16) |
| 149 | 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) |
| 150 | if err != nil { |
| 151 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("proto.Marshal() err = %s, want nil", err) |
| 152 | } |
| 153 | p, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.HMACTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/HMACTypeURL., serializedKey) |
| 154 | if err != nil { |
| 155 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("registry.Primitive() err = %s, want nil", err) |
| 156 | } |
| 157 | if _, ok := p.(tinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/.MACscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/MAC#); !ok { |
| 158 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.Primitive() e, _ = %T, want tink.MAC", p) |
| 159 | } |
| 160 | // unregistered url |
| 161 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().("some url", serializedKey); err == nil { |
| 162 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when typeURL has not been registered") |
| 163 | } |
| 164 | // unmatched url |
| 165 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL., serializedKey); err == nil { |
| 166 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when typeURL doesn't match key") |
| 167 | } |
| 168 | // void key |
| 169 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL., nil); err == nil { |
| 170 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key is nil") |
| 171 | } |
| 172 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL., []byte{}); err == nil { |
| 173 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key is nil") |
| 174 | } |
| 175 | if _, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.Primitivescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/Primitive().(testutilscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/.AESGCMTypeURLscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testutil`/AESGCMTypeURL., []byte{0}); err == nil { |
| 176 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expect an error when key is nil") |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | func TestRegisterKmsClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestRegisterKmsClient().(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#) { |
| 181 | client1, err := fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/.NewClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/NewClient().("fake-kms://prefix1") |
| 182 | if err != nil { |
| 183 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("fakekms.NewClient('fake-kms://prefix1') failed: %v", err) |
| 184 | } |
| 185 | client2, err := fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/.NewClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/NewClient().("fake-kms://prefix2") |
| 186 | if err != nil { |
| 187 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("fakekms.NewClient('fake-kms://prefix2') failed: %v", err) |
| 188 | } |
| 189 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKMSClient().(client1) |
| 190 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKMSClient().(client2) |
| 191 | output1, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://prefix1-postfix") |
| 192 | if err != nil { |
| 193 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://prefix1-postfix') failed: %v", err) |
| 194 | } |
| 195 | if output1 != client1 { |
| 196 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://prefix1-postfix') did not return client1") |
| 197 | } |
| 198 | output2, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://prefix2-postfix") |
| 199 | if err != nil { |
| 200 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://prefix2-postfix') failed: %v", err) |
| 201 | } |
| 202 | if output2 != client2 { |
| 203 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://prefix2-postfix') did not return client2") |
| 204 | } |
| 205 | _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://unknown-prefix") |
| 206 | if err == nil { |
| 207 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://unknown-prefix') succeeded, want fail") |
| 208 | } |
| 209 | _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("bad-kms://unknown-prefix") |
| 210 | if err == nil { |
| 211 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('bad-kms://unknown-prefix') succeeded, want fail") |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | func TestRegisterTwoKmsClientsForSameUri_firstGetsReturnedscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestRegisterTwoKmsClientsForSameUri_firstGetsReturned().(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#) { |
| 216 | abcClient, err := fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/.NewClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/NewClient().("fake-kms://abc") |
| 217 | if err != nil { |
| 218 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("fakekms.NewClient(\"fake-kms://abc\") err = %q, want nil", err) |
| 219 | } |
| 220 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKMSClient().(abcClient) |
| 221 | |
| 222 | abc123Client, err := fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/.NewClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/NewClient().("fake-kms://abc123") |
| 223 | if err != nil { |
| 224 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("fakekms.NewClient(\"fake-kms://abc123\") err = %q, want nil", err) |
| 225 | } |
| 226 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKMSClient().(abc123Client) |
| 227 | |
| 228 | // Both clients support "fake-kms://abc123". But abcClient was registered first. |
| 229 | got, err := registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://abc123") |
| 230 | if err != nil { |
| 231 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("registry.GetKMSClient(\"fake-kms://abc123\") err = %q, want nil", err) |
| 232 | } |
| 233 | if got != abcClient { |
| 234 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient(\"fake-kms://abc123\") = %q, want abcClient", got) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | func TestClearKMSClientsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry_test`/TestClearKMSClients().(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#) { |
| 239 | client, err := fakekmsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/.NewClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/testing/fakekms`/NewClient().("fake-kms://xyz") |
| 240 | if err != nil { |
| 241 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("fakekms.NewClient('fake-kms://xyz') failed: %v", err) |
| 242 | } |
| 243 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.RegisterKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/RegisterKMSClient().(client) |
| 244 | |
| 245 | _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://xyz-123") |
| 246 | if err != nil { |
| 247 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://xyz-123') failed: %v", err) |
| 248 | } |
| 249 | |
| 250 | registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.ClearKMSClientsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/ClearKMSClients().() |
| 251 | |
| 252 | _, err = registryscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/.GetKMSClientscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/core/registry`/GetKMSClient().("fake-kms://xyz-123") |
| 253 | if err == nil { |
| 254 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("registry.GetKMSClient('fake-kms://xyz-123') succeeded, want fail") |
| 255 | } |
| 256 | } |