diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c index 757754cd9..efbf558b6 100644 --- a/ext/openssl/ossl_hmac.c +++ b/ext/openssl/ossl_hmac.c @@ -94,9 +94,9 @@ ossl_hmac_alloc(VALUE klass) * instance == other_instance * #=> false * - * Use #digest and compare in constant time: + * Instead, compare in constant time: * - * OpenSSL.fixed_length_secure_compare(instance.digest, other_instance.digest) + * OpenSSL.fixed_length_secure_compare(instance, other_instance) * #=> true * */ diff --git a/lib/openssl.rb b/lib/openssl.rb index ec143bc74..be2969557 100644 --- a/lib/openssl.rb +++ b/lib/openssl.rb @@ -17,6 +17,7 @@ require_relative 'openssl/cipher' require_relative 'openssl/config' require_relative 'openssl/digest' +require_relative 'openssl/hmac' require_relative 'openssl/x509' require_relative 'openssl/ssl' require_relative 'openssl/pkcs5' diff --git a/lib/openssl/hmac.rb b/lib/openssl/hmac.rb new file mode 100644 index 000000000..d974aa3f7 --- /dev/null +++ b/lib/openssl/hmac.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module OpenSSL + class HMAC + def to_str + digest + end + end +end diff --git a/test/test_hmac.rb b/test/test_hmac.rb index 831a5b6b3..66d4f385e 100644 --- a/test/test_hmac.rb +++ b/test/test_hmac.rb @@ -39,6 +39,14 @@ def test_reset_keep_key second = h1.update("test").hexdigest assert_equal first, second end + + def test_to_str + h1 = OpenSSL::HMAC.new("KEY", "SHA1") + assert_equal h1.digest, h1.to_str + + h2 = OpenSSL::HMAC.new("KEY", "SHA1") + assert_equal h1.to_str, h2.to_str + end end end