Class: Trustworthy::CLI::Encrypt
- Inherits:
-
Object
- Object
- Trustworthy::CLI::Encrypt
show all
- Includes:
- Command, Crypt
- Defined in:
- lib/trustworthy/cli/encrypt.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Crypt
#_check_options, #_command, included, #parse_options, #run
Methods included from Command
#default_options, #parse_options, #print_help, #say
Class Method Details
._command ⇒ Object
7
8
9
|
# File 'lib/trustworthy/cli/encrypt.rb', line 7
def self._command
'encrypt'
end
|
Instance Method Details
#_format_ciphertext(output_file, ciphertext) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/trustworthy/cli/encrypt.rb', line 22
def _format_ciphertext(output_file, ciphertext)
wrapped_ciphertext = ciphertext.scan(/.{1,64}/).join("\n")
output_file.puts('-----BEGIN TRUSTWORTHY ENCRYPTED FILE-----')
output_file.puts("Version: Trustworthy/#{Trustworthy::VERSION}")
output_file.puts
output_file.puts(wrapped_ciphertext)
output_file.puts('-----END TRUSTWORTHY ENCRYPTED FILE-----')
end
|
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/trustworthy/cli/encrypt.rb', line 11
def _transform(prompt, options, input_file)
plaintext = input_file.read
master_key = prompt.unlock_master_key
ciphertext = master_key.encrypt(plaintext)
File.open(options[:output_file], 'wb+') do |output_file|
_format_ciphertext(output_file, ciphertext)
end
say("Encrypted #{options[:input_file]} to #{options[:output_file]}")
end
|