Skip to content

Commit ccd025a

Browse files
patapenka-alexeybigbes
authored andcommitted
integrity: signer and verifier implementation
Closes #TNTP-4171
1 parent 4e1445d commit ccd025a

File tree

9 files changed

+333
-35
lines changed

9 files changed

+333
-35
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ linters:
6565
- "github.com/tarantool/go-option"
6666
- "github.com/vmihailenco/msgpack/v5"
6767
- "github.com/tarantool/go-iproto"
68+
- "gopkg.in/yaml.v3"
6869
test:
6970
files:
7071
- "$test"
@@ -76,3 +77,4 @@ linters:
7677
- "github.com/tarantool/go-iproto"
7778
- "github.com/vmihailenco/msgpack/v5"
7879
- "github.com/gojuno/minimock/v3"
80+
- "gopkg.in/yaml.v3"

crypto/interfaces.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Package crypto implements crypto interfaces.
2+
package crypto
3+
4+
// Signer implements high-level API for package signing.
5+
type Signer interface {
6+
// Name returns name of the crypto algorithm, used by signer.
7+
Name() string
8+
// Sign returns signature for passed data.
9+
Sign(data []byte) ([]byte, error)
10+
}
11+
12+
// Verifier is an interface implementing a generic signature
13+
// verification algorithm.
14+
type Verifier interface {
15+
// Name returns name of the crypto algorithm, used by verifier.
16+
Name() string
17+
// Verify checks data and signature mapping.
18+
Verify(data []byte, signature []byte) error
19+
}
20+
21+
// SignerVerifier common interface.
22+
type SignerVerifier interface {
23+
Signer
24+
Verifier
25+
}

crypto/rsa.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package crypto
2+
3+
import (
4+
"crypto"
5+
"crypto/rand"
6+
"crypto/rsa"
7+
"fmt"
8+
9+
"github.com/tarantool/go-storage/hasher"
10+
)
11+
12+
// RSAPSS represents RSA PSS algo for signing/verification
13+
// (with SHA256 as digest calculation function).
14+
type RSAPSS struct {
15+
publicKey rsa.PublicKey
16+
privateKey rsa.PrivateKey
17+
hash crypto.Hash
18+
hasher hasher.Hasher
19+
}
20+
21+
// NewRSAPSS creates new RSAPSS object.
22+
func NewRSAPSS(privKey rsa.PrivateKey, pubKey rsa.PublicKey) RSAPSS {
23+
return RSAPSS{
24+
publicKey: pubKey,
25+
privateKey: privKey,
26+
hash: crypto.SHA256,
27+
hasher: hasher.NewSHA256Hasher(),
28+
}
29+
}
30+
31+
// Name implements SignerVerifier interface.
32+
func (r *RSAPSS) Name() string {
33+
return "RSASSA-PSS"
34+
}
35+
36+
// Sign generates SHA-256 digest and signs it using RSASSA-PSS.
37+
func (r *RSAPSS) Sign(data []byte) ([]byte, error) {
38+
digest, err := r.hasher.Hash(data)
39+
if err != nil {
40+
return []byte{}, fmt.Errorf("failed to get hash: %w", err)
41+
}
42+
43+
signature, err := rsa.SignPSS(rand.Reader, &r.privateKey, r.hash, digest, &rsa.PSSOptions{
44+
SaltLength: rsa.PSSSaltLengthEqualsHash,
45+
Hash: r.hash,
46+
})
47+
if err != nil {
48+
return nil, fmt.Errorf("failed to sign: %w", err)
49+
}
50+
51+
return signature, nil
52+
}
53+
54+
// Verify compares data with signature.
55+
func (r *RSAPSS) Verify(data []byte, signature []byte) error {
56+
digest, err := r.hasher.Hash(data)
57+
if err != nil {
58+
return fmt.Errorf("failed to get hash: %w", err)
59+
}
60+
61+
err = rsa.VerifyPSS(&r.publicKey, r.hash, digest, signature, &rsa.PSSOptions{
62+
SaltLength: rsa.PSSSaltLengthEqualsHash,
63+
Hash: r.hash,
64+
})
65+
if err != nil {
66+
return fmt.Errorf("failed to verify: %w", err)
67+
}
68+
69+
return nil
70+
}

