8 "golang.org/x/crypto/blake2b"
11// Nonce generates a random 32-byte slice to be used as a nonce
12func Nonce() ([]byte, error) {
14 _, err := rand.Read(b)
21// HashNonce returns the BLAKE2b 256-bit hash of a nonce
22// NOTE: Error checking (G104) is purposefully skipped:
23// - `blake2b.New256` has no error path with a nil signing key
24// - `hash.Hash` interface's `Write` has an error signature, but
25// `blake2b.digest.Write` does not use it.
27func HashNonce(nonce []byte) string {
28 hasher, _ := blake2b.New256(nil)
30 sum := hasher.Sum(nil)
31 return base64.RawURLEncoding.EncodeToString(sum)
34// CheckNonce tests if a nonce matches the hashed version of it
35func CheckNonce(nonce []byte, hashed string) bool {
36 return hmac.Equal([]byte(HashNonce(nonce)), []byte(hashed))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list