summaryrefslogtreecommitdiff
path: root/lib/metropolis/multi_hash/digest.rb
blob: 56264aa0bdab4a07e4a4fb0c770c1b7656eab015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- encoding: binary -*-
require 'digest'
module Metropolis::MultiHash::Digest
  N = "N"

  def digest_sha1(key)
    ::Digest::SHA1.digest(key)[0,4].unpack(N)[0]
  end

  def digest_md5(key)
    ::Digest::MD5.digest(key)[0,4].unpack(N)[0]
  end

  def digest_sha256(key)
    ::Digest::SHA256.digest(key)[0,4].unpack(N)[0]
  end

  def digest_sha384(key)
    ::Digest::SHA384.digest(key)[0,4].unpack(N)[0]
  end

  def digest_sha512(key)
    ::Digest::SHA512.digest(key)[0,4].unpack(N)[0]
  end
end