Skip to content

Commit 7ea4a36

Browse files
committed
Reduce rubocop custom rules
1 parent 659b038 commit 7ea4a36

File tree

14 files changed

+15
-45
lines changed

14 files changed

+15
-45
lines changed

.rubocop.yml

-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ AllCops:
99
Style/Documentation:
1010
Enabled: false
1111

12-
Style/IfUnlessModifier:
13-
Enabled: false
14-
1512
Metrics/AbcSize:
1613
Max: 25
1714

18-
Metrics/ClassLength:
19-
Max: 112
20-
2115
Metrics/MethodLength:
2216
Max: 18
2317

.simplecov

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ SimpleCov.start do
1010
add_filter 'spec'
1111
end
1212

13-
if ENV['CI']
14-
SimpleCov.formatters = SimpleCov::Formatter::JSONFormatter
15-
end
13+
SimpleCov.formatters = SimpleCov::Formatter::JSONFormatter if ENV['CI']

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- JWT::Token and JWT::EncodedToken for signing and verifying tokens [#621](https://github.com/jwt/ruby-jwt/pull/621) ([@anakinj](https://github.com/anakinj))
1010
- Detached payload support for JWT::Token and JWT::EncodedToken [#630](https://github.com/jwt/ruby-jwt/pull/630) ([@anakinj](https://github.com/anakinj))
1111
- Skip decoding payload if b64 header is present and false [#631](https://github.com/jwt/ruby-jwt/pull/631) ([@anakinj](https://github.com/anakinj))
12+
- Remove a few custom Rubocop configs [#638](https://github.com/jwt/ruby-jwt/pull/638) ([@anakinj](https://github.com/anakinj))
1213
- Your contribution here
1314

1415
**Fixes and enhancements:**

lib/jwt/configuration/jwk_configuration.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
module JWT
77
module Configuration
8+
# @api private
89
class JwkConfiguration
910
def initialize
1011
self.kid_generator_type = :key_digest

lib/jwt/jwa.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
require_relative 'jwa/unsupported'
1919
require_relative 'jwa/wrapper'
2020

21-
if JWT.rbnacl?
22-
require_relative 'jwa/eddsa'
23-
end
21+
require_relative 'jwa/eddsa' if JWT.rbnacl?
2422

2523
if JWT.rbnacl_6_or_greater?
2624
require_relative 'jwa/hmac_rbnacl'

lib/jwt/jwa/ecdsa.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ def initialize(alg, digest)
1313
def sign(data:, signing_key:)
1414
curve_definition = curve_by_name(signing_key.group.curve_name)
1515
key_algorithm = curve_definition[:algorithm]
16-
if alg != key_algorithm
17-
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} signing key was provided"
18-
end
16+
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} signing key was provided" if alg != key_algorithm
1917

2018
asn1_to_raw(signing_key.dsa_sign_asn1(digest.digest(data)), signing_key)
2119
end
2220

2321
def verify(data:, signature:, verification_key:)
2422
curve_definition = curve_by_name(verification_key.group.curve_name)
2523
key_algorithm = curve_definition[:algorithm]
26-
if alg != key_algorithm
27-
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} verification key was provided"
28-
end
24+
raise IncorrectAlgorithm, "payload algorithm is #{alg} but #{key_algorithm} verification key was provided" if alg != key_algorithm
2925

3026
verification_key.dsa_verify_asn1(digest.digest(data), raw_to_asn1(signature, verification_key))
3127
rescue OpenSSL::PKey::PKeyError

lib/jwt/jwa/eddsa.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ def initialize(alg)
1010
end
1111

1212
def sign(data:, signing_key:)
13-
unless signing_key.is_a?(RbNaCl::Signatures::Ed25519::SigningKey)
14-
raise_sign_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey")
15-
end
13+
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)
1614

1715
signing_key.sign(data)
1816
end
1917

2018
def verify(data:, signature:, verification_key:)
21-
unless verification_key.is_a?(RbNaCl::Signatures::Ed25519::VerifyKey)
22-
raise_verify_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey")
23-
end
19+
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)
2420

2521
verification_key.verify(signature, data)
2622
rescue RbNaCl::CryptoError

lib/jwt/jwa/hmac.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def sign(data:, signing_key:)
2020

2121
OpenSSL::HMAC.digest(digest.new, signing_key, data)
2222
rescue OpenSSL::HMACError => e
23-
if signing_key == '' && e.message == 'EVP_PKEY_new_mac_key: malloc failure'
24-
raise_verify_error!('OpenSSL 3.0 does not support nil or empty hmac_secret')
25-
end
23+
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'
2624

2725
raise e
2826
end

lib/jwt/jwa/ps.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def initialize(alg)
1111
end
1212

1313
def sign(data:, signing_key:)
14-
unless signing_key.is_a?(::OpenSSL::PKey::RSA)
15-
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance.")
16-
end
14+
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)
1715

1816
signing_key.sign_pss(digest_algorithm, data, salt_length: :digest, mgf1_hash: digest_algorithm)
1917
end

lib/jwt/jwa/rsa.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def initialize(alg)
1111
end
1212

1313
def sign(data:, signing_key:)
14-
unless signing_key.is_a?(OpenSSL::PKey::RSA)
15-
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance")
16-
end
14+
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)
1715

1816
signing_key.sign(digest, data)
1917
end

lib/jwt/jwk/ec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def key_digest
6565
end
6666

6767
def []=(key, value)
68-
if EC_KEY_ELEMENTS.include?(key.to_sym)
69-
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
70-
end
68+
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if EC_KEY_ELEMENTS.include?(key.to_sym)
7169

7270
super(key, value)
7371
end

lib/jwt/jwk/hmac.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def key_digest
6161
end
6262

6363
def []=(key, value)
64-
if HMAC_KEY_ELEMENTS.include?(key.to_sym)
65-
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
66-
end
64+
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if HMAC_KEY_ELEMENTS.include?(key.to_sym)
6765

6866
super(key, value)
6967
end

lib/jwt/jwk/okp_rbnacl.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def parse_okp_key_params(verify_key, signing_key = nil)
8383
x: ::JWT::Base64.url_encode(verify_key.to_bytes)
8484
}
8585

86-
if signing_key
87-
params[:d] = ::JWT::Base64.url_encode(signing_key.to_bytes)
88-
end
86+
params[:d] = ::JWT::Base64.url_encode(signing_key.to_bytes) if signing_key
8987

9088
params
9189
end

lib/jwt/jwk/rsa.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def key_digest
6464
end
6565

6666
def []=(key, value)
67-
if RSA_KEY_ELEMENTS.include?(key.to_sym)
68-
raise ArgumentError, 'cannot overwrite cryptographic key attributes'
69-
end
67+
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if RSA_KEY_ELEMENTS.include?(key.to_sym)
7068

7169
super(key, value)
7270
end

0 commit comments

Comments
 (0)