From 7ea4a366a8a5e36dede46b8ada969052c9f0dead Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Sat, 7 Dec 2024 16:19:52 +0200 Subject: [PATCH] Reduce rubocop custom rules --- .rubocop.yml | 6 ------ .simplecov | 4 +--- CHANGELOG.md | 1 + lib/jwt/configuration/jwk_configuration.rb | 1 + lib/jwt/jwa.rb | 4 +--- lib/jwt/jwa/ecdsa.rb | 8 ++------ lib/jwt/jwa/eddsa.rb | 8 ++------ lib/jwt/jwa/hmac.rb | 4 +--- lib/jwt/jwa/ps.rb | 4 +--- lib/jwt/jwa/rsa.rb | 4 +--- lib/jwt/jwk/ec.rb | 4 +--- lib/jwt/jwk/hmac.rb | 4 +--- lib/jwt/jwk/okp_rbnacl.rb | 4 +--- lib/jwt/jwk/rsa.rb | 4 +--- 14 files changed, 15 insertions(+), 45 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 204fa8bf..ac4eb0e0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/.simplecov b/.simplecov index 4af4eb6a..51b38561 100644 --- a/.simplecov +++ b/.simplecov @@ -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'] diff --git a/CHANGELOG.md b/CHANGELOG.md index 4475e960..74ac03cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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:** diff --git a/lib/jwt/configuration/jwk_configuration.rb b/lib/jwt/configuration/jwk_configuration.rb index 90503961..f1373bce 100644 --- a/lib/jwt/configuration/jwk_configuration.rb +++ b/lib/jwt/configuration/jwk_configuration.rb @@ -5,6 +5,7 @@ module JWT module Configuration + # @api private class JwkConfiguration def initialize self.kid_generator_type = :key_digest diff --git a/lib/jwt/jwa.rb b/lib/jwt/jwa.rb index 943fc96b..81d808aa 100644 --- a/lib/jwt/jwa.rb +++ b/lib/jwt/jwa.rb @@ -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' diff --git a/lib/jwt/jwa/ecdsa.rb b/lib/jwt/jwa/ecdsa.rb index 076d28f1..580452f5 100644 --- a/lib/jwt/jwa/ecdsa.rb +++ b/lib/jwt/jwa/ecdsa.rb @@ -13,9 +13,7 @@ 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 @@ -23,9 +21,7 @@ def sign(data:, signing_key:) 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 diff --git a/lib/jwt/jwa/eddsa.rb b/lib/jwt/jwa/eddsa.rb index 1d9e656f..824ef5e7 100644 --- a/lib/jwt/jwa/eddsa.rb +++ b/lib/jwt/jwa/eddsa.rb @@ -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 diff --git a/lib/jwt/jwa/hmac.rb b/lib/jwt/jwa/hmac.rb index ac95c8c6..be973306 100644 --- a/lib/jwt/jwa/hmac.rb +++ b/lib/jwt/jwa/hmac.rb @@ -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 diff --git a/lib/jwt/jwa/ps.rb b/lib/jwt/jwa/ps.rb index ed27f792..9bfb7058 100644 --- a/lib/jwt/jwa/ps.rb +++ b/lib/jwt/jwa/ps.rb @@ -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 diff --git a/lib/jwt/jwa/rsa.rb b/lib/jwt/jwa/rsa.rb index 79ca52a0..d9169d42 100644 --- a/lib/jwt/jwa/rsa.rb +++ b/lib/jwt/jwa/rsa.rb @@ -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 diff --git a/lib/jwt/jwk/ec.rb b/lib/jwt/jwk/ec.rb index 41e74831..40ccd2e4 100644 --- a/lib/jwt/jwk/ec.rb +++ b/lib/jwt/jwk/ec.rb @@ -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 diff --git a/lib/jwt/jwk/hmac.rb b/lib/jwt/jwk/hmac.rb index be371471..5e243ccb 100644 --- a/lib/jwt/jwk/hmac.rb +++ b/lib/jwt/jwk/hmac.rb @@ -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 diff --git a/lib/jwt/jwk/okp_rbnacl.rb b/lib/jwt/jwk/okp_rbnacl.rb index cb24211f..76cfdf23 100644 --- a/lib/jwt/jwk/okp_rbnacl.rb +++ b/lib/jwt/jwk/okp_rbnacl.rb @@ -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 diff --git a/lib/jwt/jwk/rsa.rb b/lib/jwt/jwk/rsa.rb index 6dfbe844..5d8012e2 100644 --- a/lib/jwt/jwk/rsa.rb +++ b/lib/jwt/jwk/rsa.rb @@ -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