Sha256: 0d3bd2cdf6369646af3752ae7b0753eed5b2fd063b539b0015e9f34d52d69cc4

Contents?: true

Size: 1.05 KB

Versions: 50

Compression:

Stored size: 1.05 KB

Contents

begin
  require "openssl"
rescue LoadError
end
require "test/unit"

if defined?(OpenSSL)

class OpenSSL::TestHMAC < Test::Unit::TestCase
  def setup
    @digest = OpenSSL::Digest::MD5.new
    @key = "KEY"
    @data = "DATA"
    @h1 = OpenSSL::HMAC.new(@key, @digest)
    @h2 = OpenSSL::HMAC.new(@key, @digest)
  end

  def teardown
  end

  def test_hmac
    @h1.update(@data)
    assert_equal(OpenSSL::HMAC.digest(@digest, @key, @data), @h1.digest, "digest")
    assert_equal(OpenSSL::HMAC.hexdigest(@digest, @key, @data), @h1.hexdigest, "hexdigest")
  end

  def test_dup
    @h1.update(@data)
    h = @h1.dup
    assert_equal(@h1.digest, h.digest, "dup digest")
  end

  def test_sha256
    digest256 = OpenSSL::Digest::Digest.new("sha256")
    assert_equal(
      "\210\236-\3270\331Yq\265\177sE\266\231hXa\332\250\026\235O&c*\307\001\227~\260n\362",
      OpenSSL::HMAC.digest(digest256, 'blah', "blah"))
    assert_equal(
      "889e2dd730d95971b57f7345b699685861daa8169d4f26632ac701977eb06ef2",
      OpenSSL::HMAC.hexdigest(digest256, 'blah', "blah"))
  end
end

end

Version data entries

50 entries across 50 versions & 5 rubygems

Version Path
jruby-jruby-openssl-0.5.0.4 test/openssl/test_hmac.rb
redcar-dev-0.12.1dev-java lib/openssl/test/openssl/test_hmac.rb
redcar-dev-0.12.0dev-java lib/openssl/test/openssl/test_hmac.rb
redcar-0.11 lib/openssl/test/openssl/test_hmac.rb
redcar-0.11.0dev lib/openssl/test/openssl/test_hmac.rb
redcar-0.10 lib/openssl/test/openssl/test_hmac.rb
redcar-0.9.2 lib/openssl/test/openssl/test_hmac.rb
redcar-0.9.1 lib/openssl/test/openssl/test_hmac.rb
redcar-0.9.0 lib/openssl/test/openssl/test_hmac.rb
redcar-0.8.1 lib/openssl/test/openssl/test_hmac.rb
redcar-0.8 lib/openssl/test/openssl/test_hmac.rb
redcar-0.7 lib/openssl/test/openssl/test_hmac.rb
redcar-0.6.1 lib/openssl/test/openssl/test_hmac.rb
redcar-0.6 lib/openssl/test/openssl/test_hmac.rb
redcar-0.6.1dev lib/openssl/test/openssl/test_hmac.rb
redcar-0.5.1 lib/openssl/test/openssl/test_hmac.rb
redcar-0.5 lib/openssl/test/openssl/test_hmac.rb
redcar-0.5.6dev lib/openssl/test/openssl/test_hmac.rb
redcar-0.5.5dev lib/openssl/test/openssl/test_hmac.rb
redcar-0.5.4dev lib/openssl/test/openssl/test_hmac.rb