Class: Shhh::EncryptedFile

Inherits:
Object
  • Object
show all
Includes:
Shhh
Defined in:
lib/shhh/encrypted_file.rb

Overview

This class provides a convenience wrapper for opening and reading encrypted files as they were regular files, and then possibly writing changes to them later.

Constant Summary

Constants included from Shhh

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, key_id:, key_type:) ⇒ EncryptedFile

Returns a new instance of EncryptedFile.



16
17
18
19
20
21
22
# File 'lib/shhh/encrypted_file.rb', line 16

def initialize(file:, key_id:, key_type:)
  @file        = file
  @key_id      = key_id
  @key_type    = key_type.to_sym
  @app_args    = { file: file, key_type => key_id, decrypt: true }
  @application = Shhh::Application.new(self.app_args)
end

Instance Attribute Details

#app_argsObject (readonly)

Returns the value of attribute app_args.



14
15
16
# File 'lib/shhh/encrypted_file.rb', line 14

def app_args
  @app_args
end

#applicationObject (readonly)

Returns the value of attribute application.



14
15
16
# File 'lib/shhh/encrypted_file.rb', line 14

def application
  @application
end

#fileObject (readonly)

Returns the value of attribute file.



14
15
16
# File 'lib/shhh/encrypted_file.rb', line 14

def file
  @file
end

#key_idObject (readonly)

Returns the value of attribute key_id.



14
15
16
# File 'lib/shhh/encrypted_file.rb', line 14

def key_id
  @key_id
end

#key_typeObject (readonly)

Returns the value of attribute key_type.



14
15
16
# File 'lib/shhh/encrypted_file.rb', line 14

def key_type
  @key_type
end

Instance Method Details

#readObject



24
25
26
27
# File 'lib/shhh/encrypted_file.rb', line 24

def read
  @content = application.execute! unless @content
  @content
end

#writeObject



29
30
31
# File 'lib/shhh/encrypted_file.rb', line 29

def write
  Shhh::Application.new(file: file, key_type => key_id, encrypt: true, output: file).execute
end