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

Overview

JSON Web Algorithms

Defined Under Namespace

Modules: SigningAlgorithm, Unsupported Classes: Ecdsa, Hmac, None, Ps, Rsa

Class Method Summary collapse

Class Method Details

.find(algo) ⇒ Object



51
52
53
# File 'lib/jwt/jwa/signing_algorithm.rb', line 51

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

.register_algorithm(algo) ⇒ Object



47
48
49
# File 'lib/jwt/jwa/signing_algorithm.rb', line 47

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.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
# File 'lib/jwt/jwa.rb', line 18

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

  raise ArgumentError, 'Custom algorithms are required to include JWT::JWA::SigningAlgorithm' unless algorithm.is_a?(SigningAlgorithm)

  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.



27
28
29
30
# File 'lib/jwt/jwa.rb', line 27

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