Class: Conceal::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/conceal/cli.rb

Instance Method Summary collapse

Instance Method Details

#decrypt(key_file) ⇒ Object

Raises:

  • (Thor::Error)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/conceal/cli.rb', line 11

def decrypt(key_file)
  require 'conceal'

  # load the key
  raise Thor::Error, 'ERROR: key file is not readable or does not exist' unless File.readable?(key_file)
  key = IO.read(key_file)

  # decrypt from stdin
  encrypted_data = $stdin.read
  plaintext = Conceal.decrypt(encrypted_data, key: key)

  $stdout.write(plaintext)
  $stdout.write("\n") if options[:newline]
end

#encrypt(key_file) ⇒ Object

Raises:

  • (Thor::Error)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/conceal/cli.rb', line 28

def encrypt(key_file)
  require 'conceal'

  # load the key
  raise Thor::Error, 'ERROR: key file is not readable or does not exist' unless File.readable?(key_file)
  key = IO.read(key_file)

  # encrypt from stdin
  plaintext = $stdin.read
  encrypted_data = Conceal.encrypt(plaintext, key: key)

  $stdout.write(encrypted_data)
  $stdout.write("\n") if options[:newline]
end

#versionObject



44
45
46
47
# File 'lib/conceal/cli.rb', line 44

def version
  require 'conceal/version'
  puts VERSION
end