Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore casing of algorithm #405

Merged
merged 13 commits into from
Feb 9, 2021
Prev Previous commit
Next Next commit
Respond to comments
  • Loading branch information
johnnyshields committed Feb 8, 2021
commit 6300a32a5864f183c2bab401fedc2ce87b900413
5 changes: 2 additions & 3 deletions lib/jwt/algos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def find(algorithm)

def indexed
@indexed ||= begin
algos = ALGOS.dup
fallback = [algos.pop, nil]
algos.each_with_object(Hash.new(fallback)) do |alg, hash|
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
Expand Down
4 changes: 2 additions & 2 deletions spec/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@
enc = JWT.encode(payload, '', 'hs256')
expect(JWT.decode(enc, '')).to eq([payload, { 'alg' => 'HS256'}])

enc = JWT.encode(payload, data[:rsa_private], 'ps384')
expect(JWT.decode(enc, data[:rsa_public], true, algorithm: 'PS384')).to eq([payload, { 'alg' => 'PS384'}])
enc = JWT.encode(payload, data[:rsa_private], 'rs512')
expect(JWT.decode(enc, data[:rsa_public], true, algorithm: 'RS512')).to eq([payload, { 'alg' => 'RS512'}])

enc = JWT.encode(payload, data[:rsa_private], 'RS512')
expect(JWT.decode(enc, data[:rsa_public], true, algorithm: 'rs512')).to eq([payload, { 'alg' => 'RS512'}])
Expand Down