Skip to content

Commit

Permalink
stop using JSON::JOSE#algorithm alias
Browse files Browse the repository at this point in the history
  • Loading branch information
nov committed May 23, 2020
1 parent 6de1dd9 commit 967731d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/json/jose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module JOSE
included do
extend ClassMethods
register_header_keys :alg, :jku, :jwk, :x5u, :x5t, :x5c, :kid, :typ, :cty, :crit

# NOTE: not used anymore in this gem, but keeping in case developers are calling it.
alias_method :algorithm, :alg

attr_writer :header
Expand Down
6 changes: 3 additions & 3 deletions lib/json/jwe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def cbc?
end

def dir?
:dir == algorithm&.to_sym
:dir == alg&.to_sym
end

def cipher
Expand Down Expand Up @@ -159,7 +159,7 @@ def derive_encryption_and_mac_keys
# encryption

def jwe_encrypted_key
@jwe_encrypted_key ||= case algorithm&.to_sym
@jwe_encrypted_key ||= case alg&.to_sym
when :RSA1_5
public_key_or_secret.public_encrypt content_encryption_key
when :'RSA-OAEP'
Expand Down Expand Up @@ -211,7 +211,7 @@ def authentication_tag

def decrypt_content_encryption_key
fake_content_encryption_key = generate_content_encryption_key # NOTE: do this always not to make timing difference
case algorithm&.to_sym
case alg&.to_sym
when :RSA1_5
private_key_or_secret.private_decrypt jwe_encrypted_key
when :'RSA-OAEP'
Expand Down
12 changes: 6 additions & 6 deletions lib/json/jws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(jwt)
end

def sign!(private_key_or_secret)
self.alg = autodetected_algorithm_from(private_key_or_secret) if algorithm == :autodetect
self.alg = autodetected_algorithm_from(private_key_or_secret) if alg == :autodetect
self.signature = sign signature_base_string, private_key_or_secret
self
end
Expand Down Expand Up @@ -43,19 +43,19 @@ def update(hash_or_jwt)
private

def digest
OpenSSL::Digest.new "SHA#{algorithm.to_s[2, 3]}"
OpenSSL::Digest.new "SHA#{alg.to_s[2, 3]}"
end

def hmac?
[:HS256, :HS384, :HS512].include? algorithm&.to_sym
[:HS256, :HS384, :HS512].include? alg&.to_sym
end

def rsa?
[:RS256, :RS384, :RS512].include? algorithm&.to_sym
[:RS256, :RS384, :RS512].include? alg&.to_sym
end

def rsa_pss?
if [:PS256, :PS384, :PS512].include? algorithm&.to_sym
if [:PS256, :PS384, :PS512].include? alg&.to_sym
if OpenSSL::VERSION < '2.1.0'
raise "#{alg} isn't supported. OpenSSL gem v2.1.0+ is required to use #{alg}."
else
Expand All @@ -67,7 +67,7 @@ def rsa_pss?
end

def ecdsa?
[:ES256, :ES384, :ES512].include? algorithm&.to_sym
[:ES256, :ES384, :ES512].include? alg&.to_sym
end

def autodetected_algorithm_from(private_key_or_secret)
Expand Down

0 comments on commit 967731d

Please sign in to comment.