From b129b7cbc9fd9a9c11a77e5922861ef08893efa1 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sat, 8 Jun 2024 20:36:04 -0700 Subject: Convert bespoke methods to io.Reader/io.Writer interfaces --- hotline/account.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'hotline/account.go') diff --git a/hotline/account.go b/hotline/account.go index b041f3c..4c5a9b9 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -3,7 +3,9 @@ package hotline import ( "encoding/binary" "golang.org/x/crypto/bcrypt" + "io" "log" + "slices" ) const GuestAccount = "guest" // default account used when no login is provided for a connection @@ -30,13 +32,12 @@ func (a *Account) Read(p []byte) (n int, err error) { fieldCount := make([]byte, 2) binary.BigEndian.PutUint16(fieldCount, uint16(len(fields))) - p = append(p, fieldCount...) - + var fieldBytes []byte for _, field := range fields { - p = append(p, field.Payload()...) + fieldBytes = append(fieldBytes, field.Payload()...) } - return len(p), nil + return copy(p, slices.Concat(fieldCount, fieldBytes)), io.EOF } // hashAndSalt generates a password hash from a users obfuscated plaintext password -- cgit