Class: EncrApp

Inherits:
Object
  • Object
show all
Includes:
LEnc
Defined in:
lib/lenc/encr.rb

Constant Summary

Constants included from LEnc

LEnc::KEY_LEN_MAX, LEnc::KEY_LEN_MIN

Instance Method Summary collapse

Instance Method Details

#run(argv = ARGV) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lenc/encr.rb', line 6

def run(argv = ARGV) 
   
  req 'trollop'
  p = Trollop::Parser.new do
      opt :init, "create new singular repository"  
      opt :orignames, "(with --init) leave filenames unencrypted"
      opt :encrypt, "encrypt files (default operation)"
      opt :decrypt, "decrypt files"
      opt :key, "encryption key", :type => :string  
      opt :verbose,"verbose operation"
      opt :where, "specify source directory (default = current directory)", :type => :strings
      opt :quiet, "quiet operation"
      opt :dryrun, "show which files will be modified, but make no changes"
  end
  
  options = Trollop::with_standard_exception_handling p do
    p.parse argv
  end
  
  v = 0
  v = -1 if options[:quiet]
  v = 1  if options[:verbose]
  
  nOpt = 0
  nOpt += 1 if options[:init]
  nOpt += 1 if options[:encrypt]
  nOpt += 1 if options[:decrypt]
          
  p.die("Only one operation can be performed at a time.",nil) if nOpt > 1

  r = Repo.new(:dryrun => options[:dryrun], :verbosity => v)
  
  key = options[:key]
    
  begin
    
    if options[:init]
      r.create(options[:where], key, nil, options[:orignames])
    elsif options[:decrypt]
      r.open(options[:where],key)
      r.perform_decrypt
    else
      r.open(options[:where],key)
      r.perform_encrypt
    end

    r.close()
  rescue Exception =>e
    puts("\nProblem encountered: #{e.message}")
  end

end