all: use min/max/clear from go1.21 (#29307)
This commit is contained in:
parent
bca6c40709
commit
14eb8967be
@ -500,7 +500,5 @@ func (ks *KeyStore) isUpdating() bool {
|
|||||||
// zeroKey zeroes a private key in memory.
|
// zeroKey zeroes a private key in memory.
|
||||||
func zeroKey(k *ecdsa.PrivateKey) {
|
func zeroKey(k *ecdsa.PrivateKey) {
|
||||||
b := k.D.Bits()
|
b := k.D.Bits()
|
||||||
for i := range b {
|
clear(b)
|
||||||
b[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -93,9 +93,7 @@ func BenchmarkJumpdestOpAnalysis(bench *testing.B) {
|
|||||||
bits := make(bitvec, len(code)/8+1+4)
|
bits := make(bitvec, len(code)/8+1+4)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for j := range bits {
|
clear(bits)
|
||||||
bits[j] = 0
|
|
||||||
}
|
|
||||||
codeBitmapInternal(code, bits)
|
codeBitmapInternal(code, bits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,5 @@ func PubkeyToAddress(p ecdsa.PublicKey) common.Address {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func zeroBytes(bytes []byte) {
|
func zeroBytes(bytes []byte) {
|
||||||
for i := range bytes {
|
clear(bytes)
|
||||||
bytes[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,8 @@ func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int,
|
|||||||
// Unpack the result and clear temporaries.
|
// Unpack the result and clear temporaries.
|
||||||
x := new(big.Int).SetBytes(point[:32])
|
x := new(big.Int).SetBytes(point[:32])
|
||||||
y := new(big.Int).SetBytes(point[32:])
|
y := new(big.Int).SetBytes(point[32:])
|
||||||
for i := range point {
|
clear(point)
|
||||||
point[i] = 0
|
clear(scalar)
|
||||||
}
|
|
||||||
for i := range padded {
|
|
||||||
scalar[i] = 0
|
|
||||||
}
|
|
||||||
if res != 1 {
|
if res != 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -42,14 +42,6 @@ const (
|
|||||||
maxQueuedTxAnns = 4096
|
maxQueuedTxAnns = 4096
|
||||||
)
|
)
|
||||||
|
|
||||||
// max is a helper function which returns the larger of the two given integers.
|
|
||||||
func max(a, b int) int {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Peer is a collection of relevant information we have about a `eth` peer.
|
// Peer is a collection of relevant information we have about a `eth` peer.
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
id string // Unique ID for the peer, cached
|
id string // Unique ID for the peer, cached
|
||||||
|
@ -229,7 +229,7 @@ func (e *Era) readOffset(n uint64) (int64, error) {
|
|||||||
)
|
)
|
||||||
e.mu.Lock()
|
e.mu.Lock()
|
||||||
defer e.mu.Unlock()
|
defer e.mu.Unlock()
|
||||||
clearBuffer(e.buf[:])
|
clear(e.buf[:])
|
||||||
if _, err := e.f.ReadAt(e.buf[:], offOffset); err != nil {
|
if _, err := e.f.ReadAt(e.buf[:], offOffset); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -248,13 +248,6 @@ func newSnappyReader(e *e2store.Reader, expectedType uint16, off int64) (io.Read
|
|||||||
return snappy.NewReader(r), int64(n), err
|
return snappy.NewReader(r), int64(n), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearBuffer zeroes out the buffer.
|
|
||||||
func clearBuffer(buf []byte) {
|
|
||||||
for i := 0; i < len(buf); i++ {
|
|
||||||
buf[i] = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// metadata wraps the metadata in the block index.
|
// metadata wraps the metadata in the block index.
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
start uint64
|
start uint64
|
||||||
|
@ -87,13 +87,6 @@ func BenchmarkUniformSample1028(b *testing.B) {
|
|||||||
benchmarkSample(b, NewUniformSample(1028))
|
benchmarkSample(b, NewUniformSample(1028))
|
||||||
}
|
}
|
||||||
|
|
||||||
func min(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExpDecaySample(t *testing.T) {
|
func TestExpDecaySample(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
reservoirSize int
|
reservoirSize int
|
||||||
|
@ -92,10 +92,3 @@ type ReadPacket struct {
|
|||||||
Data []byte
|
Data []byte
|
||||||
Addr *net.UDPAddr
|
Addr *net.UDPAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func min(x, y int) int {
|
|
||||||
if x > y {
|
|
||||||
return y
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
@ -129,9 +129,7 @@ func deriveKeys(hash hashFn, priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, n1, n
|
|||||||
sec := session{writeKey: make([]byte, aesKeySize), readKey: make([]byte, aesKeySize)}
|
sec := session{writeKey: make([]byte, aesKeySize), readKey: make([]byte, aesKeySize)}
|
||||||
kdf.Read(sec.writeKey)
|
kdf.Read(sec.writeKey)
|
||||||
kdf.Read(sec.readKey)
|
kdf.Read(sec.readKey)
|
||||||
for i := range eph {
|
clear(eph)
|
||||||
eph[i] = 0
|
|
||||||
}
|
|
||||||
return &sec
|
return &sec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1105,9 +1105,7 @@ func (s *Stream) readUint(size byte) (uint64, error) {
|
|||||||
return uint64(b), err
|
return uint64(b), err
|
||||||
default:
|
default:
|
||||||
buffer := s.uintbuf[:8]
|
buffer := s.uintbuf[:8]
|
||||||
for i := range buffer {
|
clear(buffer)
|
||||||
buffer[i] = 0
|
|
||||||
}
|
|
||||||
start := int(8 - size)
|
start := int(8 - size)
|
||||||
if err := s.readFull(buffer[start:]); err != nil {
|
if err := s.readFull(buffer[start:]); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
Loading…
Reference in New Issue
Block a user