lib/keyring.rb in attr_keyring-0.4.0 vs lib/keyring.rb in attr_keyring-0.5.0

- old
+ new

@@ -7,10 +7,11 @@ require "keyring/encryptor/aes" UnknownKey = Class.new(StandardError) InvalidSecret = Class.new(StandardError) EmptyKeyring = Class.new(StandardError) + InvalidAuthentication = Class.new(StandardError) class Base def initialize(keyring, encryptor) @encryptor = encryptor @keyring = keyring.map do |id, value| @@ -29,30 +30,32 @@ return key if key raise UnknownKey, "key=#{id} is not available on keyring" end - def []=(id, value) - @keyring << Key.new(id, value, @encryptor.key_size) + def []=(id, key) + @keyring << Key.new(id, key, @encryptor.key_size) end def clear @keyring.clear end def encrypt(message, keyring_id = nil) keyring_id ||= current_key&.id digest = Digest::SHA1.hexdigest(message) + key = self[keyring_id] [ - @encryptor.encrypt(self[keyring_id].value, message), + @encryptor.encrypt(key, message), keyring_id, digest ] end def decrypt(message, keyring_id) - @encryptor.decrypt(self[keyring_id].value, message) + key = self[keyring_id] + @encryptor.decrypt(key, message) end end def self.new(keyring, encryptor = Encryptor::AES::AES128CBC) Base.new(keyring, encryptor)