3 // Implements the none signing method. This is required by the spec
4 // but you probably should never use it.
5 var SigningMethodNone *signingMethodNone
7 const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
9 var NoneSignatureTypeDisallowedError error
11 type signingMethodNone struct{}
12 type unsafeNoneMagicConstant string
15 SigningMethodNone = &signingMethodNone{}
16 NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid)
18 RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod {
19 return SigningMethodNone
23 func (m *signingMethodNone) Alg() string {
27 // Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key
28 func (m *signingMethodNone) Verify(signingString, signature string, 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
34 // If signing method is none, signature must be an empty string
36 return NewValidationError(
37 "'none' signing method with non-empty signature",
38 ValidationErrorSignatureInvalid,
42 // Accept 'none' signing method.
46 // Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key
47 func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) {
48 if _, ok := key.(unsafeNoneMagicConstant); ok {
51 return "", NoneSignatureTypeDisallowedError