Skip to content

Commit

Permalink
BACKUP
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 12, 2024
1 parent 22f5589 commit fcf2c0b
Show file tree
Hide file tree
Showing 34 changed files with 1,585 additions and 1,728 deletions.
5 changes: 4 additions & 1 deletion checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Checksum struct {

// Type represents the enumeration
// of checksum types.
type Type uint32
type Type int32

const (
Unknown Type = iota // Deprecated: use 0 instead.
Expand Down Expand Up @@ -99,6 +99,9 @@ func NewFromData(typ Type, data []byte) (Checksum, error) {
//
// See also [Checksum.ProtoMessage].
func (c *Checksum) FromProtoMessage(m *refs.Checksum) error {
if m.Type < 0 {
return fmt.Errorf("negative type %d", m.Type)
}
if len(m.Sum) == 0 {
return errors.New("missing value")
}
Expand Down
6 changes: 3 additions & 3 deletions checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func TestChecksumDecodingFailures(t *testing.T) {
}

func TestNew(t *testing.T) {
typ := checksum.Type(rand.Uint32())
typ := checksum.Type(rand.Int31())
val := make([]byte, 128)
//nolint:staticcheck
rand.Read(val)
cs := checksum.New(typ, val)
require.Equal(t, typ, cs.Type())
require.Equal(t, val, cs.Value())

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

typ := checksum.Type(rand.Uint32())
typ := checksum.Type(rand.Int31())
cs := checksum.NewFromHash(typ, h)
require.Equal(t, typ, cs.Type())
require.Equal(t, hb, cs.Value())
Expand Down
Loading

0 comments on commit fcf2c0b

Please sign in to comment.