From ab6eefbe9d962c0d2ad0adf5cd041ff63422e454 Mon Sep 17 00:00:00 2001 From: Kuba Date: Wed, 22 May 2024 12:51:05 +0200 Subject: [PATCH 1/3] feat(BUMP): implementation of NewBUMPFromStream that returns bytes used --- bump.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bump.go b/bump.go index afb90f5..beffd10 100644 --- a/bump.go +++ b/bump.go @@ -28,10 +28,12 @@ type leaf struct { Duplicate *bool `json:"duplicate,omitempty"` } -// NewBUMPFromBytes creates a new BUMP from a byte slice. -func NewBUMPFromBytes(bytes []byte) (*BUMP, error) { +// NewBUMPFromStream takes an array of bytes and contructs a BUMP from it, returning the BUMP +// and the bytes used. Despite the name, this is not actually reading a stream in the true sense: +// it is a byte slice that contains many BUMPs one after another. +func NewBUMPFromStream(bytes []byte) (*BUMP, int, error) { if len(bytes) < 37 { - return nil, errors.New("BUMP bytes do not contain enough data to be valid") + return nil, 0, errors.New("BUMP bytes do not contain enough data to be valid") } bump := &BUMP{} @@ -54,7 +56,7 @@ func NewBUMPFromBytes(bytes []byte) (*BUMP, error) { skip += size nLeavesAtThisHeight := uint64(n) if nLeavesAtThisHeight == 0 { - return nil, errors.New("There are no leaves at height: " + fmt.Sprint(lv) + " which makes this invalid") + return nil, 0, errors.New("There are no leaves at height: " + fmt.Sprint(lv) + " which makes this invalid") } bump.Path[lv] = make([]leaf, nLeavesAtThisHeight) for lf := uint64(0); lf < nLeavesAtThisHeight; lf++ { @@ -72,7 +74,7 @@ func NewBUMPFromBytes(bytes []byte) (*BUMP, error) { l.Duplicate = &dup } else { if len(bytes) < skip+32 { - return nil, errors.New("BUMP bytes do not contain enough data to be valid") + return nil, 0, errors.New("BUMP bytes do not contain enough data to be valid") } h := StringFromBytesReverse(bytes[skip : skip+32]) l.Hash = &h @@ -92,6 +94,15 @@ func NewBUMPFromBytes(bytes []byte) (*BUMP, error) { }) } + return bump, skip, nil +} + +// NewBUMPFromBytes creates a new BUMP from a byte slice. +func NewBUMPFromBytes(bytes []byte) (*BUMP, error) { + bump, _, err := NewBUMPFromStream(bytes) + if err != nil { + return nil, err + } return bump, nil } From c480147b3286270ecde35d6eefbb008894b53007 Mon Sep 17 00:00:00 2001 From: Kuba Date: Fri, 24 May 2024 10:52:36 +0200 Subject: [PATCH 2/3] feat(golint-ci): remove depricated and faulty linter --- .golangci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 569bc51..21782b1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -239,9 +239,6 @@ linters-settings: line-length: 150 # tab width in spaces. Default to 1. tab-width: 1 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. From 8f5ad17e5a445c12e13a31bc29bac94f91e89f94 Mon Sep 17 00:00:00 2001 From: Kuba Date: Fri, 24 May 2024 11:00:28 +0200 Subject: [PATCH 3/3] feat: now properly remove linter --- .golangci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 21782b1..707752c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -336,7 +336,6 @@ linters: - revive - unconvert - dupl - - maligned - misspell - dogsled - prealloc @@ -385,7 +384,6 @@ issues: - goconst - dupl - gosec - - maligned - lll # Exclude known linters from partially hard-vendored code,