| 1 | // Copyright 2026 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 aead_testscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead_test`/ |
| 16 | |
| 17 | import ( |
| 18 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 20 | |
| 21 | "golang.org/x/crypto/chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/" |
| 22 | "github.com/tink-crypto/tink-go/v2/internal/aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/" |
| 23 | ) |
| 24 | |
| 25 | func TestCheckChaCha20Poly1305PlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead_test`/TestCheckChaCha20Poly1305PlaintextSize().(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#) { |
| 26 | tests := []struct { |
| 27 | name string |
| 28 | plaintextSize int |
| 29 | wantErr bool |
| 30 | }{ |
| 31 | { |
| 32 | name: "plaintext too long", |
| 33 | plaintextSize: mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxIntscip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.NonceSizescip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/NonceSize. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.Overheadscip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/Overhead. + 1, |
| 34 | wantErr: true, |
| 35 | }, |
| 36 | { |
| 37 | name: "plaintext ok", |
| 38 | plaintextSize: mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxIntscip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.NonceSizescip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/NonceSize. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.Overheadscip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/Overhead., |
| 39 | wantErr: false, |
| 40 | }, |
| 41 | } |
| 42 | for _, tc := range tests { |
| 43 | 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#) { |
| 44 | err := aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/.CheckChaCha20Poly1305PlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/CheckChaCha20Poly1305PlaintextSize().(tc.plaintextSize) |
| 45 | if got, want := (err != nil), tc.wantErr; got != want { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("aead.CheckChaCha20Poly1305PlaintextSize(%d) err = %v, want %v", tc.plaintextSize, err, tc.wantErr) |
| 47 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("aead.CheckChaCha20Poly1305PlaintextSize(plaintext) (err == nil) = %v, want %v", got, want) |
| 48 | } |
| 49 | }) |
| 50 | } |
| 51 | } |