Skip to content

Commit

Permalink
Use fetch to avoid explicit require
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Sep 7, 2024
1 parent 7b77143 commit 3a6f400
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/jwt/jwa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_relative 'jwa/rsa'
require_relative 'jwa/ps'
require_relative 'jwa/none'
require_relative 'jwa/unsupported'

if JWT.rbnacl_6_or_greater?
require_relative 'jwa/hmac_rbnacl'
Expand Down
6 changes: 2 additions & 4 deletions lib/jwt/jwa/signing_algorithm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ def raise_sign_error!(message)
end
end

require_relative 'unsupported' # Require the unsupported algo as it's needed as a default for the rest

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

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

private

def algorithms
@algorithms ||= {}.tap { |h| h.default = Unsupported }
@algorithms ||= {}
end
end
end
Expand Down

0 comments on commit 3a6f400

Please sign in to comment.