Skip to content

Commit

Permalink
Rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aldosolorzano committed Nov 16, 2018
1 parent abd80c4 commit 6323569
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ group :development, :test do
# compatible with ruby >= 1.9.3
gem 'guard-rubocop'
gem 'listen', '3.0.8'
gem 'terminal-notifier-guard'
gem 'openssl', '2.1.2'
gem 'terminal-notifier-guard'
end
2 changes: 1 addition & 1 deletion lib/crypto.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Crypto
autoload :PBE, 'crypto/PBE'
autoload :PBE, 'crypto/pbe'
end
4 changes: 2 additions & 2 deletions lib/crypto/PBE.rb → lib/crypto/pbe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Crypto
class PBE
ALPHA_NUM = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
SPECIALS = ['-', '_', '+', '=', '#', '&', '*', '.']
SPECIALS = ['-', '_', '+', '=', '#', '&', '*', '.'].freeze
CHARS = ALPHA_NUM + SPECIALS

def self.generate
Expand Down Expand Up @@ -34,7 +34,7 @@ def derived_key(password, salt, sizeKey = 24)
salt: salt,
iterations: @iterations,
sizeKey: sizeKey,
digest: @digest,
digest: @digest
}
PKCS5.new(args)
end
Expand Down
22 changes: 11 additions & 11 deletions spec/crypto/PBE_spec.rb → spec/crypto/pbe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
let(:specials) { ['-', '_', '+', '=', '#', '&', '*', '.'] }
let(:valid_chars) { alpha_num + specials }

describe "#PBE good" do
pbe_fixture[:valid].each do | v |
describe "#{v.slice(:key, :salt, :keylen, :iterations)}" do
describe '#PBE good' do
pbe_fixture[:valid].each do |v|
describe v.slice(:key, :salt, :keylen, :iterations).to_s do
let(:pbe) { Crypto::PBE.new(v[:iterations]) }
let(:key) { pbe.derived_key(v[:key], v[:salt], v[:keylen]) }
it 'should return a strong key' do
Expand All @@ -15,7 +15,7 @@
end
end

describe "Generate random keys" do
describe 'Generate random keys' do
let(:keys) { Set.new }
5.times do
key = Crypto::PBE.generate.to_hex
Expand All @@ -26,7 +26,7 @@
end
end

describe "Random password + size" do
describe 'Random password + size' do
let(:passwords) { Set.new }
key_lens = [32, 64, 40]
5.times do
Expand All @@ -39,7 +39,7 @@
it "should be size #{size}" do
expect(pass.length).to be size
end
it "should contain specified chars" do
it 'should contain specified chars' do
pass_chars = pass.chars
expect(pass_chars).to eq(pass_chars & valid_chars)
end
Expand All @@ -48,12 +48,12 @@
end

describe '#PBE bad' do
pbe_fixture[:invalid].each do | v |
describe "#{v[:description]}" do
let(:pbe){ Crypto::PBE.new(v[:iterations]) }
let(:error){ "integer #{v[:keylen]} too big to convert to `int'" }
pbe_fixture[:invalid].each do |v|
describe v[:description].to_s do
let(:pbe) { Crypto::PBE.new(v[:iterations]) }
let(:error) { "integer #{v[:keylen]} too big to convert to `int'" }
it 'should raise key length error' do
expect{ pbe.derived_key(v[:key], v[:salt], v[:keylen]) }.to raise_error(RangeError, error)
expect { pbe.derived_key(v[:key], v[:salt], v[:keylen]) }.to raise_error(RangeError, error)
end
end
end
Expand Down

0 comments on commit 6323569

Please sign in to comment.