forked from dghubble/oauth1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoncer.go
More file actions
34 lines (28 loc) · 729 Bytes
/
Copy pathnoncer.go
File metadata and controls
34 lines (28 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
}