Class: H::Builder

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

Overview

Builder handles the creation of salted password hashes using SHA-256

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ Builder

Initialize a new Builder with a secret salt

Parameters:

  • secret (Object)

    the salt to use for hashing (will be converted to String)



17
18
19
20
21
# File 'lib/h.rb', line 17

def initialize(secret)
  @secret = String(secret)

  freeze
end

Instance Attribute Details

#secretString (readonly)

Returns the secret salt used for hashing.

Returns:

  • (String)

    the secret salt used for hashing



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

def secret
  @secret
end

Instance Method Details

#call(value) ⇒ String

Generate a salted hash of the provided value

Parameters:

  • value (String)

    the value to hash

Returns:

  • (String)

    Base64 encoded SHA-256 hash



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

def call(value)
  ::Digest::SHA256.base64digest("#{value}++#{secret}")
end