Skip to content

Commit

Permalink
Merge pull request #14 from alpaca-tc/set_specific_cipher
Browse files Browse the repository at this point in the history
Fixed #13
  • Loading branch information
alpaca-tc authored Dec 18, 2018
2 parents 835fc0b + 3eeacbe commit bf7ca3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/active_record_encryption/encryptor/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
module ActiveRecordEncryption
module Encryptor
class ActiveSupport < Raw
def initialize(key:, salt:)
def initialize(key:, salt:, cipher: nil)
key_generator = ::ActiveSupport::KeyGenerator.new(key)
@encryptor = ::ActiveSupport::MessageEncryptor.new(key_generator.generate_key(salt, 32))
@encryptor = ::ActiveSupport::MessageEncryptor.new(key_generator.generate_key(salt, 32), cipher: cipher)
end

def encrypt(value)
Expand Down
24 changes: 24 additions & 0 deletions spec/active_record_encryption/encryptor/active_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
expect { described_class.new(key: key) }.to raise_error(ArgumentError)
end
end

context 'with cipher' do
let(:instance) { described_class.new(salt: salt, key: key, cipher: cipher) }

def new_cipher
instance.instance_variable_get(:@encryptor).send(:new_cipher)
end

context 'cipher is "aes-256-gcm"' do
let(:cipher) { 'aes-256-gcm' }

it 'builds aes-256-gcm encryptor' do
expect(new_cipher.name).to eq('id-aes256-GCM')
end
end

context 'cipher is "aes-256-cbc"' do
let(:cipher) { 'aes-256-cbc' }

it 'builds aes-256-cbc encryptor' do
expect(new_cipher.name).to eq('AES-256-CBC')
end
end
end
end

describe '#encrypt/decrypt' do
Expand Down

0 comments on commit bf7ca3c

Please sign in to comment.