Class: KmsTools::CLI::Decrypt
- Inherits:
-
Object
- Object
- KmsTools::CLI::Decrypt
- Defined in:
- lib/kms-tools/cli/decrypt.rb
Overview
Class for handling decrypt operations from the CLI
Instance Method Summary collapse
-
#decrypt(source) ⇒ String
Handle decrypt command.
-
#decrypt_file(source) ⇒ String
Decrypt a file from source path.
-
#initialize(global_options, options) ⇒ Decrypt
constructor
Set up decryption handler.
Constructor Details
Instance Method Details
#decrypt(source) ⇒ String
Handle decrypt command
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kms-tools/cli/decrypt.rb', line 22 def decrypt(source) if File.file?(source) save_path = decrypt_file(source) Output.say("Decrypted file saved to: #{save_path}") elsif source.is_a?(String) decrypted_response = @dec.decrypt_string(source) if STDIN.tty? Output.say("Decrypted string:\n\n#{decrypted_response}\n\n") else print decrypted_response end else raise "Unknown input to encrypt..." end source = nil end |
#decrypt_file(source) ⇒ String
Decrypt a file from source path
43 44 45 46 47 48 49 50 51 |
# File 'lib/kms-tools/cli/decrypt.rb', line 43 def decrypt_file(source) ef = KmsTools::EncryptedFile.new(path: source) save_path = Helpers::get_save_path({ :prompt => "Save decrytped file to", :suggested_path => File.absolute_path(source.sub File.extname(source), ef.original_extension) }) ef.save_decrypted(save_path) save_path end |