diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-06-08 20:36:04 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-06-09 14:05:15 -0700 |
| commit | b129b7cbc9fd9a9c11a77e5922861ef08893efa1 (patch) | |
| tree | 1e3687d1c96fb54bcac1d9c13cdac4297976a758 /hotline/account.go | |
| parent | 9c44621ee1ca9abfca79c593e80193afd9204c83 (diff) | |
Convert bespoke methods to io.Reader/io.Writer interfaces
Diffstat (limited to 'hotline/account.go')
| -rw-r--r-- | hotline/account.go | 9 |
1 files changed, 5 insertions, 4 deletions
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 |