Class: H::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/h.rb

Constant Summary collapse

CONF_PATH =
File.join(File.expand_path('~'), '.h')

Instance Method Summary collapse

Constructor Details

#initialize(static_key = nil) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/h.rb', line 8

def initialize(static_key = nil)
  @static_key = if static_key
    static_key
  else
    unless File.exists?(CONF_PATH)
      print "Creating #{CONF_PATH} file... "

      File.open(CONF_PATH, 'w') do |f|
        f.write('secret')
      end

      File.chmod(0600, CONF_PATH)

      puts "Done."
    end

    File.open(CONF_PATH).readlines.first.chomp
  end
end

Instance Method Details

#input(m, l = 44) ⇒ Object



32
33
34
35
36
# File 'lib/h.rb', line 32

def input(m, l = 44)
  m = m + @static_key
  d = cryptographic_hash(m)
  truncate d, l
end

#promptObject



28
29
30
# File 'lib/h.rb', line 28

def prompt
  input ask('Message: ') {|q| q.echo = '*' }
end