Class: Sym::EncryptedFile

Inherits:
Object show all
Includes:
Sym
Defined in:
lib/sym/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 Sym

BASH_COMPLETION, COMPLETION_FILE, COMPLETION_PATH, DESCRIPTION, ENV_ARGS_VARIABLE_NAME, LOGGER, NIL_LOGGER, 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/sym/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 = Sym::Application.new(self.app_args)
end

Instance Attribute Details

#app_argsObject (readonly)

Returns the value of attribute app_args.



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

def app_args
  @app_args
end

#applicationObject (readonly)

Returns the value of attribute application.



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

def application
  @application
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#key_idObject (readonly)

Returns the value of attribute key_id.



14
15
16
# File 'lib/sym/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/sym/encrypted_file.rb', line 14

def key_type
  @key_type
end

Instance Method Details

#readObject



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

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

#writeObject



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

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