Class: Worklog::Hasher

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

Overview

Simple hashing utility

Class Method Summary collapse

Class Method Details

.sha256(input, length = 7) ⇒ String

Generate SHA256 hash for the given input string

Parameters:

  • input (String)

    The input string to hash

  • length (Integer) (defaults to: 7)

    The length of the resulting hash (default: 7)

Returns:

  • (String)

    The resulting SHA256 hash in hexadecimal format

Raises:

  • (ArgumentError)

    if length is not between 1 and 64



13
14
15
16
17
# File 'lib/hasher.rb', line 13

def self.sha256(input, length = 7)
  raise ArgumentError, 'Length must be between 1 and 64' unless length.between?(1, 64)

  Digest::SHA256.hexdigest(input)[..(length - 1)]
end