http urls monitor.

signing_method.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. package jwt
  2. import (
  3. "sync"
  4. )
  5. var signingMethods = map[string]func() SigningMethod{}
  6. var signingMethodLock = new(sync.RWMutex)
  7. // Implement SigningMethod to add new methods for signing or verifying tokens.
  8. type SigningMethod interface {
  9. Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid
  10. Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error
  11. Alg() string // returns the alg identifier for this method (example: 'HS256')
  12. }
  13. // Register the "alg" name and a factory function for signing method.
  14. // This is typically done during init() in the method's implementation
  15. func RegisterSigningMethod(alg string, f func() SigningMethod) {
  16. signingMethodLock.Lock()
  17. defer signingMethodLock.Unlock()
  18. signingMethods[alg] = f
  19. }
  20. // Get a signing method from an "alg" string
  21. func GetSigningMethod(alg string) (method SigningMethod) {
  22. signingMethodLock.RLock()
  23. defer signingMethodLock.RUnlock()
  24. if methodF, ok := signingMethods[alg]; ok {
  25. method = methodF()
  26. }
  27. return
  28. }