@@ -27,6 +27,7 @@ import (
27
27
"errors"
28
28
"fmt"
29
29
"hash"
30
+ "slices"
30
31
31
32
"github.com/ethereum/go-ethereum/common/mclock"
32
33
"github.com/ethereum/go-ethereum/p2p/enode"
@@ -222,7 +223,7 @@ func (c *Codec) Encode(id enode.ID, addr string, packet Packet, challenge *Whoar
222
223
223
224
// Store sent WHOAREYOU challenges.
224
225
if challenge , ok := packet .(* Whoareyou ); ok {
225
- challenge .ChallengeData = bytesCopy ( & c .buf )
226
+ challenge .ChallengeData = slices . Clone ( c .buf . Bytes () )
226
227
enc , err := c .EncodeRaw (id , head , msgData )
227
228
if err != nil {
228
229
return nil , Nonce {}, err
@@ -325,7 +326,7 @@ func (c *Codec) encodeWhoareyou(toID enode.ID, packet *Whoareyou) (Header, error
325
326
326
327
// Create header.
327
328
head := c .makeHeader (toID , flagWhoareyou , 0 )
328
- head .AuthData = bytesCopy ( & c .buf )
329
+ head .AuthData = slices . Clone ( c .buf . Bytes () )
329
330
head .Nonce = packet .Nonce
330
331
331
332
// Encode auth data.
@@ -430,7 +431,7 @@ func (c *Codec) encodeMessageHeader(toID enode.ID, s *session) (Header, error) {
430
431
auth := messageAuthData {SrcID : c .localnode .ID ()}
431
432
c .buf .Reset ()
432
433
binary .Write (& c .buf , binary .BigEndian , & auth )
433
- head .AuthData = bytesCopy ( & c .buf )
434
+ head .AuthData = slices . Clone ( c .buf . Bytes () )
434
435
head .Nonce = nonce
435
436
return head , err
436
437
}
@@ -686,9 +687,3 @@ func (h *Header) mask(destID enode.ID) cipher.Stream {
686
687
}
687
688
return cipher .NewCTR (block , h .IV [:])
688
689
}
689
-
690
- func bytesCopy (r * bytes.Buffer ) []byte {
691
- b := make ([]byte , r .Len ())
692
- copy (b , r .Bytes ())
693
- return b
694
- }
0 commit comments