database: Use bytes.Clone instead of manual copy.

bytes.Clone was introduced in go 1.20 and removes the need to manually
copy byte slices.
This commit is contained in:
Jamie Holdstock 2024-02-15 18:20:28 +08:00 committed by Jamie Holdstock
parent 6a72321ddb
commit cdd02dbd2e
2 changed files with 5 additions and 6 deletions

View File

@ -1,10 +1,11 @@
// Copyright (c) 2020-2023 The Decred developers // Copyright (c) 2020-2024 The Decred developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package database package database
import ( import (
"bytes"
"crypto/ed25519" "crypto/ed25519"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
@ -285,8 +286,7 @@ func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error)
// Byte slices returned from Bolt are only valid during a transaction. // Byte slices returned from Bolt are only valid during a transaction.
// Need to make a copy. // Need to make a copy.
seed = make([]byte, len(s)) seed = bytes.Clone(s)
copy(seed, s)
if seed == nil { if seed == nil {
// should not happen // should not happen
@ -341,8 +341,7 @@ func (vdb *VspDatabase) CookieSecret() ([]byte, error) {
// Byte slices returned from Bolt are only valid during a transaction. // Byte slices returned from Bolt are only valid during a transaction.
// Need to make a copy. // Need to make a copy.
cookieSecret = make([]byte, len(cs)) cookieSecret = bytes.Clone(cs)
copy(cookieSecret, cs)
return nil return nil
}) })

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/decred/vspd module github.com/decred/vspd
go 1.19 go 1.20
require ( require (
decred.org/dcrwallet/v3 v3.1.0 decred.org/dcrwallet/v3 v3.1.0