Skip to content

Commit faea065

Browse files
authored
Fix RuboCop issues (#37)
* Fix Style/RedundantRegexpEscape * Fix autocorrectable rubocop issues * Fix accessor lint issues
1 parent 0a210f1 commit faea065

File tree

7 files changed

+11
-71
lines changed

7 files changed

+11
-71
lines changed

.rubocop.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
inherit_from: .rubocop_todo.yml
2-
31
AllCops:
42
TargetRubyVersion: 2.5
53
NewCops: enable
@@ -17,3 +15,7 @@ Metrics/BlockLength:
1715
Style/PercentLiteralDelimiters:
1816
PreferredDelimiters:
1917
"%w": "[]"
18+
19+
Naming/MethodParameterName:
20+
AllowedNames: ["iv", "b", "j", "a", "r", "t"]
21+

.rubocop_todo.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

jwe.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
lib = File.expand_path('../lib/', __FILE__)
3+
lib = File.expand_path('lib', __dir__)
44
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
55
require 'jwe/version'
66

lib/jwe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def check_key(key)
7575
end
7676

7777
def param_to_class_name(param)
78-
klass = param.gsub(/[-\+]/, '_').downcase.sub(/^[a-z\d]*/) { $&.capitalize }
78+
klass = param.gsub(/[-+]/, '_').downcase.sub(/^[a-z\d]*/) { ::Regexp.last_match(0).capitalize }
7979
klass.gsub(/_([a-z\d]*)/i) { Regexp.last_match(1).capitalize }
8080
end
8181

lib/jwe/alg/aes_kw.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ module JWE
66
module Alg
77
# Generic AES Key Wrapping algorithm for any key size.
88
module AesKw
9-
attr_accessor :key
10-
attr_accessor :iv
9+
attr_accessor :key, :iv
1110

1211
def initialize(key = nil, iv = "\xA6\xA6\xA6\xA6\xA6\xA6\xA6\xA6")
1312
self.iv = iv.b
@@ -45,9 +44,7 @@ def decrypt(encrypted_cek)
4544
a, r = kw_decrypt_round(j, a, r)
4645
end
4746

48-
if a != iv
49-
raise StandardError.new('The encrypted key has been tampered. Do not use this key.')
50-
end
47+
raise StandardError.new('The encrypted key has been tampered. Do not use this key.') if a != iv
5148

5249
r.join
5350
end

lib/jwe/enc/aes_cbc_hs.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ module JWE
66
module Enc
77
# Abstract AES in Block cipher mode, with message signature for different key sizes.
88
module AesCbcHs
9-
attr_accessor :cek
10-
attr_accessor :iv
11-
attr_accessor :tag
9+
attr_writer :cek, :iv, :tag
1210

1311
def initialize(cek = nil, iv = nil)
1412
self.iv = iv
@@ -30,9 +28,7 @@ def decrypt(ciphertext, authenticated_data)
3028
raise JWE::BadCEK, "The supplied key is invalid. Required length: #{key_length}" if cek.length != key_length
3129

3230
signature = generate_tag(authenticated_data, iv, ciphertext)
33-
if signature != tag
34-
raise JWE::InvalidData, 'Authentication tag verification failed'
35-
end
31+
raise JWE::InvalidData, 'Authentication tag verification failed' if signature != tag
3632

3733
cipher_round(:decrypt, iv, ciphertext)
3834
rescue OpenSSL::Cipher::CipherError

lib/jwe/enc/aes_gcm.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ module JWE
66
module Enc
77
# Abstract AES in Galois Counter mode for different key sizes.
88
module AesGcm
9-
attr_accessor :cek
10-
attr_accessor :iv
11-
attr_accessor :tag
9+
attr_writer :iv, :cek, :tag
1210

1311
def initialize(cek = nil, iv = nil)
1412
self.iv = iv

0 commit comments

Comments
 (0)