0
0
forked from toolshed/abra

build: go 1.24

We were running behind and there were quite some deprecations to update.
This was mostly in the upstream copy/pasta package but seems quite
minimal.
This commit is contained in:
2025-03-16 12:04:32 +01:00
parent a2b678caf6
commit 1723025fbf
822 changed files with 25433 additions and 197407 deletions

View File

@ -5,6 +5,8 @@ import (
"fmt"
"math/big"
"strings"
"golang.org/x/crypto/cryptobyte"
)
// BytesLe2Hex returns an hexadecimal string of a number stored in a
@ -138,3 +140,34 @@ func BigInt2Uint64Le(z []uint64, x *big.Int) {
z[i] = 0
}
}
// MarshalBinary encodes a value into a byte array in a format readable by UnmarshalBinary.
func MarshalBinary(v cryptobyte.MarshalingValue) ([]byte, error) {
const DefaultSize = 32
b := cryptobyte.NewBuilder(make([]byte, 0, DefaultSize))
b.AddValue(v)
return b.Bytes()
}
// MarshalBinaryLen encodes a value into an array of n bytes in a format readable by UnmarshalBinary.
func MarshalBinaryLen(v cryptobyte.MarshalingValue, length uint) ([]byte, error) {
b := cryptobyte.NewFixedBuilder(make([]byte, 0, length))
b.AddValue(v)
return b.Bytes()
}
// A UnmarshalingValue decodes itself from a cryptobyte.String and advances the pointer.
// It reports whether the read was successful.
type UnmarshalingValue interface {
Unmarshal(*cryptobyte.String) bool
}
// UnmarshalBinary recovers a value from a byte array.
// It returns an error if the read was unsuccessful.
func UnmarshalBinary(v UnmarshalingValue, data []byte) (err error) {
s := cryptobyte.String(data)
if data == nil || !v.Unmarshal(&s) || !s.Empty() {
err = fmt.Errorf("cannot read %T from input string", v)
}
return
}