mirror of https://github.com/ethereum/go-ethereum
p2p/discover: move discv4 encoding to new 'v4wire' package (#21147)
This moves all v4 protocol definitions to a new package, p2p/discover/v4wire. The new package will be used for low-level protocol tests.pull/21160/head
parent
cd57d5cd38
commit
723bd8c17f
@ -0,0 +1,300 @@ |
||||
// Copyright 2019 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package v4wire implements the Discovery v4 Wire Protocol.
|
||||
package v4wire |
||||
|
||||
import ( |
||||
"bytes" |
||||
"crypto/ecdsa" |
||||
"crypto/elliptic" |
||||
"errors" |
||||
"fmt" |
||||
"math/big" |
||||
"net" |
||||
"time" |
||||
|
||||
"github.com/ethereum/go-ethereum/common/math" |
||||
"github.com/ethereum/go-ethereum/crypto" |
||||
"github.com/ethereum/go-ethereum/p2p/enode" |
||||
"github.com/ethereum/go-ethereum/p2p/enr" |
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
) |
||||
|
||||
// RPC packet types
|
||||
const ( |
||||
PingPacket = iota + 1 // zero is 'reserved'
|
||||
PongPacket |
||||
FindnodePacket |
||||
NeighborsPacket |
||||
ENRRequestPacket |
||||
ENRResponsePacket |
||||
) |
||||
|
||||
// RPC request structures
|
||||
type ( |
||||
Ping struct { |
||||
Version uint |
||||
From, To Endpoint |
||||
Expiration uint64 |
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
|
||||
// Pong is the reply to ping.
|
||||
Pong struct { |
||||
// This field should mirror the UDP envelope address
|
||||
// of the ping packet, which provides a way to discover the
|
||||
// the external address (after NAT).
|
||||
To Endpoint |
||||
ReplyTok []byte // This contains the hash of the ping packet.
|
||||
Expiration uint64 // Absolute timestamp at which the packet becomes invalid.
|
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
|
||||
// Findnode is a query for nodes close to the given target.
|
||||
Findnode struct { |
||||
Target Pubkey |
||||
Expiration uint64 |
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
|
||||
// Neighbors is the reply to findnode.
|
||||
Neighbors struct { |
||||
Nodes []Node |
||||
Expiration uint64 |
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
|
||||
// enrRequest queries for the remote node's record.
|
||||
ENRRequest struct { |
||||
Expiration uint64 |
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
|
||||
// enrResponse is the reply to enrRequest.
|
||||
ENRResponse struct { |
||||
ReplyTok []byte // Hash of the enrRequest packet.
|
||||
Record enr.Record |
||||
// Ignore additional fields (for forward compatibility).
|
||||
Rest []rlp.RawValue `rlp:"tail"` |
||||
} |
||||
) |
||||
|
||||
// This number is the maximum number of neighbor nodes in a Neigbors packet.
|
||||
const MaxNeighbors = 12 |
||||
|
||||
// This code computes the MaxNeighbors constant value.
|
||||
|
||||
// func init() {
|
||||
// var maxNeighbors int
|
||||
// p := Neighbors{Expiration: ^uint64(0)}
|
||||
// maxSizeNode := Node{IP: make(net.IP, 16), UDP: ^uint16(0), TCP: ^uint16(0)}
|
||||
// for n := 0; ; n++ {
|
||||
// p.Nodes = append(p.Nodes, maxSizeNode)
|
||||
// size, _, err := rlp.EncodeToReader(p)
|
||||
// if err != nil {
|
||||
// // If this ever happens, it will be caught by the unit tests.
|
||||
// panic("cannot encode: " + err.Error())
|
||||
// }
|
||||
// if headSize+size+1 >= 1280 {
|
||||
// maxNeighbors = n
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// fmt.Println("maxNeighbors", maxNeighbors)
|
||||
// }
|
||||
|
||||
// Pubkey represents an encoded 64-byte secp256k1 public key.
|
||||
type Pubkey [64]byte |
||||
|
||||
// ID returns the node ID corresponding to the public key.
|
||||
func (e Pubkey) ID() enode.ID { |
||||
return enode.ID(crypto.Keccak256Hash(e[:])) |
||||
} |
||||
|
||||
// Node represents information about a node.
|
||||
type Node struct { |
||||
IP net.IP // len 4 for IPv4 or 16 for IPv6
|
||||
UDP uint16 // for discovery protocol
|
||||
TCP uint16 // for RLPx protocol
|
||||
ID Pubkey |
||||
} |
||||
|
||||
// Endpoint represents a network endpoint.
|
||||
type Endpoint struct { |
||||
IP net.IP // len 4 for IPv4 or 16 for IPv6
|
||||
UDP uint16 // for discovery protocol
|
||||
TCP uint16 // for RLPx protocol
|
||||
} |
||||
|
||||
// NewEndpoint creates an endpoint.
|
||||
func NewEndpoint(addr *net.UDPAddr, tcpPort uint16) Endpoint { |
||||
ip := net.IP{} |
||||
if ip4 := addr.IP.To4(); ip4 != nil { |
||||
ip = ip4 |
||||
} else if ip6 := addr.IP.To16(); ip6 != nil { |
||||
ip = ip6 |
||||
} |
||||
return Endpoint{IP: ip, UDP: uint16(addr.Port), TCP: tcpPort} |
||||
} |
||||
|
||||
type Packet interface { |
||||
// packet name and type for logging purposes.
|
||||
Name() string |
||||
Kind() byte |
||||
} |
||||
|
||||
func (req *Ping) Name() string { return "PING/v4" } |
||||
func (req *Ping) Kind() byte { return PingPacket } |
||||
func (req *Ping) ENRSeq() uint64 { return seqFromTail(req.Rest) } |
||||
|
||||
func (req *Pong) Name() string { return "PONG/v4" } |
||||
func (req *Pong) Kind() byte { return PongPacket } |
||||
func (req *Pong) ENRSeq() uint64 { return seqFromTail(req.Rest) } |
||||
|
||||
func (req *Findnode) Name() string { return "FINDNODE/v4" } |
||||
func (req *Findnode) Kind() byte { return FindnodePacket } |
||||
|
||||
func (req *Neighbors) Name() string { return "NEIGHBORS/v4" } |
||||
func (req *Neighbors) Kind() byte { return NeighborsPacket } |
||||
|
||||
func (req *ENRRequest) Name() string { return "ENRREQUEST/v4" } |
||||
func (req *ENRRequest) Kind() byte { return ENRRequestPacket } |
||||
|
||||
func (req *ENRResponse) Name() string { return "ENRRESPONSE/v4" } |
||||
func (req *ENRResponse) Kind() byte { return ENRResponsePacket } |
||||
|
||||
// Expired checks whether the given UNIX time stamp is in the past.
|
||||
func Expired(ts uint64) bool { |
||||
return time.Unix(int64(ts), 0).Before(time.Now()) |
||||
} |
||||
|
||||
func seqFromTail(tail []rlp.RawValue) uint64 { |
||||
if len(tail) == 0 { |
||||
return 0 |
||||
} |
||||
var seq uint64 |
||||
rlp.DecodeBytes(tail[0], &seq) |
||||
return seq |
||||
} |
||||
|
||||
// Encoder/decoder.
|
||||
|
||||
const ( |
||||
macSize = 32 |
||||
sigSize = crypto.SignatureLength |
||||
headSize = macSize + sigSize // space of packet frame data
|
||||
) |
||||
|
||||
var ( |
||||
ErrPacketTooSmall = errors.New("too small") |
||||
ErrBadHash = errors.New("bad hash") |
||||
ErrBadPoint = errors.New("invalid curve point") |
||||
) |
||||
|
||||
var headSpace = make([]byte, headSize) |
||||
|
||||
// Decode reads a discovery v4 packet.
|
||||
func Decode(input []byte) (Packet, Pubkey, []byte, error) { |
||||
if len(input) < headSize+1 { |
||||
return nil, Pubkey{}, nil, ErrPacketTooSmall |
||||
} |
||||
hash, sig, sigdata := input[:macSize], input[macSize:headSize], input[headSize:] |
||||
shouldhash := crypto.Keccak256(input[macSize:]) |
||||
if !bytes.Equal(hash, shouldhash) { |
||||
return nil, Pubkey{}, nil, ErrBadHash |
||||
} |
||||
fromKey, err := recoverNodeKey(crypto.Keccak256(input[headSize:]), sig) |
||||
if err != nil { |
||||
return nil, fromKey, hash, err |
||||
} |
||||
|
||||
var req Packet |
||||
switch ptype := sigdata[0]; ptype { |
||||
case PingPacket: |
||||
req = new(Ping) |
||||
case PongPacket: |
||||
req = new(Pong) |
||||
case FindnodePacket: |
||||
req = new(Findnode) |
||||
case NeighborsPacket: |
||||
req = new(Neighbors) |
||||
case ENRRequestPacket: |
||||
req = new(ENRRequest) |
||||
case ENRResponsePacket: |
||||
req = new(ENRResponse) |
||||
default: |
||||
return nil, fromKey, hash, fmt.Errorf("unknown type: %d", ptype) |
||||
} |
||||
s := rlp.NewStream(bytes.NewReader(sigdata[1:]), 0) |
||||
err = s.Decode(req) |
||||
return req, fromKey, hash, err |
||||
} |
||||
|
||||
// Encode encodes a discovery packet.
|
||||
func Encode(priv *ecdsa.PrivateKey, req Packet) (packet, hash []byte, err error) { |
||||
b := new(bytes.Buffer) |
||||
b.Write(headSpace) |
||||
b.WriteByte(req.Kind()) |
||||
if err := rlp.Encode(b, req); err != nil { |
||||
return nil, nil, err |
||||
} |
||||
packet = b.Bytes() |
||||
sig, err := crypto.Sign(crypto.Keccak256(packet[headSize:]), priv) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
copy(packet[macSize:], sig) |
||||
// Add the hash to the front. Note: this doesn't protect the packet in any way.
|
||||
hash = crypto.Keccak256(packet[macSize:]) |
||||
copy(packet, hash) |
||||
return packet, hash, nil |
||||
} |
||||
|
||||
// recoverNodeKey computes the public key used to sign the given hash from the signature.
|
||||
func recoverNodeKey(hash, sig []byte) (key Pubkey, err error) { |
||||
pubkey, err := crypto.Ecrecover(hash, sig) |
||||
if err != nil { |
||||
return key, err |
||||
} |
||||
copy(key[:], pubkey[1:]) |
||||
return key, nil |
||||
} |
||||
|
||||
// EncodePubkey encodes a secp256k1 public key.
|
||||
func EncodePubkey(key *ecdsa.PublicKey) Pubkey { |
||||
var e Pubkey |
||||
math.ReadBits(key.X, e[:len(e)/2]) |
||||
math.ReadBits(key.Y, e[len(e)/2:]) |
||||
return e |
||||
} |
||||
|
||||
// DecodePubkey reads an encoded secp256k1 public key.
|
||||
func DecodePubkey(curve elliptic.Curve, e Pubkey) (*ecdsa.PublicKey, error) { |
||||
p := &ecdsa.PublicKey{Curve: curve, X: new(big.Int), Y: new(big.Int)} |
||||
half := len(e) / 2 |
||||
p.X.SetBytes(e[:half]) |
||||
p.Y.SetBytes(e[half:]) |
||||
if !p.Curve.IsOnCurve(p.X, p.Y) { |
||||
return nil, ErrBadPoint |
||||
} |
||||
return p, nil |
||||
} |
@ -0,0 +1,152 @@ |
||||
// Copyright 2019 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package v4wire |
||||
|
||||
import ( |
||||
"encoding/hex" |
||||
"net" |
||||
"reflect" |
||||
"testing" |
||||
|
||||
"github.com/davecgh/go-spew/spew" |
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/crypto" |
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
) |
||||
|
||||
// EIP-8 test vectors.
|
||||
var testPackets = []struct { |
||||
input string |
||||
wantPacket interface{} |
||||
}{ |
||||
{ |
||||
input: "71dbda3a79554728d4f94411e42ee1f8b0d561c10e1e5f5893367948c6a7d70bb87b235fa28a77070271b6c164a2dce8c7e13a5739b53b5e96f2e5acb0e458a02902f5965d55ecbeb2ebb6cabb8b2b232896a36b737666c55265ad0a68412f250001ea04cb847f000001820cfa8215a8d790000000000000000000000000000000018208ae820d058443b9a355", |
||||
wantPacket: &Ping{ |
||||
Version: 4, |
||||
From: Endpoint{net.ParseIP("127.0.0.1").To4(), 3322, 5544}, |
||||
To: Endpoint{net.ParseIP("::1"), 2222, 3333}, |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{}, |
||||
}, |
||||
}, |
||||
{ |
||||
input: "e9614ccfd9fc3e74360018522d30e1419a143407ffcce748de3e22116b7e8dc92ff74788c0b6663aaa3d67d641936511c8f8d6ad8698b820a7cf9e1be7155e9a241f556658c55428ec0563514365799a4be2be5a685a80971ddcfa80cb422cdd0101ec04cb847f000001820cfa8215a8d790000000000000000000000000000000018208ae820d058443b9a3550102", |
||||
wantPacket: &Ping{ |
||||
Version: 4, |
||||
From: Endpoint{net.ParseIP("127.0.0.1").To4(), 3322, 5544}, |
||||
To: Endpoint{net.ParseIP("::1"), 2222, 3333}, |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{{0x01}, {0x02}}, |
||||
}, |
||||
}, |
||||
{ |
||||
input: "577be4349c4dd26768081f58de4c6f375a7a22f3f7adda654d1428637412c3d7fe917cadc56d4e5e7ffae1dbe3efffb9849feb71b262de37977e7c7a44e677295680e9e38ab26bee2fcbae207fba3ff3d74069a50b902a82c9903ed37cc993c50001f83e82022bd79020010db83c4d001500000000abcdef12820cfa8215a8d79020010db885a308d313198a2e037073488208ae82823a8443b9a355c5010203040531b9019afde696e582a78fa8d95ea13ce3297d4afb8ba6433e4154caa5ac6431af1b80ba76023fa4090c408f6b4bc3701562c031041d4702971d102c9ab7fa5eed4cd6bab8f7af956f7d565ee1917084a95398b6a21eac920fe3dd1345ec0a7ef39367ee69ddf092cbfe5b93e5e568ebc491983c09c76d922dc3", |
||||
wantPacket: &Ping{ |
||||
Version: 555, |
||||
From: Endpoint{net.ParseIP("2001:db8:3c4d:15::abcd:ef12"), 3322, 5544}, |
||||
To: Endpoint{net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"), 2222, 33338}, |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{{0xC5, 0x01, 0x02, 0x03, 0x04, 0x05}}, |
||||
}, |
||||
}, |
||||
{ |
||||
input: "09b2428d83348d27cdf7064ad9024f526cebc19e4958f0fdad87c15eb598dd61d08423e0bf66b2069869e1724125f820d851c136684082774f870e614d95a2855d000f05d1648b2d5945470bc187c2d2216fbe870f43ed0909009882e176a46b0102f846d79020010db885a308d313198a2e037073488208ae82823aa0fbc914b16819237dcd8801d7e53f69e9719adecb3cc0e790c57e91ca4461c9548443b9a355c6010203c2040506a0c969a58f6f9095004c0177a6b47f451530cab38966a25cca5cb58f055542124e", |
||||
wantPacket: &Pong{ |
||||
To: Endpoint{net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"), 2222, 33338}, |
||||
ReplyTok: common.Hex2Bytes("fbc914b16819237dcd8801d7e53f69e9719adecb3cc0e790c57e91ca4461c954"), |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{{0xC6, 0x01, 0x02, 0x03, 0xC2, 0x04, 0x05}, {0x06}}, |
||||
}, |
||||
}, |
||||
{ |
||||
input: "c7c44041b9f7c7e41934417ebac9a8e1a4c6298f74553f2fcfdcae6ed6fe53163eb3d2b52e39fe91831b8a927bf4fc222c3902202027e5e9eb812195f95d20061ef5cd31d502e47ecb61183f74a504fe04c51e73df81f25c4d506b26db4517490103f84eb840ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31387574077f301b421bc84df7266c44e9e6d569fc56be00812904767bf5ccd1fc7f8443b9a35582999983999999280dc62cc8255c73471e0a61da0c89acdc0e035e260add7fc0c04ad9ebf3919644c91cb247affc82b69bd2ca235c71eab8e49737c937a2c396", |
||||
wantPacket: &Findnode{ |
||||
Target: hexPubkey("ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31387574077f301b421bc84df7266c44e9e6d569fc56be00812904767bf5ccd1fc7f"), |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{{0x82, 0x99, 0x99}, {0x83, 0x99, 0x99, 0x99}}, |
||||
}, |
||||
}, |
||||
{ |
||||
input: "c679fc8fe0b8b12f06577f2e802d34f6fa257e6137a995f6f4cbfc9ee50ed3710faf6e66f932c4c8d81d64343f429651328758b47d3dbc02c4042f0fff6946a50f4a49037a72bb550f3a7872363a83e1b9ee6469856c24eb4ef80b7535bcf99c0004f9015bf90150f84d846321163782115c82115db8403155e1427f85f10a5c9a7755877748041af1bcd8d474ec065eb33df57a97babf54bfd2103575fa829115d224c523596b401065a97f74010610fce76382c0bf32f84984010203040101b840312c55512422cf9b8a4097e9a6ad79402e87a15ae909a4bfefa22398f03d20951933beea1e4dfa6f968212385e829f04c2d314fc2d4e255e0d3bc08792b069dbf8599020010db83c4d001500000000abcdef12820d05820d05b84038643200b172dcfef857492156971f0e6aa2c538d8b74010f8e140811d53b98c765dd2d96126051913f44582e8c199ad7c6d6819e9a56483f637feaac9448aacf8599020010db885a308d313198a2e037073488203e78203e8b8408dcab8618c3253b558d459da53bd8fa68935a719aff8b811197101a4b2b47dd2d47295286fc00cc081bb542d760717d1bdd6bec2c37cd72eca367d6dd3b9df738443b9a355010203b525a138aa34383fec3d2719a0", |
||||
wantPacket: &Neighbors{ |
||||
Nodes: []Node{ |
||||
{ |
||||
ID: hexPubkey("3155e1427f85f10a5c9a7755877748041af1bcd8d474ec065eb33df57a97babf54bfd2103575fa829115d224c523596b401065a97f74010610fce76382c0bf32"), |
||||
IP: net.ParseIP("99.33.22.55").To4(), |
||||
UDP: 4444, |
||||
TCP: 4445, |
||||
}, |
||||
{ |
||||
ID: hexPubkey("312c55512422cf9b8a4097e9a6ad79402e87a15ae909a4bfefa22398f03d20951933beea1e4dfa6f968212385e829f04c2d314fc2d4e255e0d3bc08792b069db"), |
||||
IP: net.ParseIP("1.2.3.4").To4(), |
||||
UDP: 1, |
||||
TCP: 1, |
||||
}, |
||||
{ |
||||
ID: hexPubkey("38643200b172dcfef857492156971f0e6aa2c538d8b74010f8e140811d53b98c765dd2d96126051913f44582e8c199ad7c6d6819e9a56483f637feaac9448aac"), |
||||
IP: net.ParseIP("2001:db8:3c4d:15::abcd:ef12"), |
||||
UDP: 3333, |
||||
TCP: 3333, |
||||
}, |
||||
{ |
||||
ID: hexPubkey("8dcab8618c3253b558d459da53bd8fa68935a719aff8b811197101a4b2b47dd2d47295286fc00cc081bb542d760717d1bdd6bec2c37cd72eca367d6dd3b9df73"), |
||||
IP: net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"), |
||||
UDP: 999, |
||||
TCP: 1000, |
||||
}, |
||||
}, |
||||
Expiration: 1136239445, |
||||
Rest: []rlp.RawValue{{0x01}, {0x02}, {0x03}}, |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
// This test checks that the decoder accepts packets according to EIP-8.
|
||||
func TestForwardCompatibility(t *testing.T) { |
||||
testkey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
||||
wantNodeKey := EncodePubkey(&testkey.PublicKey) |
||||
|
||||
for _, test := range testPackets { |
||||
input, err := hex.DecodeString(test.input) |
||||
if err != nil { |
||||
t.Fatalf("invalid hex: %s", test.input) |
||||
} |
||||
packet, nodekey, _, err := Decode(input) |
||||
if err != nil { |
||||
t.Errorf("did not accept packet %s\n%v", test.input, err) |
||||
continue |
||||
} |
||||
if !reflect.DeepEqual(packet, test.wantPacket) { |
||||
t.Errorf("got %s\nwant %s", spew.Sdump(packet), spew.Sdump(test.wantPacket)) |
||||
} |
||||
if nodekey != wantNodeKey { |
||||
t.Errorf("got id %v\nwant id %v", nodekey, wantNodeKey) |
||||
} |
||||
} |
||||
} |
||||
|
||||
func hexPubkey(h string) (ret Pubkey) { |
||||
b, err := hex.DecodeString(h) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
if len(b) != len(ret) { |
||||
panic("invalid length") |
||||
} |
||||
copy(ret[:], b) |
||||
return ret |
||||
} |
Loading…
Reference in new issue