diff --git a/.golangci.yml b/.golangci.yml index e93e1b5..d631a67 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -116,8 +116,6 @@ linters-settings: # See https://go-critic.github.io/overview#checks-overview # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # By default list of stable checks is used. - enabled-checks: - - rangeValCopy # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty disabled-checks: @@ -143,9 +141,6 @@ linters-settings: hugeParam: # size in bytes that makes the warning trigger (default 80) sizeThreshold: 1700 # TODO our context is 1648 bytes, we should consider increase this - nestingReduce: - # min number of statements inside a branch to trigger a warning (default 5) - bodyWidth: 5 rangeExprCopy: # size in bytes that makes the warning trigger (default 512) sizeThreshold: 512 @@ -156,18 +151,6 @@ linters-settings: sizeThreshold: 1300 # TODO our transaction.Data is 1208 bytes, we should consider increase this # whether to check test functions (default true) skipTestFuncs: true - ruleguard: - # path to a gorules file for the ruleguard checker - rules: '' - truncateCmp: - # whether to skip int/uint/uintptr types (default true) - skipArchDependent: true - underef: - # whether to skip (*x).method() calls where x is a pointer receiver (default true) - skipRecvDeref: true - unnamedResult: - # whether to check exported functions - checkExported: true goimports: # put imports beginning with prefix after 3rd-party packages; @@ -202,7 +185,7 @@ linters-settings: gosimple: # Select the Go version to target. The default is '1.13'. - go: "1.23" + go: "1.22.1" # https://staticcheck.io/docs/options#checks checks: [ "all" ] @@ -230,7 +213,7 @@ linters-settings: staticcheck: # Select the Go version to target. The default is '1.13'. - go: "1.23" + go: "1.22.1" # https://staticcheck.io/docs/options#checks checks: [ "all" ] @@ -273,7 +256,7 @@ linters-settings: unused: # Select the Go version to target. The default is '1.13'. - go: "1.23" + go: "1.22.1" linters: @@ -293,9 +276,11 @@ linters: - gosimple - govet - staticcheck - - ifshort - lll - misspell - prealloc - unparam - unused + - gomnd + - forcetypeassert + - golint \ No newline at end of file diff --git a/aged/age_bind.go b/aged/age_bind.go index 9cefe64..63e25d8 100644 --- a/aged/age_bind.go +++ b/aged/age_bind.go @@ -68,7 +68,6 @@ type Parameters struct { } func (k Keychain) Encrypt(p Parameters) ([]byte, error) { - in, err := compressor(p) if err != nil { return nil, err @@ -175,7 +174,6 @@ func compressor(p Parameters) (*bytes.Reader, error) { } in = bytes.NewReader(writer.Bytes()) - } else { in = bytes.NewReader(p.Data) } diff --git a/aged/obf.go b/aged/obf.go index f85fe70..d865492 100644 --- a/aged/obf.go +++ b/aged/obf.go @@ -11,7 +11,7 @@ type Obfuscation interface { Deobfuscate([]byte) ([]byte, error) } -// AgeV1Obf is a obfuscation for age encryption header +// AgeV1Obf is a obfuscation for age encryption header. type AgeV1Obf struct{} var ( @@ -21,11 +21,9 @@ var ( endFlag = []byte{0, 255, 1, 254} ) -//nolint:gochecknoglobals const lengthOfKey = 47 func (a *AgeV1Obf) Obfuscate(payload []byte) ([]byte, error) { - headerIndex := bytes.Index(payload, endOfHeader) if headerIndex == -1 { return nil, errors.New("missing end flag") @@ -41,7 +39,7 @@ func (a *AgeV1Obf) Obfuscate(payload []byte) ([]byte, error) { pad[i] = e ^ counter counter-- } - // nolint:gocritic + //nolint:gocritic obfHeader := append(pad, endFlag...) return bytes.ReplaceAll(payload, header, obfHeader), nil } diff --git a/aged/stream.go b/aged/stream.go index 763f45d..243be46 100644 --- a/aged/stream.go +++ b/aged/stream.go @@ -14,8 +14,7 @@ import ( "io" "golang.org/x/crypto/chacha20poly1305" - - // nolint:staticcheck + //nolint:staticcheck "golang.org/x/crypto/poly1305" ) @@ -38,6 +37,7 @@ const ( ) func NewReader(key []byte, src io.Reader) (*Reader, error) { + //nolint:gomnd if len(key) != 32 { return nil, errors.New("key length must be 32 byte long") } @@ -136,6 +136,7 @@ func (r *Reader) readChunk() (last bool, err error) { } func incNonce(nonce *[chacha20poly1305.NonceSizeX]byte) { + //nolint:gomnd for i := len(nonce) - 2; i >= 0; i-- { nonce[i]++ if nonce[i] != 0 { @@ -165,6 +166,7 @@ type Writer struct { } func NewWriter(key []byte, dst io.Writer) (*Writer, error) { + //nolint:gomnd if len(key) != 32 { return nil, errors.New("key length must be 32 byte long") } @@ -181,7 +183,7 @@ func NewWriter(key []byte, dst io.Writer) (*Writer, error) { } func (w *Writer) Write(p []byte) (n int, err error) { - // nolint:godox + //nolint:godox // TODO: consider refactoring with a bytes.Buffer. if w.err != nil { return 0, w.err diff --git a/asymmetric/attestation.go b/asymmetric/attestation.go index dd53b54..38e88cb 100644 --- a/asymmetric/attestation.go +++ b/asymmetric/attestation.go @@ -22,7 +22,6 @@ type Minimalistic struct { } func (m *Minimalistic) Sign(payload []byte) (string, error) { - if m.Suite == nil { return "", errors.New("missing signing suite declaration") } diff --git a/asymmetric/attestation_test.go b/asymmetric/attestation_test.go index 995f2b6..a025da3 100644 --- a/asymmetric/attestation_test.go +++ b/asymmetric/attestation_test.go @@ -10,7 +10,6 @@ import ( ) func TestMinimalisticAttestation(t *testing.T) { - ecdsa := asymmetric.Ed25519{} err := ecdsa.Generate() r.NoError(t, err) @@ -108,7 +107,6 @@ func TestMinimalisticAttestation(t *testing.T) { } func TestFaultMinimalisticAttestation(t *testing.T) { - ecdsa := asymmetric.Ed25519{} err := ecdsa.Generate() r.NoError(t, err) diff --git a/asymmetric/ecdh.go b/asymmetric/ecdh.go index cc50d9a..5e0a9f7 100644 --- a/asymmetric/ecdh.go +++ b/asymmetric/ecdh.go @@ -5,6 +5,10 @@ import ( "golang.org/x/crypto/curve25519" ) +const ( + Ed25519PrivateKeySize = 32 +) + type DH interface { GenerateKeypair() error GenerateSharedSecret([]byte) ([]byte, error) @@ -16,7 +20,7 @@ type Curve25519 struct { } func (c *Curve25519) GenerateKeypair() error { - secretKey, err := generic.CSPRNG(32) + secretKey, err := generic.CSPRNG(Ed25519PrivateKeySize) if err != nil { return err } diff --git a/asymmetric/ecdsa.go b/asymmetric/ecdsa.go index 7fbf2f3..9673374 100644 --- a/asymmetric/ecdsa.go +++ b/asymmetric/ecdsa.go @@ -66,16 +66,15 @@ func (e *Ed25519) Sign(msg []byte) string { } func (e *Ed25519) Verify(msg []byte, sig string) (bool, error) { - if e.Encoder == nil { return ed25519.Verify(e.PublicKey, msg, []byte(sig)), nil - } else { - sig_raw, err := e.Encoder.Decode(sig) - if err != nil { - return false, err - } - return ed25519.Verify(e.PublicKey, msg, sig_raw), nil } + sigRaw, err := e.Encoder.Decode(sig) + if err != nil { + return false, err + } + return ed25519.Verify(e.PublicKey, msg, sigRaw), nil + } func (e *Ed25519) GetSecretKey() []byte { @@ -124,13 +123,12 @@ func (e *Ed448) Sign(msg []byte) string { func (e *Ed448) Verify(msg []byte, sig string) (bool, error) { if e.Encoder == nil { return ed448.Verify(e.PublicKey, msg, []byte(sig), e.Context), nil - } else { - sig_raw, err := e.Encoder.Decode(sig) - if err != nil { - return false, err - } - return ed448.Verify(e.PublicKey, msg, sig_raw, e.Context), nil } + sigRaw, err := e.Encoder.Decode(sig) + if err != nil { + return false, err + } + return ed448.Verify(e.PublicKey, msg, sigRaw, e.Context), nil } func (e *Ed448) GetSecretKey() []byte { diff --git a/asymmetric/ecdsa_test.go b/asymmetric/ecdsa_test.go index 2b736e4..71828a0 100644 --- a/asymmetric/ecdsa_test.go +++ b/asymmetric/ecdsa_test.go @@ -72,13 +72,13 @@ func TestE2EEEd25519SignVerify(t *testing.T) { { name: "UrlBase64 encoder", asym: asymmetric.Ed25519{ - Encoder: &generic.UrlBase64{}, + Encoder: &generic.URLBase64{}, }, }, { name: "RawUrlBase64 encoder", asym: asymmetric.Ed25519{ - Encoder: &generic.RawUrlBase64{}, + Encoder: &generic.RawURLBase64{}, }, }, { @@ -169,13 +169,13 @@ func TestE2EEEd448SignVerify(t *testing.T) { { name: "UrlBase64 encoder", asym: asymmetric.Ed448{ - Encoder: &generic.UrlBase64{}, + Encoder: &generic.URLBase64{}, }, }, { name: "RawUrlBase64 encoder", asym: asymmetric.Ed448{ - Encoder: &generic.RawUrlBase64{}, + Encoder: &generic.RawURLBase64{}, }, }, { diff --git a/compression/compression.go b/compression/compression.go index 632d1d6..cf5d8e0 100644 --- a/compression/compression.go +++ b/compression/compression.go @@ -77,7 +77,6 @@ func (g *Gzip) Compress(in []byte) ([]byte, error) { } func (g *Gzip) CompressStream(in io.Reader, out io.Writer) error { - enc, err := gzip.NewWriterLevel(out, g.Level) if err != nil { return err @@ -157,7 +156,6 @@ func (z *Zstd) Compress(in []byte) ([]byte, error) { } func (z *Zstd) CompressStream(in io.Reader, out io.Writer) error { - enc, err := zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(z.Level))) if err != nil { return err @@ -233,7 +231,6 @@ func (f *Flate) Compress(in []byte) ([]byte, error) { } func (f *Flate) CompressStream(in io.Reader, out io.Writer) error { - enc, err := flate.NewWriter(out, f.Level) if err != nil { return err @@ -308,7 +305,6 @@ func (zl *Zlib) Compress(in []byte) ([]byte, error) { } func (zl *Zlib) CompressStream(in io.Reader, out io.Writer) error { - enc, err := zlib.NewWriterLevel(out, zl.Level) if err != nil { return err @@ -389,7 +385,6 @@ func (b *Brotli) Compress(in []byte) ([]byte, error) { } func (b *Brotli) CompressStream(in io.Reader, out io.Writer) error { - b.bw.Reset(out) _, err := io.Copy(b.bw, in) if err != nil { @@ -416,7 +411,6 @@ func (b *Brotli) Decompress(in []byte) ([]byte, error) { } func (b *Brotli) DecompressStream(in io.Reader, out io.Writer) error { - if err := b.br.Reset(in); err != nil { return err } diff --git a/compression/compression_test.go b/compression/compression_test.go index e6d1ac1..de604e7 100644 --- a/compression/compression_test.go +++ b/compression/compression_test.go @@ -8,7 +8,6 @@ import ( "github.com/D3vl0per/crypt/asymmetric" "github.com/D3vl0per/crypt/compression" "github.com/D3vl0per/crypt/generic" - r "github.com/stretchr/testify/require" ) @@ -59,7 +58,6 @@ type compressionSample struct { } func compressionSamples() []compressionSample { - ed25519 := asymmetric.Ed25519{} if err := ed25519.Generate(); err != nil { panic(err) @@ -87,7 +85,7 @@ func compressionSamples() []compressionSample { data: ed25519.SecretKey, }, { - name: "ed15519-public-key", + name: "ed25519-public-key", data: ed25519.PublicKey, }, } @@ -113,7 +111,6 @@ func BenchmarkRoundTrip(b *testing.B) { } func benchmarkRoundTrip(b *testing.B, compressor compression.Compressor, data []byte) { - compressed, err := compressor.Compress(data) r.NoError(b, err) @@ -157,7 +154,6 @@ func TestRoundTrips(t *testing.T) { } func testRoundTrip(t *testing.T, compressor compression.Compressor, data []byte) { - compressed, err := compressor.Compress(data) r.NoError(t, err) @@ -317,7 +313,6 @@ func TestRoundTripsFault(t *testing.T) { } func TestZstdWrongDecompressData(t *testing.T) { - data, err := generic.CSPRNG(16) r.NoError(t, err) diff --git a/generic/csprng.go b/generic/csprng.go index 06127f5..178419d 100644 --- a/generic/csprng.go +++ b/generic/csprng.go @@ -7,7 +7,7 @@ import ( "os" ) -// CSPRNG is a cryptographically secure pseudo-random number generator for byte slices +// CSPRNG is a cryptographically secure pseudo-random number generator for byte slices. func CSPRNG(n int64) ([]byte, error) { random := make([]byte, n) if _, err := io.ReadFull(rand.Reader, random); err != nil { @@ -16,13 +16,13 @@ func CSPRNG(n int64) ([]byte, error) { return random, nil } -// CSPRNGHex is a CSPRNG in hex format +// CSPRNGHex is a CSPRNG in hex format. func CSPRNGHex(n int64) (string, error) { rnd, err := CSPRNG(n) return hex.EncodeToString(rnd), err } -// HWRng is a hardware random number generator +// HWRng is a hardware random number generator. func HWRng(n int64) ([]byte, error) { file, err := os.Open("/dev/hwrng") if err != nil { diff --git a/generic/csprng_test.go b/generic/csprng_test.go index 1383070..61e4c13 100644 --- a/generic/csprng_test.go +++ b/generic/csprng_test.go @@ -1,12 +1,11 @@ package generic_test import ( + "crypto/rand" "encoding/hex" "reflect" "testing" - "crypto/rand" - "github.com/D3vl0per/crypt/generic" r "github.com/stretchr/testify/require" ) diff --git a/generic/encoder.go b/generic/encoder.go index d83bd9e..44c39c4 100644 --- a/generic/encoder.go +++ b/generic/encoder.go @@ -15,11 +15,11 @@ type Encoder interface { type Base64 struct{} // URLEncoding is the alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names. -type UrlBase64 struct{} +type URLBase64 struct{} // nolint: lll // RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names. This is the same as URLEncoding but omits padding characters. -type RawUrlBase64 struct{} +type RawURLBase64 struct{} // nolint: lll // RawStdEncoding is the standard raw, unpadded base64 encoding, as defined in RFC 4648 section 3.2. This is the same as StdEncoding but omits padding characters. @@ -39,19 +39,19 @@ func (b *Base64) Decode(data string) ([]byte, error) { return base64.StdEncoding.DecodeString(data) } -func (b *UrlBase64) Encode(data []byte) string { +func (b *URLBase64) Encode(data []byte) string { return base64.URLEncoding.EncodeToString(data) } -func (b *UrlBase64) Decode(data string) ([]byte, error) { +func (b *URLBase64) Decode(data string) ([]byte, error) { return base64.URLEncoding.DecodeString(data) } -func (b *RawUrlBase64) Encode(data []byte) string { +func (b *RawURLBase64) Encode(data []byte) string { return base64.RawURLEncoding.EncodeToString(data) } -func (b *RawUrlBase64) Decode(data string) ([]byte, error) { +func (b *RawURLBase64) Decode(data string) ([]byte, error) { return base64.RawURLEncoding.DecodeString(data) } diff --git a/generic/fs.go b/generic/fs.go index 391fa6d..40e02eb 100644 --- a/generic/fs.go +++ b/generic/fs.go @@ -7,12 +7,12 @@ import ( "path/filepath" ) -// Secure way to delete file +// Secure way to delete file. func Delete(targetPath string, cycle int) error { if cycle == 0 { cycle = 3 } - // #do-not-check-gosec + //nolint:gomnd file, err := os.OpenFile(targetPath, os.O_RDWR, 0o666) if err != nil { return err @@ -56,13 +56,13 @@ func Delete(targetPath string, cycle int) error { return nil } -// Secure way to overwrite file +// Secure way to overwrite file. func Overwrite(targetPath string, data []byte, cycle int) error { if cycle == 0 { cycle = 3 } - // #do-not-check-gosec + //nolint:gomnd file, err := os.OpenFile(targetPath, os.O_RDWR, 0o666) if err != nil { return err diff --git a/generic/fs_test.go b/generic/fs_test.go index 207ee3d..def3538 100644 --- a/generic/fs_test.go +++ b/generic/fs_test.go @@ -36,6 +36,7 @@ func TestDelete(t *testing.T) { t.Errorf("expected file to be deleted, got error: %v", err) } } + func TestOverwrite(t *testing.T) { // Create a temporary file for testing tempFile, err := os.CreateTemp("", "testfile") diff --git a/generic/imports_exports.go b/generic/imports_exports.go index 92e362f..a0a0321 100644 --- a/generic/imports_exports.go +++ b/generic/imports_exports.go @@ -18,7 +18,7 @@ type ImportExport interface { // 1. ImportData (string) -> PublicKey (ed25519.PublicKey) // Two ways to export: // 1. PublicKey (ed25519.PublicKey) -> ExportData (string) -// 2. ExportPublicKey (crypto.PublicKey) -> ExportData (string) +// 2. ExportPublicKey (crypto.PublicKey) -> ExportData (string). type PKIX struct { PublicKey ed25519.PublicKey ImportData string @@ -34,9 +34,8 @@ type PKCS struct { Encoder Encoder } -// struct PKIX ImportData (string) -> struct PKIX PublicKey (ed25519.PublicKey) +// struct PKIX ImportData (string) -> struct PKIX PublicKey (ed25519.PublicKey). func (e *PKIX) Import() error { - if e.ImportData == "" { return errors.New("import data is empty") } @@ -61,18 +60,24 @@ func (e *PKIX) Import() error { if err != nil { return err } - // nolint:errcheck - pkC := pkRaw.(crypto.PublicKey) - // nolint:errcheck - e.PublicKey = pkC.(ed25519.PublicKey) + + pkC, ok := pkRaw.(crypto.PublicKey) + if !ok { + return errors.New("invalid crypto public key type") + } + + pk, ok := pkC.(ed25519.PublicKey) + if !ok { + return errors.New("invalid ed25519 public key type") + } + e.PublicKey = pk return nil } // Two ways to export: // 1. struct PKIX PublicKey (ed25519.PublicKey) -> struct PKIX ExportData (string) -// 2. struct PKIX ExportPublicKey (crypto.PublicKey) -> struct PKIX ExportData (string) +// 2. struct PKIX ExportPublicKey (crypto.PublicKey) -> struct PKIX ExportData (string). func (e *PKIX) Export() error { - if e.ExportPublicKey == nil && e.PublicKey == nil { return errors.New("missing public key") } @@ -102,16 +107,15 @@ func (e *PKIX) Export() error { if e.Encoder == nil { e.ExportData = string(pem.EncodeToMemory(block)) - } else { - e.ExportData = e.Encoder.Encode(pem.EncodeToMemory(block)) + return nil } + e.ExportData = e.Encoder.Encode(pem.EncodeToMemory(block)) return nil } -// struct PKCS ImportData (string) -> struct PKCS SecretKey (ed25519.PrivateKey) +// struct PKCS ImportData (string) -> struct PKCS SecretKey (ed25519.PrivateKey). func (e *PKCS) Import() error { - if e.ImportData == "" { return errors.New("import data is empty") } @@ -136,16 +140,22 @@ func (e *PKCS) Import() error { if err != nil { return err } - // nolint:errcheck - pkC := pkRaw.(crypto.PrivateKey) - // nolint:errcheck - e.SecretKey = pkC.(ed25519.PrivateKey) + + pkC, ok := pkRaw.(crypto.PrivateKey) + if !ok { + return errors.New("invalid crypto private key type") + } + + pk, ok := pkC.(ed25519.PrivateKey) + if !ok { + return errors.New("invalid ed25519 private key type") + } + e.SecretKey = pk return nil } -// struct PKCS SecretKey (ed25519.PrivateKey) -> struct PKCS ExportData (string) +// struct PKCS SecretKey (ed25519.PrivateKey) -> struct PKCS ExportData (string). func (e *PKCS) Export() error { - if e.SecretKey == nil { return errors.New("missing secret key") } diff --git a/generic/imports_exports_test.go b/generic/imports_exports_test.go index 9615bca..2e50012 100644 --- a/generic/imports_exports_test.go +++ b/generic/imports_exports_test.go @@ -64,28 +64,28 @@ func TestPKIX(t *testing.T) { name: "UrlBase64 encoded keys", pkix: generic.PKIX{ ExportPublicKey: asym.SecretKey.Public(), - Encoder: &generic.UrlBase64{}, + Encoder: &generic.URLBase64{}, }, }, { name: "UrlBase64 encoded keys with ed25519.PublicKey", pkix: generic.PKIX{ ExportPublicKey: asym.PublicKey, - Encoder: &generic.UrlBase64{}, + Encoder: &generic.URLBase64{}, }, }, { name: "RawUrlBase64 encoded keys", pkix: generic.PKIX{ ExportPublicKey: asym.SecretKey.Public(), - Encoder: &generic.RawUrlBase64{}, + Encoder: &generic.RawURLBase64{}, }, }, { name: "RawUrlBase64 encoded keys with ed25519.PublicKey", pkix: generic.PKIX{ ExportPublicKey: asym.PublicKey, - Encoder: &generic.RawUrlBase64{}, + Encoder: &generic.RawURLBase64{}, }, }, { @@ -242,14 +242,14 @@ func TestPKCS(t *testing.T) { name: "UrlBase64 encoded keys", pkcs: generic.PKCS{ SecretKey: asym.SecretKey, - Encoder: &generic.UrlBase64{}, + Encoder: &generic.URLBase64{}, }, }, { name: "RawUrlBase64 encoded keys", pkcs: generic.PKCS{ SecretKey: asym.SecretKey, - Encoder: &generic.RawUrlBase64{}, + Encoder: &generic.RawURLBase64{}, }, }, { @@ -277,7 +277,6 @@ func TestPKCS(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err = tt.pkcs.Export() r.NoError(t, err) t.Log("PKCS wrapped Ed25519 Secret Key", tt.pkcs.ExportData) diff --git a/generic/utils.go b/generic/utils.go index 87ff804..95743c5 100644 --- a/generic/utils.go +++ b/generic/utils.go @@ -4,7 +4,7 @@ import ( "bytes" ) -// AllZero checks if all bytes in a slice are zero +// AllZero checks if all bytes in a slice are zero. func AllZero(s []byte) bool { for _, v := range s { if v != 0 { @@ -15,7 +15,7 @@ func AllZero(s []byte) bool { } // StrCnct concatenates strings into one -// Example: StrCnct([]string{"a", "b", "c"}...) -> "abc" +// Example: StrCnct([]string{"a", "b", "c"}...) -> "abc". func StrCnct(str ...string) string { var buffer bytes.Buffer diff --git a/generic/utils_test.go b/generic/utils_test.go index 852e3e2..6fa12d2 100644 --- a/generic/utils_test.go +++ b/generic/utils_test.go @@ -42,6 +42,7 @@ func TestAllZero(t *testing.T) { }) } } + func TestStrCnct(t *testing.T) { tests := []struct { name string diff --git a/go.mod b/go.mod index f7aa524..b70139b 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,19 @@ module github.com/D3vl0per/crypt -go 1.21.7 +go 1.22.1 require ( filippo.io/age v1.1.1 github.com/andybalholm/brotli v1.1.0 github.com/cloudflare/circl v1.3.7 github.com/klauspost/compress v1.17.7 - github.com/stretchr/testify v1.8.4 - golang.org/x/crypto v0.19.0 + github.com/stretchr/testify v1.9.0 + golang.org/x/crypto v0.21.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.17.0 // indirect + golang.org/x/sys v0.18.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index eea62ae..f6b9df4 100644 --- a/go.sum +++ b/go.sum @@ -12,10 +12,16 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/hash/hash.go b/hash/hash.go index 66cd911..480027e 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -9,9 +9,7 @@ import ( "golang.org/x/crypto/sha3" ) -var ( - ErrHmacSecretNil = errors.New("HMAC secret is nil") -) +var ErrHmacSecretNil = errors.New("HMAC secret is nil") type Algorithms interface { // data diff --git a/hash/hash_test.go b/hash/hash_test.go index b0fd77f..6617418 100644 --- a/hash/hash_test.go +++ b/hash/hash_test.go @@ -1,18 +1,17 @@ package hash_test import ( - // "encoding/hex" + // "encoding/hex". "encoding/hex" "strings" "testing" hasher "github.com/D3vl0per/crypt/hash" - // a "github.com/stretchr/testify/assert" + // a "github.com/stretchr/testify/assert". r "github.com/stretchr/testify/require" ) func TestBlakes(t *testing.T) { - tests := []struct { name string algo hasher.Algorithms @@ -113,11 +112,9 @@ func TestBlakes(t *testing.T) { } }) } - } func TestFaultBlakes(t *testing.T) { - tests := []struct { name string algo hasher.Algorithms @@ -211,7 +208,6 @@ func TestFaultBlakes(t *testing.T) { } func TestNilKeyError(t *testing.T) { - tests := []struct { name string algo hasher.Algorithms diff --git a/hash/kdf.go b/hash/kdf.go index f43ac5f..b57febb 100644 --- a/hash/kdf.go +++ b/hash/kdf.go @@ -12,11 +12,12 @@ import ( ) const ( - AIterations uint32 = 2 - AMemory uint32 = 1 * 64 * 1024 - AParallelism uint8 = 4 - AKeyLen uint32 = 32 - HKDFKeysize int = 32 + AIterations uint32 = 2 + AMemory uint32 = 1 * 64 * 1024 + AParallelism uint8 = 4 + AKeyLen uint32 = 32 + HKDFKeysize int = 32 + Argon2Saltsize int = 16 ) type Kdf interface { @@ -59,7 +60,8 @@ func (a *Argon2ID) argon2ID(data []byte) argonOutput { ",t=", strconv.FormatUint(uint64(a.Iterations), 10), ",p=", strconv.FormatInt(int64(a.Parallelism), 10), "$", saltB64, - "$", hashB64}..., + "$", hashB64, + }..., ) return argonOutput{ @@ -73,12 +75,12 @@ func (a *Argon2ID) argon2ID(data []byte) argonOutput { func (a *Argon2ID) Hash(data []byte) (string, error) { if a.Salt != nil { - if len(a.Salt) != 16 { + if len(a.Salt) != Argon2Saltsize { return "", errors.New("salt must be 16 byte long") } } else { var err error - a.Salt, err = generic.CSPRNG(16) + a.Salt, err = generic.CSPRNG(int64(Argon2Saltsize)) if err != nil { return "", err } @@ -137,7 +139,7 @@ func (a *Argon2ID) ExtractParameters(input string) (Parameters, error) { re := regexp.MustCompile(pattern) matches := re.FindStringSubmatch(input) - + //nolint:gomnd if len(matches) != 8 { return Parameters{}, errors.New("invalid input format") } @@ -159,7 +161,7 @@ func (a *Argon2ID) ExtractParameters(input string) (Parameters, error) { return Parameters{}, errors.New(generic.StrCnct([]string{"salt base64 decode error: ", err.Error()}...)) } - if len(parameters.Salt) != 16 { + if len(parameters.Salt) != Argon2Saltsize { return Parameters{}, errors.New("salt must be 16 byte long") } diff --git a/hash/kdf_test.go b/hash/kdf_test.go index 49f088c..bcea4b2 100644 --- a/hash/kdf_test.go +++ b/hash/kdf_test.go @@ -66,7 +66,6 @@ func TestArgon2ID(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - argonString, err := tt.argon.Hash(data) r.NoError(t, err) @@ -189,7 +188,6 @@ func TestArgon2IDWrongParameters(t *testing.T) { } }) } - } func TestWrongValidate(t *testing.T) { diff --git a/insecure/asymmetric/asymmetric.go b/insecure/asymmetric/asymmetric.go index b42126b..40e4d72 100644 --- a/insecure/asymmetric/asymmetric.go +++ b/insecure/asymmetric/asymmetric.go @@ -13,11 +13,17 @@ import ( /// NaCl Box Suite /// +const ( + BoxKeySize = 32 + BoxNonceSize = 24 +) + type keypairs struct { PK []byte SK []byte } +//nolint:golint func GenerateBoxKeypair() (keypairs, error) { pk, sk, err := box.GenerateKey(rand.Reader) if err != nil { @@ -31,38 +37,38 @@ func GenerateBoxKeypair() (keypairs, error) { } func EncryptBox(senderSK, recipientPK, plaintext []byte) ([]byte, error) { - var recipientPublicKey [32]byte + var recipientPublicKey [BoxKeySize]byte subtle.ConstantTimeCopy(1, recipientPublicKey[:], recipientPK) - var senderSecretKey [32]byte + var senderSecretKey [BoxKeySize]byte subtle.ConstantTimeCopy(1, senderSecretKey[:], senderSK) - sharedEncryptKey := new([32]byte) + sharedEncryptKey := new([BoxKeySize]byte) box.Precompute(sharedEncryptKey, &recipientPublicKey, &senderSecretKey) - nonce_raw, err := generic.CSPRNG(24) + nonceRaw, err := generic.CSPRNG(BoxNonceSize) if err != nil { return nil, err } - var nonce [24]byte - subtle.ConstantTimeCopy(1, nonce[:], nonce_raw) + var nonce [BoxNonceSize]byte + subtle.ConstantTimeCopy(1, nonce[:], nonceRaw) return box.SealAfterPrecomputation(nonce[:], plaintext, &nonce, sharedEncryptKey), nil } func DecryptBox(senderPK, recipientSK, ciphertext []byte) ([]byte, error) { - var senderPublicKey [32]byte + var senderPublicKey [BoxKeySize]byte subtle.ConstantTimeCopy(1, senderPublicKey[:], senderPK) - var recipientSecretKey [32]byte + var recipientSecretKey [BoxKeySize]byte subtle.ConstantTimeCopy(1, recipientSecretKey[:], recipientSK) - var sharedDecryptKey [32]byte + var sharedDecryptKey [BoxKeySize]byte box.Precompute(&sharedDecryptKey, &senderPublicKey, &recipientSecretKey) - var decryptNonce [24]byte - subtle.ConstantTimeCopy(1, decryptNonce[:], ciphertext[:24]) - decrypted, ok := box.OpenAfterPrecomputation(nil, ciphertext[24:], &decryptNonce, &sharedDecryptKey) + var decryptNonce [BoxNonceSize]byte + subtle.ConstantTimeCopy(1, decryptNonce[:], ciphertext[:BoxNonceSize]) + decrypted, ok := box.OpenAfterPrecomputation(nil, ciphertext[BoxNonceSize:], &decryptNonce, &sharedDecryptKey) if !ok { return nil, errors.New("decryption error") } diff --git a/insecure/asymmetric/asymmetric_test.go b/insecure/asymmetric/asymmetric_test.go index c1b7a9e..3c19f2b 100644 --- a/insecure/asymmetric/asymmetric_test.go +++ b/insecure/asymmetric/asymmetric_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/D3vl0per/crypt/insecure/asymmetric" - a "github.com/stretchr/testify/assert" r "github.com/stretchr/testify/require" ) diff --git a/insecure/symmetric/symmetric.go b/insecure/symmetric/symmetric.go index 8c4d59a..a52be43 100644 --- a/insecure/symmetric/symmetric.go +++ b/insecure/symmetric/symmetric.go @@ -12,6 +12,11 @@ import ( "golang.org/x/crypto/nacl/secretbox" ) +const ( + SecretBoxKeySize = 32 + SecretBoxNonceSize = 24 +) + type Symmetric interface { Encrypt([]byte, []byte) ([]byte, error) Decrypt([]byte, []byte) ([]byte, error) @@ -20,39 +25,39 @@ type Symmetric interface { type SecretBox struct{} func (s *SecretBox) Encrypt(key, payload []byte) ([]byte, error) { - if len(key) != 32 { + if len(key) != SecretBoxKeySize { return nil, errors.New("invalid key size") } - var secretKey [32]byte + var secretKey [SecretBoxKeySize]byte subtle.ConstantTimeCopy(1, secretKey[:], key) - nonce_raw, err := generic.CSPRNG(24) + nonceRaw, err := generic.CSPRNG(SecretBoxNonceSize) if err != nil { return nil, err } - var nonce [24]byte - subtle.ConstantTimeCopy(1, nonce[:], nonce_raw) + var nonce [SecretBoxNonceSize]byte + subtle.ConstantTimeCopy(1, nonce[:], nonceRaw) return secretbox.Seal(nonce[:], payload, &nonce, &secretKey), nil } func (s *SecretBox) Decrypt(key, payload []byte) ([]byte, error) { - if len(key) != 32 { + if len(key) != SecretBoxKeySize { return nil, errors.New("invalid key size") } - var secretKey [32]byte + var secretKey [SecretBoxKeySize]byte subtle.ConstantTimeCopy(1, secretKey[:], key) - if len(payload) < 24 { + if len(payload) < SecretBoxNonceSize { return nil, errors.New("payload is too short") } var nonce [24]byte - subtle.ConstantTimeCopy(1, nonce[:], payload[:24]) + subtle.ConstantTimeCopy(1, nonce[:], payload[:SecretBoxNonceSize]) - decrypted, ok := secretbox.Open(nil, payload[24:], &nonce, &secretKey) + decrypted, ok := secretbox.Open(nil, payload[SecretBoxNonceSize:], &nonce, &secretKey) if !ok { return nil, errors.New("decryption error") } diff --git a/insecure/symmetric/symmetric_test.go b/insecure/symmetric/symmetric_test.go index 8b1207f..017314f 100644 --- a/insecure/symmetric/symmetric_test.go +++ b/insecure/symmetric/symmetric_test.go @@ -49,7 +49,6 @@ func TestE2E(t *testing.T) { } func TestE2EFault(t *testing.T) { - type cases struct { name string key []byte diff --git a/symmetric/symmetric.go b/symmetric/symmetric.go index 06f35be..c7e437a 100644 --- a/symmetric/symmetric.go +++ b/symmetric/symmetric.go @@ -21,6 +21,7 @@ type Symmetric interface { Decrypt([]byte, []byte) ([]byte, error) } +//nolint:golint type SymmetricStream interface { Encrypt(io.Reader, io.Writer) error Decrypt(io.Reader, io.Writer) error @@ -29,17 +30,19 @@ type SymmetricStream interface { type XChaCha20 struct { AdditionalData []byte } -type Xor struct{} -type AesGCM struct { - AdditionalData []byte -} +type ( + Xor struct{} + AesGCM struct { + AdditionalData []byte + } +) type XChaCha20Stream struct { Key []byte Hash func() hash.Hash } -// XChaCha20-Poly1305 +// XChaCha20-Poly1305. func (x *XChaCha20) Encrypt(key, plaintext []byte) ([]byte, error) { if generic.AllZero(key) { return nil, errors.New("key is all zero") @@ -57,10 +60,8 @@ func (x *XChaCha20) Encrypt(key, plaintext []byte) ([]byte, error) { if x.AdditionalData != nil { return aead.Seal(nonce, nonce, plaintext, x.AdditionalData), nil - } else { - return aead.Seal(nonce, nonce, plaintext, nil), nil } - + return aead.Seal(nonce, nonce, plaintext, nil), nil } func (x *XChaCha20) Decrypt(key, ciphertext []byte) ([]byte, error) { @@ -85,16 +86,15 @@ func (x *XChaCha20) Decrypt(key, ciphertext []byte) ([]byte, error) { return nil, err } return payload, nil - } else { - payload, err := aead.Open(nil, nonce, ciphertext, nil) - if err != nil { - return nil, err - } - return payload, nil } + payload, err := aead.Open(nil, nonce, ciphertext, nil) + if err != nil { + return nil, err + } + return payload, nil } -// XOR +// XOR. func (x *Xor) Encrypt(key, payload []byte) ([]byte, error) { if len(payload) != len(key) { return nil, errors.New("insecure xor operation, key and payload length need to be equal") @@ -114,7 +114,7 @@ func (x *Xor) Decrypt(key, payload []byte) ([]byte, error) { return x.Encrypt(key, payload) } -// XChaCha20-Poly1305 Age Stream +// XChaCha20-Poly1305 Age Stream. func (x *XChaCha20Stream) Encrypt(in io.Reader, out io.Writer) error { if generic.AllZero(x.Key) { return errors.New("key is all zero") @@ -249,9 +249,8 @@ func (a *AesGCM) Encrypt(key, payload []byte) ([]byte, error) { if a.AdditionalData != nil { return gcm.Seal(nonce, nonce, payload, a.AdditionalData), nil - } else { - return gcm.Seal(nonce, nonce, payload, nil), nil } + return gcm.Seal(nonce, nonce, payload, nil), nil } func (a *AesGCM) Decrypt(key, ciphertext []byte) ([]byte, error) { @@ -282,11 +281,10 @@ func (a *AesGCM) Decrypt(key, ciphertext []byte) ([]byte, error) { return nil, err } return payload, nil - } else { - payload, err := gcm.Open(nil, nonce, rawCiphertext, nil) - if err != nil { - return nil, err - } - return payload, nil } + payload, err := gcm.Open(nil, nonce, rawCiphertext, nil) + if err != nil { + return nil, err + } + return payload, nil } diff --git a/symmetric/symmetric_test.go b/symmetric/symmetric_test.go index fefdec2..2058f52 100644 --- a/symmetric/symmetric_test.go +++ b/symmetric/symmetric_test.go @@ -3,7 +3,6 @@ package symmetric_test import ( "bytes" "crypto/sha256" - "testing" "github.com/D3vl0per/crypt/generic" @@ -139,7 +138,6 @@ func TestE2EE(t *testing.T) { r.Equal(t, out2.Bytes(), tc.payload) }) } - } func TestE2EEFault(t *testing.T) { @@ -418,7 +416,6 @@ func TestE2EEFault(t *testing.T) { } }) } - } func generateKey(t *testing.T, size int) []byte { diff --git a/vendor/github.com/stretchr/testify/assert/assertion_compare.go b/vendor/github.com/stretchr/testify/assert/assertion_compare.go index b774da8..4d4b4aa 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_compare.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_compare.go @@ -28,6 +28,8 @@ var ( uint32Type = reflect.TypeOf(uint32(1)) uint64Type = reflect.TypeOf(uint64(1)) + uintptrType = reflect.TypeOf(uintptr(1)) + float32Type = reflect.TypeOf(float32(1)) float64Type = reflect.TypeOf(float64(1)) @@ -308,11 +310,11 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) { case reflect.Struct: { // All structs enter here. We're not interested in most types. - if !canConvert(obj1Value, timeType) { + if !obj1Value.CanConvert(timeType) { break } - // time.Time can compared! + // time.Time can be compared! timeObj1, ok := obj1.(time.Time) if !ok { timeObj1 = obj1Value.Convert(timeType).Interface().(time.Time) @@ -328,7 +330,7 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) { case reflect.Slice: { // We only care about the []byte type. - if !canConvert(obj1Value, bytesType) { + if !obj1Value.CanConvert(bytesType) { break } @@ -345,6 +347,26 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) { return CompareType(bytes.Compare(bytesObj1, bytesObj2)), true } + case reflect.Uintptr: + { + uintptrObj1, ok := obj1.(uintptr) + if !ok { + uintptrObj1 = obj1Value.Convert(uintptrType).Interface().(uintptr) + } + uintptrObj2, ok := obj2.(uintptr) + if !ok { + uintptrObj2 = obj2Value.Convert(uintptrType).Interface().(uintptr) + } + if uintptrObj1 > uintptrObj2 { + return compareGreater, true + } + if uintptrObj1 == uintptrObj2 { + return compareEqual, true + } + if uintptrObj1 < uintptrObj2 { + return compareLess, true + } + } } return compareEqual, false diff --git a/vendor/github.com/stretchr/testify/assert/assertion_compare_can_convert.go b/vendor/github.com/stretchr/testify/assert/assertion_compare_can_convert.go deleted file mode 100644 index da86790..0000000 --- a/vendor/github.com/stretchr/testify/assert/assertion_compare_can_convert.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build go1.17 -// +build go1.17 - -// TODO: once support for Go 1.16 is dropped, this file can be -// merged/removed with assertion_compare_go1.17_test.go and -// assertion_compare_legacy.go - -package assert - -import "reflect" - -// Wrapper around reflect.Value.CanConvert, for compatibility -// reasons. -func canConvert(value reflect.Value, to reflect.Type) bool { - return value.CanConvert(to) -} diff --git a/vendor/github.com/stretchr/testify/assert/assertion_compare_legacy.go b/vendor/github.com/stretchr/testify/assert/assertion_compare_legacy.go deleted file mode 100644 index 1701af2..0000000 --- a/vendor/github.com/stretchr/testify/assert/assertion_compare_legacy.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build !go1.17 -// +build !go1.17 - -// TODO: once support for Go 1.16 is dropped, this file can be -// merged/removed with assertion_compare_go1.17_test.go and -// assertion_compare_can_convert.go - -package assert - -import "reflect" - -// Older versions of Go does not have the reflect.Value.CanConvert -// method. -func canConvert(value reflect.Value, to reflect.Type) bool { - return false -} diff --git a/vendor/github.com/stretchr/testify/assert/assertion_format.go b/vendor/github.com/stretchr/testify/assert/assertion_format.go index 84dbd6c..3ddab10 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_format.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_format.go @@ -1,7 +1,4 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ +// Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT. package assert @@ -107,7 +104,7 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, return EqualExportedValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") @@ -616,6 +613,16 @@ func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interf return NotErrorIs(t, err, target, append([]interface{}{msg}, args...)...) } +// NotImplementsf asserts that an object does not implement the specified interface. +// +// assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return NotImplements(t, interfaceObject, object, append([]interface{}{msg}, args...)...) +} + // NotNilf asserts that the specified object is not nil. // // assert.NotNilf(t, err, "error message %s", "formatted") @@ -660,10 +667,12 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, return NotSame(t, expected, actual, append([]interface{}{msg}, args...)...) } -// NotSubsetf asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubsetf asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") +// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() @@ -747,10 +756,11 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg return Same(t, expected, actual, append([]interface{}{msg}, args...)...) } -// Subsetf asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subsetf asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") +// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/assert/assertion_forward.go b/vendor/github.com/stretchr/testify/assert/assertion_forward.go index b1d94ae..a84e09b 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_forward.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_forward.go @@ -1,7 +1,4 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ +// Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT. package assert @@ -189,7 +186,7 @@ func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface return EqualExportedValuesf(a.t, expected, actual, msg, args...) } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // a.EqualValues(uint32(123), int32(123)) @@ -200,7 +197,7 @@ func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAn return EqualValues(a.t, expected, actual, msgAndArgs...) } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted") @@ -1221,6 +1218,26 @@ func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...in return NotErrorIsf(a.t, err, target, msg, args...) } +// NotImplements asserts that an object does not implement the specified interface. +// +// a.NotImplements((*MyInterface)(nil), new(MyObject)) +func (a *Assertions) NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotImplements(a.t, interfaceObject, object, msgAndArgs...) +} + +// NotImplementsf asserts that an object does not implement the specified interface. +// +// a.NotImplementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +func (a *Assertions) NotImplementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return NotImplementsf(a.t, interfaceObject, object, msg, args...) +} + // NotNil asserts that the specified object is not nil. // // a.NotNil(err) @@ -1309,10 +1326,12 @@ func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg stri return NotSamef(a.t, expected, actual, msg, args...) } -// NotSubset asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubset asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +// a.NotSubset([1, 3, 4], [1, 2]) +// a.NotSubset({"x": 1, "y": 2}, {"z": 3}) func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1320,10 +1339,12 @@ func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs return NotSubset(a.t, list, subset, msgAndArgs...) } -// NotSubsetf asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubsetf asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted") +// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1483,10 +1504,11 @@ func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, return Samef(a.t, expected, actual, msg, args...) } -// Subset asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subset asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +// a.Subset([1, 2, 3], [1, 2]) +// a.Subset({"x": 1, "y": 2}, {"x": 1}) func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1494,10 +1516,11 @@ func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ... return Subset(a.t, list, subset, msgAndArgs...) } -// Subsetf asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subsetf asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted") +// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/assert/assertions.go b/vendor/github.com/stretchr/testify/assert/assertions.go index a55d1bb..0b7570f 100644 --- a/vendor/github.com/stretchr/testify/assert/assertions.go +++ b/vendor/github.com/stretchr/testify/assert/assertions.go @@ -19,7 +19,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/pmezard/go-difflib/difflib" - yaml "gopkg.in/yaml.v3" + "gopkg.in/yaml.v3" ) //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_format.go.tmpl" @@ -110,7 +110,12 @@ func copyExportedFields(expected interface{}) interface{} { return result.Interface() case reflect.Array, reflect.Slice: - result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) + var result reflect.Value + if expectedKind == reflect.Array { + result = reflect.New(reflect.ArrayOf(expectedValue.Len(), expectedType.Elem())).Elem() + } else { + result = reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) + } for i := 0; i < expectedValue.Len(); i++ { index := expectedValue.Index(i) if isNil(index) { @@ -140,6 +145,8 @@ func copyExportedFields(expected interface{}) interface{} { // structures. // // This function does no assertion of any kind. +// +// Deprecated: Use [EqualExportedValues] instead. func ObjectsExportedFieldsAreEqual(expected, actual interface{}) bool { expectedCleaned := copyExportedFields(expected) actualCleaned := copyExportedFields(actual) @@ -153,17 +160,40 @@ func ObjectsAreEqualValues(expected, actual interface{}) bool { return true } - actualType := reflect.TypeOf(actual) - if actualType == nil { + expectedValue := reflect.ValueOf(expected) + actualValue := reflect.ValueOf(actual) + if !expectedValue.IsValid() || !actualValue.IsValid() { return false } - expectedValue := reflect.ValueOf(expected) - if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) { + + expectedType := expectedValue.Type() + actualType := actualValue.Type() + if !expectedType.ConvertibleTo(actualType) { + return false + } + + if !isNumericType(expectedType) || !isNumericType(actualType) { // Attempt comparison after type conversion - return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual) + return reflect.DeepEqual( + expectedValue.Convert(actualType).Interface(), actual, + ) } - return false + // If BOTH values are numeric, there are chances of false positives due + // to overflow or underflow. So, we need to make sure to always convert + // the smaller type to a larger type before comparing. + if expectedType.Size() >= actualType.Size() { + return actualValue.Convert(expectedType).Interface() == expected + } + + return expectedValue.Convert(actualType).Interface() == actual +} + +// isNumericType returns true if the type is one of: +// int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, +// float32, float64, complex64, complex128 +func isNumericType(t reflect.Type) bool { + return t.Kind() >= reflect.Int && t.Kind() <= reflect.Complex128 } /* CallerInfo is necessary because the assert functions use the testing object @@ -266,7 +296,7 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { // Aligns the provided message so that all lines after the first line start at the same location as the first line. // Assumes that the first line starts at the correct location (after carriage return, tab, label, spacer and tab). -// The longestLabelLen parameter specifies the length of the longest label in the output (required becaues this is the +// The longestLabelLen parameter specifies the length of the longest label in the output (required because this is the // basis on which the alignment occurs). func indentMessageLines(message string, longestLabelLen int) string { outBuf := new(bytes.Buffer) @@ -382,6 +412,25 @@ func Implements(t TestingT, interfaceObject interface{}, object interface{}, msg return true } +// NotImplements asserts that an object does not implement the specified interface. +// +// assert.NotImplements(t, (*MyInterface)(nil), new(MyObject)) +func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + interfaceType := reflect.TypeOf(interfaceObject).Elem() + + if object == nil { + return Fail(t, fmt.Sprintf("Cannot check if nil does not implement %v", interfaceType), msgAndArgs...) + } + if reflect.TypeOf(object).Implements(interfaceType) { + return Fail(t, fmt.Sprintf("%T implements %v", object, interfaceType), msgAndArgs...) + } + + return true +} + // IsType asserts that the specified objects are of the same type. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { @@ -496,7 +545,7 @@ func samePointers(first, second interface{}) bool { // representations appropriate to be presented to the user. // // If the values are not of like type, the returned strings will be prefixed -// with the type name, and the value will be enclosed in parenthesis similar +// with the type name, and the value will be enclosed in parentheses similar // to a type conversion in the Go grammar. func formatUnequalValues(expected, actual interface{}) (e string, a string) { if reflect.TypeOf(expected) != reflect.TypeOf(actual) { @@ -523,7 +572,7 @@ func truncatingFormat(data interface{}) string { return value } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValues(t, uint32(123), int32(123)) @@ -566,12 +615,19 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs .. return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...) } + if aType.Kind() == reflect.Ptr { + aType = aType.Elem() + } + if bType.Kind() == reflect.Ptr { + bType = bType.Elem() + } + if aType.Kind() != reflect.Struct { - return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...) + return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...) } if bType.Kind() != reflect.Struct { - return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...) + return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...) } expected = copyExportedFields(expected) @@ -620,17 +676,6 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { return Fail(t, "Expected value not to be nil.", msgAndArgs...) } -// containsKind checks if a specified kind in the slice of kinds. -func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool { - for i := 0; i < len(kinds); i++ { - if kind == kinds[i] { - return true - } - } - - return false -} - // isNil checks if a specified object is nil or not, without Failing. func isNil(object interface{}) bool { if object == nil { @@ -638,16 +683,13 @@ func isNil(object interface{}) bool { } value := reflect.ValueOf(object) - kind := value.Kind() - isNilableKind := containsKind( - []reflect.Kind{ - reflect.Chan, reflect.Func, - reflect.Interface, reflect.Map, - reflect.Ptr, reflect.Slice, reflect.UnsafePointer}, - kind) - - if isNilableKind && value.IsNil() { - return true + switch value.Kind() { + case + reflect.Chan, reflect.Func, + reflect.Interface, reflect.Map, + reflect.Ptr, reflect.Slice, reflect.UnsafePointer: + + return value.IsNil() } return false @@ -731,16 +773,14 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { } -// getLen try to get length of object. -// return (false, 0) if impossible. -func getLen(x interface{}) (ok bool, length int) { +// getLen tries to get the length of an object. +// It returns (0, false) if impossible. +func getLen(x interface{}) (length int, ok bool) { v := reflect.ValueOf(x) defer func() { - if e := recover(); e != nil { - ok = false - } + ok = recover() == nil }() - return true, v.Len() + return v.Len(), true } // Len asserts that the specified object has specific length. @@ -751,13 +791,13 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) if h, ok := t.(tHelper); ok { h.Helper() } - ok, l := getLen(object) + l, ok := getLen(object) if !ok { - return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", object), msgAndArgs...) + return Fail(t, fmt.Sprintf("\"%v\" could not be applied builtin len()", object), msgAndArgs...) } if l != length { - return Fail(t, fmt.Sprintf("\"%s\" should have %d item(s), but has %d", object, length, l), msgAndArgs...) + return Fail(t, fmt.Sprintf("\"%v\" should have %d item(s), but has %d", object, length, l), msgAndArgs...) } return true } @@ -919,10 +959,11 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) } -// Subset asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subset asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +// assert.Subset(t, [1, 2, 3], [1, 2]) +// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1}) func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) { if h, ok := t.(tHelper); ok { h.Helper() @@ -975,10 +1016,12 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok return true } -// NotSubset asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubset asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +// assert.NotSubset(t, [1, 3, 4], [1, 2]) +// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1439,7 +1482,7 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd h.Helper() } if math.IsNaN(epsilon) { - return Fail(t, "epsilon must not be NaN") + return Fail(t, "epsilon must not be NaN", msgAndArgs...) } actualEpsilon, err := calcRelativeError(expected, actual) if err != nil { @@ -1458,19 +1501,26 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m if h, ok := t.(tHelper); ok { h.Helper() } - if expected == nil || actual == nil || - reflect.TypeOf(actual).Kind() != reflect.Slice || - reflect.TypeOf(expected).Kind() != reflect.Slice { + + if expected == nil || actual == nil { return Fail(t, "Parameters must be slice", msgAndArgs...) } - actualSlice := reflect.ValueOf(actual) expectedSlice := reflect.ValueOf(expected) + actualSlice := reflect.ValueOf(actual) - for i := 0; i < actualSlice.Len(); i++ { - result := InEpsilon(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), epsilon) - if !result { - return result + if expectedSlice.Type().Kind() != reflect.Slice { + return Fail(t, "Expected value must be slice", msgAndArgs...) + } + + expectedLen := expectedSlice.Len() + if !IsType(t, expected, actual) || !Len(t, actual, expectedLen) { + return false + } + + for i := 0; i < expectedLen; i++ { + if !InEpsilon(t, expectedSlice.Index(i).Interface(), actualSlice.Index(i).Interface(), epsilon, "at index %d", i) { + return false } } @@ -1870,23 +1920,18 @@ func (c *CollectT) Errorf(format string, args ...interface{}) { } // FailNow panics. -func (c *CollectT) FailNow() { +func (*CollectT) FailNow() { panic("Assertion failed") } -// Reset clears the collected errors. -func (c *CollectT) Reset() { - c.errors = nil +// Deprecated: That was a method for internal usage that should not have been published. Now just panics. +func (*CollectT) Reset() { + panic("Reset() is deprecated") } -// Copy copies the collected errors to the supplied t. -func (c *CollectT) Copy(t TestingT) { - if tt, ok := t.(tHelper); ok { - tt.Helper() - } - for _, err := range c.errors { - t.Errorf("%v", err) - } +// Deprecated: That was a method for internal usage that should not have been published. Now just panics. +func (*CollectT) Copy(TestingT) { + panic("Copy() is deprecated") } // EventuallyWithT asserts that given condition will be met in waitFor time, @@ -1912,8 +1957,8 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time h.Helper() } - collect := new(CollectT) - ch := make(chan bool, 1) + var lastFinishedTickErrs []error + ch := make(chan []error, 1) timer := time.NewTimer(waitFor) defer timer.Stop() @@ -1924,19 +1969,25 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time for tick := ticker.C; ; { select { case <-timer.C: - collect.Copy(t) + for _, err := range lastFinishedTickErrs { + t.Errorf("%v", err) + } return Fail(t, "Condition never satisfied", msgAndArgs...) case <-tick: tick = nil - collect.Reset() go func() { + collect := new(CollectT) + defer func() { + ch <- collect.errors + }() condition(collect) - ch <- len(collect.errors) == 0 }() - case v := <-ch: - if v { + case errs := <-ch: + if len(errs) == 0 { return true } + // Keep the errors from the last ended condition, so that they can be copied to t if timeout is reached. + lastFinishedTickErrs = errs tick = ticker.C } } diff --git a/vendor/github.com/stretchr/testify/assert/http_assertions.go b/vendor/github.com/stretchr/testify/assert/http_assertions.go index d8038c2..861ed4b 100644 --- a/vendor/github.com/stretchr/testify/assert/http_assertions.go +++ b/vendor/github.com/stretchr/testify/assert/http_assertions.go @@ -12,7 +12,7 @@ import ( // an error if building a new request fails. func httpCode(handler http.HandlerFunc, method, url string, values url.Values) (int, error) { w := httptest.NewRecorder() - req, err := http.NewRequest(method, url, nil) + req, err := http.NewRequest(method, url, http.NoBody) if err != nil { return -1, err } @@ -32,12 +32,12 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, value } code, err := httpCode(handler, method, url, values) if err != nil { - Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) + Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) } isSuccessCode := code >= http.StatusOK && code <= http.StatusPartialContent if !isSuccessCode { - Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code)) + Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...) } return isSuccessCode @@ -54,12 +54,12 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, valu } code, err := httpCode(handler, method, url, values) if err != nil { - Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) + Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) } isRedirectCode := code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect if !isRedirectCode { - Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code)) + Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...) } return isRedirectCode @@ -76,12 +76,12 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values } code, err := httpCode(handler, method, url, values) if err != nil { - Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) + Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) } isErrorCode := code >= http.StatusBadRequest if !isErrorCode { - Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code)) + Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code), msgAndArgs...) } return isErrorCode @@ -98,12 +98,12 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method, url string, va } code, err := httpCode(handler, method, url, values) if err != nil { - Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) + Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err), msgAndArgs...) } successful := code == statuscode if !successful { - Fail(t, fmt.Sprintf("Expected HTTP status code %d for %q but received %d", statuscode, url+"?"+values.Encode(), code)) + Fail(t, fmt.Sprintf("Expected HTTP status code %d for %q but received %d", statuscode, url+"?"+values.Encode(), code), msgAndArgs...) } return successful @@ -113,7 +113,10 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method, url string, va // empty string if building a new request fails. func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string { w := httptest.NewRecorder() - req, err := http.NewRequest(method, url+"?"+values.Encode(), nil) + if len(values) > 0 { + url += "?" + values.Encode() + } + req, err := http.NewRequest(method, url, http.NoBody) if err != nil { return "" } @@ -135,7 +138,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, contains := strings.Contains(body, fmt.Sprint(str)) if !contains { - Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) + Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...) } return contains @@ -155,7 +158,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url strin contains := strings.Contains(body, fmt.Sprint(str)) if contains { - Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) + Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...) } return !contains diff --git a/vendor/github.com/stretchr/testify/require/require.go b/vendor/github.com/stretchr/testify/require/require.go index 63f8521..506a82f 100644 --- a/vendor/github.com/stretchr/testify/require/require.go +++ b/vendor/github.com/stretchr/testify/require/require.go @@ -1,7 +1,4 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ +// Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT. package require @@ -235,7 +232,7 @@ func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, t.FailNow() } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValues(t, uint32(123), int32(123)) @@ -249,7 +246,7 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg t.FailNow() } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") @@ -1546,6 +1543,32 @@ func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interf t.FailNow() } +// NotImplements asserts that an object does not implement the specified interface. +// +// assert.NotImplements(t, (*MyInterface)(nil), new(MyObject)) +func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotImplements(t, interfaceObject, object, msgAndArgs...) { + return + } + t.FailNow() +} + +// NotImplementsf asserts that an object does not implement the specified interface. +// +// assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.NotImplementsf(t, interfaceObject, object, msg, args...) { + return + } + t.FailNow() +} + // NotNil asserts that the specified object is not nil. // // assert.NotNil(t, err) @@ -1658,10 +1681,12 @@ func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, t.FailNow() } -// NotSubset asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubset asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +// assert.NotSubset(t, [1, 3, 4], [1, 2]) +// assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1672,10 +1697,12 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i t.FailNow() } -// NotSubsetf asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubsetf asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") +// assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1880,10 +1907,11 @@ func Samef(t TestingT, expected interface{}, actual interface{}, msg string, arg t.FailNow() } -// Subset asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subset asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +// assert.Subset(t, [1, 2, 3], [1, 2]) +// assert.Subset(t, {"x": 1, "y": 2}, {"x": 1}) func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1894,10 +1922,11 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte t.FailNow() } -// Subsetf asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subsetf asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +// assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") +// assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/require/require_forward.go b/vendor/github.com/stretchr/testify/require/require_forward.go index 3b5b093..eee8310 100644 --- a/vendor/github.com/stretchr/testify/require/require_forward.go +++ b/vendor/github.com/stretchr/testify/require/require_forward.go @@ -1,7 +1,4 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ +// Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT. package require @@ -190,7 +187,7 @@ func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface EqualExportedValuesf(a.t, expected, actual, msg, args...) } -// EqualValues asserts that two objects are equal or convertable to the same types +// EqualValues asserts that two objects are equal or convertible to the same types // and equal. // // a.EqualValues(uint32(123), int32(123)) @@ -201,7 +198,7 @@ func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAn EqualValues(a.t, expected, actual, msgAndArgs...) } -// EqualValuesf asserts that two objects are equal or convertable to the same types +// EqualValuesf asserts that two objects are equal or convertible to the same types // and equal. // // a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted") @@ -1222,6 +1219,26 @@ func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...in NotErrorIsf(a.t, err, target, msg, args...) } +// NotImplements asserts that an object does not implement the specified interface. +// +// a.NotImplements((*MyInterface)(nil), new(MyObject)) +func (a *Assertions) NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotImplements(a.t, interfaceObject, object, msgAndArgs...) +} + +// NotImplementsf asserts that an object does not implement the specified interface. +// +// a.NotImplementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted") +func (a *Assertions) NotImplementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + NotImplementsf(a.t, interfaceObject, object, msg, args...) +} + // NotNil asserts that the specified object is not nil. // // a.NotNil(err) @@ -1310,10 +1327,12 @@ func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg stri NotSamef(a.t, expected, actual, msg, args...) } -// NotSubset asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubset asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") +// a.NotSubset([1, 3, 4], [1, 2]) +// a.NotSubset({"x": 1, "y": 2}, {"z": 3}) func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1321,10 +1340,12 @@ func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs NotSubset(a.t, list, subset, msgAndArgs...) } -// NotSubsetf asserts that the specified list(array, slice...) contains not all -// elements given in the specified subset(array, slice...). +// NotSubsetf asserts that the specified list(array, slice...) or map does NOT +// contain all elements given in the specified subset list(array, slice...) or +// map. // -// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") +// a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted") +// a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1484,10 +1505,11 @@ func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, Samef(a.t, expected, actual, msg, args...) } -// Subset asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subset asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") +// a.Subset([1, 2, 3], [1, 2]) +// a.Subset({"x": 1, "y": 2}, {"x": 1}) func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1495,10 +1517,11 @@ func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ... Subset(a.t, list, subset, msgAndArgs...) } -// Subsetf asserts that the specified list(array, slice...) contains all -// elements given in the specified subset(array, slice...). +// Subsetf asserts that the specified list(array, slice...) or map contains all +// elements given in the specified subset list(array, slice...) or map. // -// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") +// a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted") +// a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.s b/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.s index d2ca5de..b3c1699 100644 --- a/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.s +++ b/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.s @@ -19,15 +19,14 @@ #define POLY1305_MUL(h0, h1, h2, r0, r1, t0, t1, t2, t3, t4, t5) \ MULLD r0, h0, t0; \ - MULLD r0, h1, t4; \ MULHDU r0, h0, t1; \ + MULLD r0, h1, t4; \ MULHDU r0, h1, t5; \ ADDC t4, t1, t1; \ MULLD r0, h2, t2; \ - ADDZE t5; \ MULHDU r1, h0, t4; \ MULLD r1, h0, h0; \ - ADD t5, t2, t2; \ + ADDE t5, t2, t2; \ ADDC h0, t1, t1; \ MULLD h2, r1, t3; \ ADDZE t4, h0; \ @@ -37,13 +36,11 @@ ADDE t5, t3, t3; \ ADDC h0, t2, t2; \ MOVD $-4, t4; \ - MOVD t0, h0; \ - MOVD t1, h1; \ ADDZE t3; \ - ANDCC $3, t2, h2; \ - AND t2, t4, t0; \ + RLDICL $0, t2, $62, h2; \ + AND t2, t4, h0; \ ADDC t0, h0, h0; \ - ADDE t3, h1, h1; \ + ADDE t3, t1, h1; \ SLD $62, t3, t4; \ SRD $2, t2; \ ADDZE h2; \ @@ -75,6 +72,7 @@ TEXT ·update(SB), $0-32 loop: POLY1305_ADD(R4, R8, R9, R10, R20, R21, R22) + PCALIGN $16 multiply: POLY1305_MUL(R8, R9, R10, R11, R12, R16, R17, R18, R14, R20, R21) ADD $-16, R5 diff --git a/vendor/modules.txt b/vendor/modules.txt index 8625541..0e056eb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -36,11 +36,11 @@ github.com/klauspost/compress/zstd/internal/xxhash # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/stretchr/testify v1.8.4 -## explicit; go 1.20 +# github.com/stretchr/testify v1.9.0 +## explicit; go 1.17 github.com/stretchr/testify/assert github.com/stretchr/testify/require -# golang.org/x/crypto v0.19.0 +# golang.org/x/crypto v0.21.0 ## explicit; go 1.18 golang.org/x/crypto/argon2 golang.org/x/crypto/blake2b @@ -58,7 +58,7 @@ golang.org/x/crypto/poly1305 golang.org/x/crypto/salsa20/salsa golang.org/x/crypto/scrypt golang.org/x/crypto/sha3 -# golang.org/x/sys v0.17.0 +# golang.org/x/sys v0.18.0 ## explicit; go 1.18 golang.org/x/sys/cpu # gopkg.in/yaml.v3 v3.0.1