Sha256: f2915eba1fc898bb0e46f3ae0867379178d8c6da8b7af0924cf058c0523eabee

Contents?: true

Size: 505 Bytes

Versions: 8

Compression:

Stored size: 505 Bytes

Contents

require "openssl"

module OTP
  module Utils
    private

    def pack_int64(i)
      return [i >> 32 & 0xffffffff, i & 0xffffffff].pack("NN")
    end

    def hmac(algorithm, secret, text)
      mac = OpenSSL::HMAC.new(secret, algorithm)
      mac << text
      return mac.digest
    end

    def truncate(hash)
      offset = hash[-1].ord & 0xf
      binary = hash[offset, 4]
      return binary.unpack("N")[0] & 0x7fffffff
    end

    def compare(a, b)
      return a.to_i == b.to_i
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
otp-0.0.9 lib/otp/utils.rb
otp-0.0.8 lib/otp/utils.rb
otp-0.0.7 lib/otp/utils.rb
otp-0.0.6 lib/otp/utils.rb
otp-0.0.5 lib/otp/utils.rb
otp-0.0.4 lib/otp/utils.rb
otp-0.0.3 lib/otp/utils.rb
otp-0.0.2 lib/otp/utils.rb