lib/lockness/content.rb in lockness-0.1.0 vs lib/lockness/content.rb in lockness-0.2.0

- old
+ new

@@ -1,27 +1,34 @@ module Lockness class Content - attr_reader :secret_file, + attr_reader :encrypted_file, :message_encryptor, :encrypted - def initialize - @secret_file = SecretFile.new + def initialize(encrypted_file:) + @encrypted_file = encrypted_file @message_encryptor = ActiveSupport::MessageEncryptor.new(MasterKey.new.read) - @encrypted = secret_file.read + @encrypted = encrypted_file.read end def plain message_encryptor.decrypt_and_verify(encrypted) + + rescue ActiveSupport::MessageVerifier::InvalidSignature => exception + puts "Unable to decrypt using the master.key." + puts + puts "Please double check that the master.key is correct." + + exit 1 end def update(new_plain_content) ensure_content(new_plain_content) encrypted_content = message_encryptor.encrypt_and_sign(new_plain_content) - secret_file.save(encrypted_content) + encrypted_file.save(encrypted_content) end private def ensure_content(new_plain_content)