forked from jwt/ruby-jwt
/
algos.rb
44 lines (38 loc) · 870 Bytes
/
algos.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
require 'jwt/algos/hmac'
require 'jwt/algos/eddsa'
require 'jwt/algos/ecdsa'
require 'jwt/algos/rsa'
require 'jwt/algos/ps'
require 'jwt/algos/none'
require 'jwt/algos/unsupported'
# JWT::Signature module
module JWT
# Signature logic for JWT
module Algos
extend self
ALGOS = [
Algos::Hmac,
Algos::Ecdsa,
Algos::Rsa,
Algos::Eddsa,
Algos::Ps,
Algos::None,
Algos::Unsupported
].freeze
def find(algorithm)
indexed[algorithm && algorithm.downcase]
end
private
def indexed
@indexed ||= begin
fallback = [Algos::Unsupported, nil]
ALGOS.each_with_object(Hash.new(fallback)) do |alg, hash|
alg.const_get(:SUPPORTED).each do |code|
hash[code.downcase] = [alg, code]
end
end
end
end
end
end