Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e27c8b

Browse files
committed
Merge pull request #187 from eitoball/change_openssl_hmac_digest_encoding_to_binary
Change encoding of OpenSSL::HMAC.digest result to binary
2 parents 963af2b + 05c8514 commit 4e27c8b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/openssl/ossl_hmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ ossl_hmac_s_digest(VALUE klass, SEL sel, VALUE digest, VALUE key, VALUE data)
201201
buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
202202
(unsigned char *)RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
203203

204-
return rb_str_new((const char *)buf, buf_len);
204+
return rb_bstr_new_with_data((UInt8 *)buf, buf_len);
205205
}
206206

207207
/*

test-mri/test/openssl/test_hmac.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def test_hmac
2828
assert_equal(OpenSSL::HMAC.hexdigest("MD5", @key, @data), @h2.hexdigest, "hexdigest")
2929
end
3030

31+
def test_hmac_digest_encoding
32+
assert_equal(Encoding::BINARY, OpenSSL::HMAC.digest("SHA1", @key, @data).encoding)
33+
end
34+
3135
def test_dup
3236
@h1.update(@data)
3337
h = @h1.dup

0 commit comments

Comments
 (0)