]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/account.go
Convert bespoke methods to io.Reader/io.Writer interfaces
[rbdr/mobius] / hotline / account.go
index b041f3cd6c4eb025381d961285eb3bacd7aefddf..4c5a9b98a608810047a8830b01495973be172bda 100644 (file)
@@ -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