Skip to content

Commit fcf2c0b

Browse files
committed
BACKUP
Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent 22f5589 commit fcf2c0b

34 files changed

+1585
-1728
lines changed

checksum/checksum.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Checksum struct {
2424

2525
// Type represents the enumeration
2626
// of checksum types.
27-
type Type uint32
27+
type Type int32
2828

2929
const (
3030
Unknown Type = iota // Deprecated: use 0 instead.
@@ -99,6 +99,9 @@ func NewFromData(typ Type, data []byte) (Checksum, error) {
9999
//
100100
// See also [Checksum.ProtoMessage].
101101
func (c *Checksum) FromProtoMessage(m *refs.Checksum) error {
102+
if m.Type < 0 {
103+
return fmt.Errorf("negative type %d", m.Type)
104+
}
102105
if len(m.Sum) == 0 {
103106
return errors.New("missing value")
104107
}

checksum/checksum_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ func TestChecksumDecodingFailures(t *testing.T) {
6363
}
6464

6565
func TestNew(t *testing.T) {
66-
typ := checksum.Type(rand.Uint32())
66+
typ := checksum.Type(rand.Int31())
6767
val := make([]byte, 128)
6868
//nolint:staticcheck
6969
rand.Read(val)
7070
cs := checksum.New(typ, val)
7171
require.Equal(t, typ, cs.Type())
7272
require.Equal(t, val, cs.Value())
7373

74-
otherTyp := checksum.Type(rand.Uint32())
74+
otherTyp := checksum.Type(rand.Int31())
7575
otherVal := make([]byte, 128)
7676
//nolint:staticcheck
7777
rand.Read(otherVal)
@@ -155,7 +155,7 @@ func TestNewFromHash(t *testing.T) {
155155
h.Write([]byte("Hello, world!"))
156156
hb := []byte{32, 94, 4, 138}
157157

158-
typ := checksum.Type(rand.Uint32())
158+
typ := checksum.Type(rand.Int31())
159159
cs := checksum.NewFromHash(typ, h)
160160
require.Equal(t, typ, cs.Type())
161161
require.Equal(t, hb, cs.Value())

0 commit comments

Comments
 (0)