crypto/rsa_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package crypto_test
2+
3+
import (
4+
"crypto/rand"
5+
"crypto/rsa"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
"github.com/tarantool/go-storage/crypto"
10+
)
11+
12+
func TestRsaWithoutKeys(t *testing.T) {
13+
t.Parallel()
14+
15+
rsapss := crypto.NewRSAPSS(rsa.PrivateKey{}, rsa.PublicKey{}) //nolint:exhaustruct
16+
require.NotNil(t, rsapss, "rsapss must be returned")
17+
18+
data := []byte("abc")
19+
20+
sig, err := rsapss.Sign(data)
21+
require.ErrorContains(t, err, "failed to sign: crypto/rsa: missing public modulus")
22+
require.Nil(t, sig, "signature must be nil")
23+
24+
err = rsapss.Verify(data, sig)
25+
require.ErrorContains(t, err, "failed to verify: crypto/rsa: missing public modulus")
26+
}
27+
28+
func TestRsaOnlyPrivateKey(t *testing.T) {
29+
t.Parallel()
30+
31+
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
32+
require.NoError(t, err)
33+
34+
rsapss := crypto.NewRSAPSS(*privateKey, rsa.PublicKey{}) //nolint:exhaustruct
35+
require.NotNil(t, rsapss, "rsapss must be returned")
36+
37+
data := []byte("abc")
38+
39+
sig, err := rsapss.Sign(data)
40+
require.NoError(t, err, "Sign must be successful")
41+
require.NotNil(t, sig, "signature must be returned")
42+
43+
err = rsapss.Verify(data, sig)
44+
require.ErrorContains(t, err, "failed to verify: crypto/rsa: missing public modulus")
45+
}
46+
47+
func TestRsaOnlyPublicKey(t *testing.T) {
48+
t.Parallel()
49+
50+
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
51+
require.NoError(t, err)
52+
53+
rsapss := crypto.NewRSAPSS(rsa.PrivateKey{}, privateKey.PublicKey) //nolint:exhaustruct
54+
require.NotNil(t, rsapss, "rsapss must be returned")
55+
56+
data := []byte("abc")
57+
58+
sig, err := rsapss.Sign(data)
59+
require.ErrorContains(t, err, "failed to sign: crypto/rsa: missing public modulus")
60+
require.Nil(t, sig, "signature must be nil")
61+
62+
// Re-create to have a valid sign.
63+
rsapss = crypto.NewRSAPSS(*privateKey, privateKey.PublicKey)
64+
require.NotNil(t, rsapss, "rsapss must be returned")
65+
66+
sign, err := rsapss.Sign(data)
67+
require.NoError(t, err)
68+
require.NotNil(t, sign)
69+
70+
err = rsapss.Verify(data, sign)
71+
require.NoError(t, err, "Verify must be successful")
72+
}
73+
74+
func TestRsaSignVerify(t *testing.T) {
75+
t.Parallel()
76+
77+
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
78+
require.NoError(t, err)
79+
80+
rsapss := crypto.NewRSAPSS(*privateKey, privateKey.PublicKey)
81+
require.NotNil(t, rsapss, "rsapss must be returned")
82+
83+
data := []byte("abc")
84+
85+
sig, err := rsapss.Sign(data)
86+
require.NoError(t, err, "Sign must be successful")
87+
require.NotNil(t, sig, "signature must be returned")
88+
89+
err = rsapss.Verify(data, sig)
90+
require.NoError(t, err, "Verify must be successful")
91+
}

