Closed scop closed 10 months ago
Hmm... Do you have a code sample ? If I recall correctly, some cases are supported
https://go.dev/play/p/p98DpofjCGz
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
func main() {
sum := sha256.Sum256([]byte("hello world\n"))
fmt.Println(fmt.Sprintf("%x", sum))
// fmt.Println(hex.EncodeToString(sum)) // cannot use sum (variable of type [32]byte) as []byte value in argument to hex.EncodeToString
fmt.Println(hex.EncodeToString(sum[:]))
}
This only works for literals, right ? Cf https://go.dev/play/p/V2PmRQt7jUn
fmt.Println(fmt.Sprintf("%x", sha256.Sum256([]byte("hello world\n"))))
// cannot be replaced by following line
fmt.Println(hex.EncodeToString(sha256.Sum256([]byte("hello world\n"))[:]))
// errors with invalid operation: sha256.Sum256([]byte("hello world\n")) (value of type [32]byte) (slice of unaddressable value)
@catenacyber this works for non literal but you need to put in a variable first:
sum := sha256.Sum256([]byte("hello world\n"))
fmt.Println(hex.EncodeToString(sum[:]))
This could be tricky because if there are multiple functions invoked in the expression moving one before in a variable might change side-effects.
@scop this works for me with latest commit 0.3.1
Which version are you running ?
Closing as working on latest version
hex.EncodeToString
is currently (correctly) not being suggested for byte arrays.I'm wondering if it should, also noting that an array would need to be made a slice one way or another, e.g. with
[:]
?