Skip to content

Commit

Permalink
Reduce rubocop custom rules
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Dec 7, 2024
1 parent 659b038 commit 7ea4a36
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 45 deletions.
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ AllCops:
Style/Documentation:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Metrics/AbcSize:
Max: 25

Metrics/ClassLength:
Max: 112

Metrics/MethodLength:
Max: 18

Expand Down
4 changes: 1 addition & 3 deletions .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ SimpleCov.start do
add_filter 'spec'
end

if ENV['CI']
SimpleCov.formatters = SimpleCov::Formatter::JSONFormatter
end
SimpleCov.formatters = SimpleCov::Formatter::JSONFormatter if ENV['CI']
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- JWT::Token and JWT::EncodedToken for signing and verifying tokens [#621](https://github.com/jwt/ruby-jwt/pull/621) ([@anakinj](https://github.com/anakinj))
- Detached payload support for JWT::Token and JWT::EncodedToken [#630](https://github.com/jwt/ruby-jwt/pull/630) ([@anakinj](https://github.com/anakinj))
- Skip decoding payload if b64 header is present and false [#631](https://github.com/jwt/ruby-jwt/pull/631) ([@anakinj](https://github.com/anakinj))
- Remove a few custom Rubocop configs [#638](https://github.com/jwt/ruby-jwt/pull/638) ([@anakinj](https://github.com/anakinj))
- Your contribution here

**Fixes and enhancements:**
Expand Down
1 change: 1 addition & 0 deletions lib/jwt/configuration/jwk_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module JWT
module Configuration
# @api private
class JwkConfiguration
def initialize
self.kid_generator_type = :key_digest
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
require_relative 'jwa/unsupported'
require_relative 'jwa/wrapper'

if JWT.rbnacl?
require_relative 'jwa/eddsa'
end
require_relative 'jwa/eddsa' if JWT.rbnacl?

if JWT.rbnacl_6_or_greater?
require_relative 'jwa/hmac_rbnacl'
Expand Down
8 changes: 2 additions & 6 deletions lib/jwt/jwa/ecdsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ def initialize(alg, digest)
def sign(data:, signing_key:)
curve_definition = curve_by_name(signing_key.group.curve_name)
key_algorithm = curve_definition[:algorithm]
if alg != key_algorithm
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} signing key was provided"
end
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} signing key was provided" if alg != key_algorithm

asn1_to_raw(signing_key.dsa_sign_asn1(digest.digest(data)), signing_key)
end

def verify(data:, signature:, verification_key:)
curve_definition = curve_by_name(verification_key.group.curve_name)
key_algorithm = curve_definition[:algorithm]
if alg != key_algorithm
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} verification key was provided"
end
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} verification key was provided" if alg != key_algorithm

verification_key.dsa_verify_asn1(digest.digest(data), raw_to_asn1(signature, verification_key))
rescue OpenSSL::PKey::PKeyError
Expand Down
8 changes: 2 additions & 6 deletions lib/jwt/jwa/eddsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ def initialize(alg)
end

def sign(data:, signing_key:)
unless signing_key.is_a?(RbNaCl::Signatures::Ed25519::SigningKey)
raise_sign_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey")
end
raise_sign_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey") unless signing_key.is_a?(RbNaCl::Signatures::Ed25519::SigningKey)

signing_key.sign(data)
end

def verify(data:, signature:, verification_key:)
unless verification_key.is_a?(RbNaCl::Signatures::Ed25519::VerifyKey)
raise_verify_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey")
end
raise_verify_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey") unless verification_key.is_a?(RbNaCl::Signatures::Ed25519::VerifyKey)

verification_key.verify(signature, data)
rescue RbNaCl::CryptoError
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwa/hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def sign(data:, signing_key:)

OpenSSL::HMAC.digest(digest.new, signing_key, data)
rescue OpenSSL::HMACError => e
if signing_key == '' && e.message == 'EVP_PKEY_new_mac_key: malloc failure'
raise_verify_error!('OpenSSL 3.0 does not support nil or empty hmac_secret')
end
raise_verify_error!('OpenSSL 3.0 does not support nil or empty hmac_secret') if signing_key == '' && e.message == 'EVP_PKEY_new_mac_key: malloc failure'

raise e
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwa/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def initialize(alg)
end

def sign(data:, signing_key:)
unless signing_key.is_a?(::OpenSSL::PKey::RSA)
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance.")
end
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance.") unless signing_key.is_a?(::OpenSSL::PKey::RSA)

signing_key.sign_pss(digest_algorithm, data, salt_length: :digest, mgf1_hash: digest_algorithm)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwa/rsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def initialize(alg)
end

def sign(data:, signing_key:)
unless signing_key.is_a?(OpenSSL::PKey::RSA)
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance")
end
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance") unless signing_key.is_a?(OpenSSL::PKey::RSA)

signing_key.sign(digest, data)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwk/ec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def key_digest
end

def []=(key, value)
if EC_KEY_ELEMENTS.include?(key.to_sym)
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
end
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if EC_KEY_ELEMENTS.include?(key.to_sym)

super(key, value)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwk/hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def key_digest
end

def []=(key, value)
if HMAC_KEY_ELEMENTS.include?(key.to_sym)
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
end
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if HMAC_KEY_ELEMENTS.include?(key.to_sym)

super(key, value)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwk/okp_rbnacl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def parse_okp_key_params(verify_key, signing_key = nil)
x: ::JWT::Base64.url_encode(verify_key.to_bytes)
}

if signing_key
params[:d] = ::JWT::Base64.url_encode(signing_key.to_bytes)
end
params[:d] = ::JWT::Base64.url_encode(signing_key.to_bytes) if signing_key

params
end
Expand Down
4 changes: 1 addition & 3 deletions lib/jwt/jwk/rsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def key_digest
end

def []=(key, value)
if RSA_KEY_ELEMENTS.include?(key.to_sym)
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
end
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if RSA_KEY_ELEMENTS.include?(key.to_sym)

super(key, value)
end
Expand Down

0 comments on commit 7ea4a36

Please sign in to comment.