Module: JWT::JWA

Defined in:
lib/jwt/jwa.rb,
lib/jwt/jwa/ps.rb,
lib/jwt/jwa/rsa.rb,
lib/jwt/jwa/hmac.rb,
lib/jwt/jwa/none.rb,
lib/jwt/jwa/ecdsa.rb,
lib/jwt/jwa/eddsa.rb,
lib/jwt/jwa/wrapper.rb,
lib/jwt/jwa/unsupported.rb

Defined Under Namespace

Modules: Ecdsa, Eddsa, Hmac, None, Ps, Rsa, Unsupported Classes: Wrapper

Constant Summary collapse

ALGOS =
[Hmac, Ecdsa, Rsa, Eddsa, Ps, None, Unsupported].tap do |l|
  if ::JWT.rbnacl_6_or_greater?
    require_relative 'jwa/hmac_rbnacl'
    l << Algos::HmacRbNaCl
  elsif ::JWT.rbnacl?
    require_relative 'jwa/hmac_rbnacl_fixed'
    l << Algos::HmacRbNaClFixed
  end
end.freeze

Class Method Summary collapse

Class Method Details

.create(algorithm) ⇒ Object



37
38
39
40
41
# File 'lib/jwt/jwa.rb', line 37

def create(algorithm)
  return algorithm if JWA.implementation?(algorithm)

  Wrapper.new(*find(algorithm))
end

.find(algorithm) ⇒ Object



33
34
35
# File 'lib/jwt/jwa.rb', line 33

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

.implementation?(algorithm) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# 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