Debian Codegraph @

streamingaead/aesctrhmac/aesctrhmac_test.go

raw symbols SCIP
1 // Copyright 2025 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 aesctrhmac_testscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac_test`/
16
17 import (
18 "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/"
19 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
20
21 "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`/"
22 "github.com/tink-crypto/tink-go/v2/internal/configscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/"
23 "github.com/tink-crypto/tink-go/v2/internal/internalapiscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/"
24 "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`/"
25 "github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/"
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 )
28
29 func TestRegisterPrimitiveConstructorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac_test`/TestRegisterPrimitiveConstructor().(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#) {
30 aesCTRHMACParams, err := aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.NewParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/NewParameters().(aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#{
31 KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#KeySizeInBytes.: 32,
32 HkdfHashTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#HkdfHashType.: aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.SHA256scip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/SHA256.,
33 DerivedKeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#DerivedKeySizeInBytes.: 32,
34 HmacHashTypescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#HmacHashType.: aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.SHA256scip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/SHA256.,
35 HmacTagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#HmacTagSizeInBytes.: 16,
36 SegmentSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/ParametersOpts#SegmentSizeInBytes.: 1024,
37 })
38 if err != nil {
39 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("aesctrhmac.NewParameters() err = %v, want nil", err)
40 }
41 keyMaterialCTRHMAC := 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("12345678901234567890123456789012"), 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#{})
42 aesCTRHMACKey, err := aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/NewKey().(aesCTRHMACParams, keyMaterialCTRHMAC)
43 if err != nil {
44 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("aesctrhmac.NewKey() err = %v, want nil", err)
45 }
46
47 b := configscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/.NewBuilderscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/NewBuilder().()
48 configWithoutAESCTRHMAC := b.Buildscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/Builder#Build().()
49
50 // Should fail because aesctrhmac.RegisterPrimitiveConstructor() was not called.
51 if _, err := configWithoutAESCTRHMAC.PrimitiveFromKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/Config#PrimitiveFromKey().(aesCTRHMACKey, internalapiscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/.Tokenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/Token#{}); err == nil {
52 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("configWithoutAESCTRHMAC.PrimitiveFromKey() err = nil, want error")
53 }
54
55 // Register aesctrhmac.RegisterPrimitiveConstructor() and check that it now works.
56 if err := aesctrhmacscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/.RegisterPrimitiveConstructorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/streamingaead/aesctrhmac`/RegisterPrimitiveConstructor().(b, internalapiscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/.Tokenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/Token#{}); err != nil {
57 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("aesctrhmac.RegisterPrimitiveConstructor() err = %v, want nil", err)
58 }
59 configWithAESCTRHMAC := b.Buildscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/Builder#Build().()
60 p, err := configWithAESCTRHMAC.PrimitiveFromKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/config`/Config#PrimitiveFromKey().(aesCTRHMACKey, internalapiscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/.Tokenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/internalapi`/Token#{})
61 if err != nil {
62 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().(" configWithAESCTRHMAC.PrimitiveFromKey() err = %v, want nil", err)
63 }
64
65 if _, ok := p.(tinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/.StreamingAEADscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/tink`/StreamingAEAD#); !ok {
66 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("p was of type %v, want tink.StreamingAEAD", reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeOf().(p))
67 }
68 }