go.mod

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ go 1.24.0
55
require (
66
github.com/gojuno/minimock/v3 v3.4.7
77
github.com/stretchr/testify v1.11.1
8+
github.com/tarantool/go-iproto v1.1.0
89
github.com/tarantool/go-option v1.0.0
9-
github.com/tarantool/go-tarantool/v2 v2.4.0
10+
github.com/tarantool/go-tarantool/v2 v2.4.1
1011
github.com/vmihailenco/msgpack/v5 v5.4.1
1112
go.etcd.io/etcd/client/v3 v3.6.5
13+
gopkg.in/yaml.v3 v3.0.1
1214
)
1315

1416
require (
@@ -17,27 +19,25 @@ require (
1719
github.com/davecgh/go-spew v1.1.1 // indirect
1820
github.com/gogo/protobuf v1.3.2 // indirect
1921
github.com/golang/protobuf v1.5.4 // indirect
20-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
22+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
2123
github.com/hexdigest/gowrap v1.4.3 // indirect
2224
github.com/pkg/errors v0.9.1 // indirect
2325
github.com/pmezard/go-difflib v1.0.0 // indirect
24-
github.com/tarantool/go-iproto v1.1.0 // indirect
2526
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
2627
go.etcd.io/etcd/api/v3 v3.6.5 // indirect
2728
go.etcd.io/etcd/client/pkg/v3 v3.6.5 // indirect
2829
go.uber.org/multierr v1.11.0 // indirect
2930
go.uber.org/zap v1.27.0 // indirect
30-
golang.org/x/mod v0.27.0 // indirect
31-
golang.org/x/net v0.44.0 // indirect
31+
golang.org/x/mod v0.28.0 // indirect
32+
golang.org/x/net v0.46.0 // indirect
3233
golang.org/x/sync v0.17.0 // indirect
33-
golang.org/x/sys v0.36.0 // indirect
34-
golang.org/x/text v0.29.0 // indirect
35-
golang.org/x/tools v0.36.0 // indirect
36-
google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 // indirect
37-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect
38-
google.golang.org/grpc v1.75.1 // indirect
39-
google.golang.org/protobuf v1.36.9 // indirect
40-
gopkg.in/yaml.v3 v3.0.1 // indirect
34+
golang.org/x/sys v0.38.0 // indirect
35+
golang.org/x/text v0.30.0 // indirect
36+
golang.org/x/tools v0.37.0 // indirect
37+
google.golang.org/genproto/googleapis/api v0.0.0-20251110190251-83f479183930 // indirect
38+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251110190251-83f479183930 // indirect
39+
google.golang.org/grpc v1.76.0 // indirect
40+
google.golang.org/protobuf v1.36.10 // indirect
4141
)
4242

4343
tool github.com/gojuno/minimock/v3/cmd/minimock

go.sum

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1818
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1919
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2020
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
21-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
22-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
21+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
22+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
2323
github.com/hexdigest/gowrap v1.4.3 h1:m+t8aj1pUiFQbEiE8QJg2xdYVH5DAMluLgZ9P/qEF0k=
2424
github.com/hexdigest/gowrap v1.4.3/go.mod h1:XWL8oQW2H3fX5ll8oT3Fduh4mt2H3cUAGQHQLMUbmG4=
2525
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -40,8 +40,8 @@ github.com/tarantool/go-iproto v1.1.0 h1:HULVOIHsiehI+FnHfM7wMDntuzUddO09DKqu2Wn
4040
github.com/tarantool/go-iproto v1.1.0/go.mod h1:LNCtdyZxojUed8SbOiYHoc3v9NvaZTB7p96hUySMlIo=
4141
github.com/tarantool/go-option v1.0.0 h1:+Etw0i3TjsXvADTo5rfZNCfsXe3BfHOs+iVfIrl0Nlo=
4242
github.com/tarantool/go-option v1.0.0/go.mod h1:lXzzeZtL+rPUtLOCDP6ny3FemFBjruG9aHKzNN2bS08=
43-
github.com/tarantool/go-tarantool/v2 v2.4.0 h1:cfGngxdknpVVbd/vF2LvaoWsKjsLV9i3xC859XgsJlI=
44-
github.com/tarantool/go-tarantool/v2 v2.4.0/go.mod h1:MTbhdjFc3Jl63Lgi/UJr5D+QbT+QegqOzsNJGmaw7VM=
43+
github.com/tarantool/go-tarantool/v2 v2.4.1 h1:Bk9mh+gMPVmHTSefHvVBpEkf6P2UZA/8xa5kqgyQtyo=
44+
github.com/tarantool/go-tarantool/v2 v2.4.1/go.mod h1:MTbhdjFc3Jl63Lgi/UJr5D+QbT+QegqOzsNJGmaw7VM=
4545
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
4646
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
4747
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
@@ -77,14 +77,14 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
7777
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
7878
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
7979
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
80-
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
81-
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
80+
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
81+
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
8282
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
8383
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8484
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8585
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
86-
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
87-
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
86+
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
87+
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
8888
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8989
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9090
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -93,32 +93,32 @@ golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
9393
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
9494
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9595
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
96-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
97-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
96+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
97+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
9898
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
9999
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
100-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
101-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
100+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
101+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
102102
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
103103
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
104104
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
105105
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
106-
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
107-
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
106+
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
107+
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
108108
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
109109
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
110110
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
111111
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
112112
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
113113
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
114-
google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 h1:jm6v6kMRpTYKxBRrDkYAitNJegUeO1Mf3Kt80obv0gg=
115-
google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9/go.mod h1:LmwNphe5Afor5V3R5BppOULHOnt2mCIf+NxMd4XiygE=
116-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 h1:V1jCN2HBa8sySkR5vLcCSqJSTMv093Rw9EJefhQGP7M=
117-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9/go.mod h1:HSkG/KdJWusxU1F6CNrwNDjBMgisKxGnc5dAZfT0mjQ=
118-
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
119-
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
120-
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
121-
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
114+
google.golang.org/genproto/googleapis/api v0.0.0-20251110190251-83f479183930 h1:8BWFtrvJRbplrKV5VHlIm4YM726eeBPPAL2QDNWhRrU=
115+
google.golang.org/genproto/googleapis/api v0.0.0-20251110190251-83f479183930/go.mod h1:G5IanEx8/PgI9w6CFcYQf7jMtHQhZruvfM1i3qOqk5U=
116+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251110190251-83f479183930 h1:tK4fkUnnRhig9TsTp4otV1FxwBFYgbKUq1RY0V6KZ4U=
117+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251110190251-83f479183930/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
118+
google.golang.org/grpc v1.76.0 h1:UnVkv1+uMLYXoIz6o7chp59WfQUYA2ex/BXQ9rHZu7A=
119+
google.golang.org/grpc v1.76.0/go.mod h1:Ju12QI8M6iQJtbcsV+awF5a4hfJMLi4X0JLo94ULZ6c=
120+
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
121+
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
122122
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
123123
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
124124
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

hasher/hasher.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func (h *sha256Hasher) Hash(data []byte) ([]byte, error) {
4141
return nil, ErrDataIsNil
4242
}
4343

44+
h.hash.Reset()
45+
4446
n, err := h.hash.Write(data)
4547
if n < len(data) || err != nil {
4648
return nil, fmt.Errorf("failed to write data: %w", err)
@@ -71,6 +73,8 @@ func (h *sha1Hasher) Hash(data []byte) ([]byte, error) {
7173
return nil, ErrDataIsNil
7274
}
7375

76+
h.hash.Reset()
77+
7478
n, err := h.hash.Write(data)
7579
if n < len(data) || err != nil {
7680
return nil, fmt.Errorf("failed to write data: %w", err)

0 commit comments

Comments
 (0)