mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
all: use new AppendEncode methods available in Go 1.22 (#11079)
Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
@@ -39,7 +39,7 @@ func ParsePrivateID(in string) (out PrivateID, err error) {
|
||||
}
|
||||
|
||||
func (id PrivateID) AppendText(b []byte) ([]byte, error) {
|
||||
return hexAppendEncode(b, id[:]), nil
|
||||
return hex.AppendEncode(b, id[:]), nil
|
||||
}
|
||||
|
||||
func (id PrivateID) MarshalText() ([]byte, error) {
|
||||
@@ -51,7 +51,7 @@ func (id *PrivateID) UnmarshalText(in []byte) error {
|
||||
}
|
||||
|
||||
func (id PrivateID) String() string {
|
||||
return string(hexAppendEncode(nil, id[:]))
|
||||
return string(hex.AppendEncode(nil, id[:]))
|
||||
}
|
||||
|
||||
func (id PrivateID) IsZero() bool {
|
||||
@@ -75,7 +75,7 @@ func ParsePublicID(in string) (out PublicID, err error) {
|
||||
}
|
||||
|
||||
func (id PublicID) AppendText(b []byte) ([]byte, error) {
|
||||
return hexAppendEncode(b, id[:]), nil
|
||||
return hex.AppendEncode(b, id[:]), nil
|
||||
}
|
||||
|
||||
func (id PublicID) MarshalText() ([]byte, error) {
|
||||
@@ -87,7 +87,7 @@ func (id *PublicID) UnmarshalText(in []byte) error {
|
||||
}
|
||||
|
||||
func (id PublicID) String() string {
|
||||
return string(hexAppendEncode(nil, id[:]))
|
||||
return string(hex.AppendEncode(nil, id[:]))
|
||||
}
|
||||
|
||||
func (id1 PublicID) Less(id2 PublicID) bool {
|
||||
@@ -106,14 +106,6 @@ func (id PublicID) Prefix64() uint64 {
|
||||
return binary.BigEndian.Uint64(id[:8])
|
||||
}
|
||||
|
||||
// TODO(https://go.dev/issue/53693): Use hex.AppendEncode instead.
|
||||
func hexAppendEncode(dst, src []byte) []byte {
|
||||
n := hex.EncodedLen(len(src))
|
||||
dst = slices.Grow(dst, n)
|
||||
hex.Encode(dst[len(dst):][:n], src)
|
||||
return dst[:len(dst)+n]
|
||||
}
|
||||
|
||||
func parseID[Bytes []byte | string](funcName string, out *[32]byte, in Bytes) (err error) {
|
||||
if len(in) != 2*len(out) {
|
||||
return fmt.Errorf("%s: invalid hex length: %d", funcName, len(in))
|
||||
|
Reference in New Issue
Block a user