module JWT::JWA

Constants

ALGOS

Public Class Methods

create(algorithm) click to toggle source
# File lib/jwt/jwa.rb, line 37
def create(algorithm)
  return algorithm if JWA.implementation?(algorithm)

  Wrapper.new(*find(algorithm))
end
find(algorithm) click to toggle source
# File lib/jwt/jwa.rb, line 33
def find(algorithm)
  indexed[algorithm&.downcase]
end
implementation?(algorithm) click to toggle source
# File lib/jwt/jwa.rb, line 43
def implementation?(algorithm)
  (algorithm.respond_to?(:valid_alg?) && algorithm.respond_to?(:verify)) ||
    (algorithm.respond_to?(:alg) && algorithm.respond_to?(:sign))
end

Private Class Methods

indexed() click to toggle source
# File lib/jwt/jwa.rb, line 50
def indexed
  @indexed ||= begin
    fallback = [nil, Unsupported]
    ALGOS.each_with_object(Hash.new(fallback)) do |cls, hash|
      cls.const_get(:SUPPORTED).each do |alg|
        hash[alg.downcase] = [alg, cls]
      end
    end
  end
end