module JWT::JWA

def create(algorithm)

def create(algorithm)
  return algorithm if JWA.implementation?(algorithm)
  Wrapper.new(*find(algorithm))
end

def find(algorithm)

def find(algorithm)
  indexed[algorithm&.downcase]
end

def implementation?(algorithm)

def implementation?(algorithm)
  (algorithm.respond_to?(:valid_alg?) && algorithm.respond_to?(:verify)) ||
    (algorithm.respond_to?(:alg) && algorithm.respond_to?(:sign))
end

def indexed

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