This repository was archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparts.go
62 lines (51 loc) · 1.52 KB
/
parts.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jwtee
import (
"encoding/json"
)
// DecodedParts stores ready to use parts of the JWT token.
type DecodedParts struct {
raw []byte
header Header
claims json.RawMessage
payload []byte
signature []byte
}
// Header returns token's Header.
func (t *DecodedParts) Header() Header {
return t.header
}
// RawClaims returns bytes with decoded claims string.
func (t *DecodedParts) RawClaims() []byte {
return t.claims
}
// Payload returns bytes used as JWS Signing Input to compute the JWS Signature.
// JWS Signing Input formatted as:
// ASCII(BASE64URL(UTF8(JWS Protected Header)) || '.' || BASE64URL(JWS Payload))
func (t *DecodedParts) Payload() []byte {
return t.payload
}
// Signature returns token's signature.
func (t *DecodedParts) Signature() []byte {
return t.signature
}
// MarshalBinary inherited from encoding.BinaryMarshaler.
func (t *DecodedParts) MarshalBinary() (data []byte, err error) {
return t.raw, nil
}
// MarshalText inherited from encoding.TextMarshaler.
func (t *DecodedParts) MarshalText() (text []byte, err error) {
return t.MarshalBinary()
}
// PartsVerifier used to verify signature of JWT.
type PartsVerifier struct {
signer Signer
key Key
}
// NewPartsVerifier returns new instance of PartsVerifier.
func NewPartsVerifier(signer Signer, key Key) *PartsVerifier {
return &PartsVerifier{signer, key}
}
// Verify used to check consistency of token signature.
func (v *PartsVerifier) Verify(parts *DecodedParts) error {
return v.signer.Verify(parts.Signature(), parts.Payload(), v.key)
}