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/compat.rb,
lib/jwt/jwa/wrapper.rb,
lib/jwt/jwa/hmac_rbnacl.rb,
lib/jwt/jwa/unsupported.rb,
lib/jwt/jwa/hmac_rbnacl_fixed.rb,
lib/jwt/jwa/signing_algorithm.rb

Overview

The JWA module contains all supported algorithms.

Defined Under Namespace

Modules: Compat, SigningAlgorithm, Unsupported Classes: Ecdsa, Eddsa, Hmac, HmacRbNaCl, HmacRbNaClFixed, None, Ps, Rsa, Wrapper

Class Method Summary collapse

Class Method Details

.create(algorithm) ⇒ Object

Deprecated.

The ‘::JWT::JWA.create` method is deprecated and will be removed in the next major version of ruby-jwt.



54
55
56
57
# File 'lib/jwt/jwa.rb', line 54

def create(algorithm)
  Deprecations.warning('The ::JWT::JWA.create method is deprecated and will be removed in the next major version of ruby-jwt.')
  resolve(algorithm)
end

.find(algo) ⇒ Object



49
50
51
# File 'lib/jwt/jwa/signing_algorithm.rb', line 49

def find(algo)
  algorithms.fetch(algo.to_s.downcase, Unsupported)
end

.register_algorithm(algo) ⇒ Object



45
46
47
# File 'lib/jwt/jwa/signing_algorithm.rb', line 45

def register_algorithm(algo)
  algorithms[algo.alg.to_s.downcase] = algo
end

.resolve(algorithm) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
43
44
45
# File 'lib/jwt/jwa.rb', line 36

def resolve(algorithm)
  return find(algorithm) if algorithm.is_a?(String) || algorithm.is_a?(Symbol)

  unless algorithm.is_a?(SigningAlgorithm)
    Deprecations.warning('Custom algorithms are required to include JWT::JWA::SigningAlgorithm. Custom algorithms that do not include this module may stop working in the next major version of ruby-jwt.')
    return Wrapper.new(algorithm)
  end

  algorithm
end

.resolve_and_sort(algorithms:, preferred_algorithm:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
# File 'lib/jwt/jwa.rb', line 48

def resolve_and_sort(algorithms:, preferred_algorithm:)
  algs = Array(algorithms).map { |alg| JWA.resolve(alg) }
  algs.partition { |alg| alg.valid_alg?(preferred_algorithm) }.flatten
end