forked from MicahParks/keyfunc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmac.go
36 lines (28 loc) · 871 Bytes
/
hmac.go
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
35
36
package keyfunc
import (
"fmt"
)
const (
// hs256 represents a cryptographic key generated by an SHA-256 hash and an HMAC algorithm.
hs256 = "HS256"
// hs384 represents a cryptographic key generated by an SHA-384 hash and an HMAC algorithm.
hs384 = "HS384"
// hs512 represents a cryptographic key generated by an SHA-512 hash and an HMAC algorithm.
hs512 = "HS512"
)
// HMAC returns the HMAC key used for parsing and verifying the JWT.
//
// The jsonKey data structure does not
func (j *jsonKey) HMAC() (key []byte, err error) {
// Confirm the key is already present as expected.
j.precomputedMux.RLock()
defer j.precomputedMux.RUnlock()
if j.precomputed != nil {
var ok bool
if key, ok = j.precomputed.([]byte); ok {
return key, nil
}
}
// The HMAC key should have been pre-attached.
return nil, fmt.Errorf("%w: hmac", ErrMissingAssets)
}