Skip to content

Commit

Permalink
Make OpenSSL::HMAC act like a string so it can be used with fixed_len…
Browse files Browse the repository at this point in the history
…gth_secure_compare
  • Loading branch information
bdewater committed Nov 2, 2019
1 parent 8382136 commit b0f0ada
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/openssl/ossl_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
Expand Down
1 change: 1 addition & 0 deletions lib/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions lib/openssl/hmac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module OpenSSL
class HMAC
def to_str
digest
end
end
end
8 changes: 8 additions & 0 deletions test/test_hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b0f0ada

Please sign in to comment.