Top Level Namespace

Includes:
Contracts

Defined Under Namespace

Modules: IOS7Crypt Classes: String

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.testObject



90
91
92
93
# File 'lib/ios7crypt.rb', line 90

def self.test
  prop_reversible = -> s { s == s.encrypt.decrypt }
  RubyCheck.for_all(prop_reversible, [:gen_str])
end

Instance Method Details

#mainObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ios7crypt.rb', line 95

def main
  mode = :usage

  password = ''
  hash = ''

  opts = GetoptLong.new(
    ['--help', '-h', GetoptLong::NO_ARGUMENT],
    ['--version', '-v', GetoptLong::NO_ARGUMENT],
    ['--encrypt', '-e', GetoptLong::REQUIRED_ARGUMENT],
    ['--decrypt', '-d', GetoptLong::REQUIRED_ARGUMENT],
    ['--test', '-t', GetoptLong::NO_ARGUMENT]
  )

  opts.each do |option, value|
    case option
    when '--help'
      usage
    when '--encrypt'
      mode = :encrypt
      password = value
    when '--decrypt'
      mode = :decrypt
      hash = value
    when '--test'
      mode = :test
    when '--version'
      puts "ios7crypt #{IOS7Crypt::VERSION}"
      exit 0
    else
      usage
    end
  end

  case mode
  when :usage
    usage
  when :encrypt
    puts password.encrypt
  when :decrypt
    puts hash.decrypt
  when :test
    test
  else
    usage
  end
end

#usageObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ios7crypt.rb', line 12

def usage
  puts "#{$PROGRAM_NAME} [OPTIONS]

--encrypt, -e <password>
    prints out the encrypted password as a hash

--decrypt, -d <hash>
    prints out the decrypted hash as a password

--test, -t
    runs unit tests

--help, -h:
    show help

--version, -v:
    show version"

  exit 0
end