aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/golang-jwt/jwt/v5/none.go
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-30 14:00:34 +0100
committerLibravatar Rutger Broekhoff2023-12-30 14:00:34 +0100
commitf6c92c5e2d87ab1334648b0d1293771de7aae4a5 (patch)
tree265c3a06accd398a1e0a173af56d7392a5f94a24 /vendor/github.com/golang-jwt/jwt/v5/none.go
parent4f167c0fa991aa9ddb3f0252e23694b3aa6532b1 (diff)
downloadgitolfs3-f6c92c5e2d87ab1334648b0d1293771de7aae4a5.tar.gz
gitolfs3-f6c92c5e2d87ab1334648b0d1293771de7aae4a5.zip
Implement git-lfs-authenticate
Diffstat (limited to 'vendor/github.com/golang-jwt/jwt/v5/none.go')
-rw-r--r--vendor/github.com/golang-jwt/jwt/v5/none.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/golang-jwt/jwt/v5/none.go b/vendor/github.com/golang-jwt/jwt/v5/none.go
new file mode 100644
index 0000000..685c2ea
--- /dev/null
+++ b/vendor/github.com/golang-jwt/jwt/v5/none.go
@@ -0,0 +1,50 @@
1package jwt
2
3// SigningMethodNone implements the none signing method. This is required by the spec
4// but you probably should never use it.
5var SigningMethodNone *signingMethodNone
6
7const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
8
9var NoneSignatureTypeDisallowedError error
10
11type signingMethodNone struct{}
12type unsafeNoneMagicConstant string
13
14func init() {
15 SigningMethodNone = &signingMethodNone{}
16 NoneSignatureTypeDisallowedError = newError("'none' signature type is not allowed", ErrTokenUnverifiable)
17
18 RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod {
19 return SigningMethodNone
20 })
21}
22
23func (m *signingMethodNone) Alg() string {
24 return "none"
25}
26
27// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key
28func (m *signingMethodNone) Verify(signingString string, sig []byte, key interface{}) (err error) {
29 // Key must be UnsafeAllowNoneSignatureType to prevent accidentally
30 // accepting 'none' signing method
31 if _, ok := key.(unsafeNoneMagicConstant); !ok {
32 return NoneSignatureTypeDisallowedError
33 }
34 // If signing method is none, signature must be an empty string
35 if len(sig) != 0 {
36 return newError("'none' signing method with non-empty signature", ErrTokenUnverifiable)
37 }
38
39 // Accept 'none' signing method.
40 return nil
41}
42
43// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key
44func (m *signingMethodNone) Sign(signingString string, key interface{}) ([]byte, error) {
45 if _, ok := key.(unsafeNoneMagicConstant); ok {
46 return []byte{}, nil
47 }
48
49 return nil, NoneSignatureTypeDisallowedError
50}