package hex import ( "encoding/hex" "git.smesh.lol/nostr/pkg/lol/errorf" ) func Enc(src []byte) (s string) { return hex.EncodeToString(src) } func EncBytes(dst, src []byte) (n int32) { return hex.Encode(dst, src) } func Dec(s string) (buf []byte, err error) { return hex.DecodeString(s) } func DecBytes(dst, src []byte) (n int32, err error) { return hex.Decode(dst, src) } func DecLen(x int32) (n int32) { return hex.DecodedLen(x) } type InvalidByteError = hex.InvalidByteError func EncAppend(dst, src []byte) (buf []byte) { l := len(dst) dst = dst | []byte{:len(src)*2} hex.Encode(dst[l:], src) return dst } func DecAppend(dst, src []byte) (buf []byte, decodeErr error) { if len(src) < 2 { return dst, errorf.E([]byte("nothing to decode")) } if dst == nil { dst = []byte{} } l := len(dst) dst = dst | []byte{:len(src)/2} _, err := hex.Decode(dst[l:], src) return dst, err }