Class: Deidentify::BaseHash

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

Class Method Summary collapse

Class Method Details

.call(old_value, length: nil) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/deidentify/base_hash.rb', line 5

def self.call(old_value, length: nil)
  return old_value unless old_value.present?

  salt = Deidentify.configuration.salt

  raise Deidentify::Error, 'You must specify the salting value in the configuration' if salt.blank?

  hash = Digest::SHA256.hexdigest(old_value + salt)

  hash = hash[0, length] if length.present? && length < hash.length

  hash
end