Class: PHash

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_function, secret, seed, key_length = 32) ⇒ PHash

Returns a new instance of PHash.



7
8
9
10
11
12
13
# File 'lib/p_hash.rb', line 7

def initialize(hash_function, secret, seed, key_length = 32)
  @hash_function = hash_function
  @secret = secret
  @seed = seed
  @key_length = key_length
  calculate_digest
end

Instance Attribute Details

#digestObject (readonly)

Returns the value of attribute digest.



5
6
7
# File 'lib/p_hash.rb', line 5

def digest
  @digest
end

#hash_functionObject (readonly)

Returns the value of attribute hash_function.



5
6
7
# File 'lib/p_hash.rb', line 5

def hash_function
  @hash_function
end

#key_lengthObject (readonly)

Returns the value of attribute key_length.



5
6
7
# File 'lib/p_hash.rb', line 5

def key_length
  @key_length
end

#secretObject (readonly)

Returns the value of attribute secret.



5
6
7
# File 'lib/p_hash.rb', line 5

def secret
  @secret
end

#seedObject (readonly)

Returns the value of attribute seed.



5
6
7
# File 'lib/p_hash.rb', line 5

def seed
  @seed
end

Instance Method Details

#base64digestObject



19
20
21
# File 'lib/p_hash.rb', line 19

def base64digest
  @base64digest ||= Base64.strict_encode64(digest)
end

#hexdigestObject



15
16
17
# File 'lib/p_hash.rb', line 15

def hexdigest
  @hexdigest ||= digest.unpack('H*').first
end