Module: Glueby::Util::Digest

Defined in:
lib/glueby/util/digest.rb

Instance Method Summary collapse

Instance Method Details

#digest_content(content, digest) ⇒ String

Hash content with specified digest algorithm

Parameters:

  • content (String)

    content to be hashed

  • digest (Symbol)

    The symbol represents algorithm used for hashing. :sha256, :double_sha256, :none are available

Returns:

  • (String)

    hex string hashed from content



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/glueby/util/digest.rb', line 9

def digest_content(content, digest)
  case digest&.downcase
  when :sha256
    Tapyrus.sha256(content).bth
  when :double_sha256
    Tapyrus.double_sha256(content).bth
  when :none
    content
  else
    raise Glueby::Contract::Errors::UnsupportedDigestType
  end
end