Skip to content

Commit 3d94e2e

Browse files
committed
avoid multiple calls to len
1 parent 0d2551e commit 3d94e2e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

internal/forwarding.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,16 @@ func decodeHexOrBase64To32Bytes(input string) (decoded []byte, err error) {
261261

262262
// leftPadIfRequired pads a byte slice to the left with 0x00 if the length is not 32 bytes.
263263
func leftPadIfRequired(input []byte) ([]byte, error) {
264-
if len(input) > 32 {
265-
return nil, fmt.Errorf("input is too long; max 32 bytes; got: %d", len(input))
264+
inputLen := len(input)
265+
if inputLen > 32 {
266+
return nil, fmt.Errorf("input is too long; max 32 bytes; got: %d", inputLen)
266267
}
267268

268-
if len(input) == 32 {
269+
if inputLen == 32 {
269270
return input, nil
270271
}
271272

272-
pad := make([]byte, 0, 32-len(input))
273+
pad := make([]byte, 0, 32-inputLen)
273274

274275
return append(pad, input...), nil
275276
}

0 commit comments

Comments
 (0)