iperf3exporter/vendor/github.com/dghubble/oauth1/noncer.go
Marvin Preuss 2343c9588a
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
first commit
2021-10-20 10:08:56 +02:00

35 lines
729 B
Go

package oauth1
import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
)
// Noncer provides random nonce strings.
type Noncer interface {
Nonce() string
}
// Base64Noncer reads 32 bytes from crypto/rand and
// returns those bytes as a base64 encoded string.
type Base64Noncer struct{}
// Nonce provides a random nonce string.
func (n Base64Noncer) Nonce() string {
b := make([]byte, 32)
rand.Read(b)
return base64.StdEncoding.EncodeToString(b)
}
// HexNoncer reads 32 bytes from crypto/rand and
// returns those bytes as a base64 encoded string.
type HexNoncer struct{}
// Nonce provides a random nonce string.
func (n HexNoncer) Nonce() string {
b := make([]byte, 32)
rand.Read(b)
return hex.EncodeToString(b)
}