Class: Lockness::Content
- Inherits:
-
Object
- Object
- Lockness::Content
- Defined in:
- lib/lockness/content.rb
Instance Attribute Summary collapse
-
#encrypted ⇒ Object
readonly
Returns the value of attribute encrypted.
-
#encrypted_file ⇒ Object
readonly
Returns the value of attribute encrypted_file.
-
#message_encryptor ⇒ Object
readonly
Returns the value of attribute message_encryptor.
Instance Method Summary collapse
-
#initialize(encrypted_file:) ⇒ Content
constructor
A new instance of Content.
- #plain ⇒ Object
- #update(new_plain_content) ⇒ Object
Constructor Details
#initialize(encrypted_file:) ⇒ Content
Returns a new instance of Content.
8 9 10 11 12 |
# File 'lib/lockness/content.rb', line 8 def initialize(encrypted_file:) @encrypted_file = encrypted_file @message_encryptor = ActiveSupport::MessageEncryptor.new(MasterKey.new.read) @encrypted = encrypted_file.read end |
Instance Attribute Details
#encrypted ⇒ Object (readonly)
Returns the value of attribute encrypted.
4 5 6 |
# File 'lib/lockness/content.rb', line 4 def encrypted @encrypted end |
#encrypted_file ⇒ Object (readonly)
Returns the value of attribute encrypted_file.
4 5 6 |
# File 'lib/lockness/content.rb', line 4 def encrypted_file @encrypted_file end |
#message_encryptor ⇒ Object (readonly)
Returns the value of attribute message_encryptor.
4 5 6 |
# File 'lib/lockness/content.rb', line 4 def @message_encryptor end |
Instance Method Details
#plain ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lockness/content.rb', line 14 def plain .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 |
#update(new_plain_content) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/lockness/content.rb', line 25 def update(new_plain_content) ensure_content(new_plain_content) encrypted_content = .encrypt_and_sign(new_plain_content) encrypted_file.save(encrypted_content) end |