Skip to content

Commit 961cb31

Browse files
authored
refactor: Use built-in clear to zero byte slice (#2566)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> Replace the manual for-loop with a call to the built-in clear function to set all elements of the slice to their zero value. This change improves code readability and makes the intent more explicit. This is the idiomatic approach for this operation since Go 1.21. Signed-off-by: alex9long <[email protected]>
1 parent 42313a1 commit 961cb31

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

pkg/signer/file/local.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,7 @@ func fallbackDeriveKey(passphrase []byte, keyLen int) []byte {
436436

437437
// zeroBytes overwrites a byte slice with zeros
438438
func zeroBytes(b []byte) {
439-
for i := range b {
440-
b[i] = 0
441-
}
439+
clear(b)
442440
}
443441

444442
// getAddress returns the Ed25519 address of the signer.

0 commit comments

Comments
 (0)