Class: H::Generator

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

Overview

Class that generates cryptographic hash

Instance Method Summary collapse

Constructor Details

#initialize(static_key) ⇒ H::Generator

Initialize a H instance.

Parameters:

  • static_key (String)

    a random data



13
14
15
# File 'lib/h.rb', line 13

def initialize(static_key)
  @static_key = static_key
end

Instance Method Details

#input(m, l) ⇒ String

Return a hash of l length.

Parameters:

  • m (String)

    a message

  • l (Fixnum)

    the length of the returned string

Returns:

  • (String)

    salted cryptographic hash.



25
26
27
28
29
# File 'lib/h.rb', line 25

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