From da6925e8cba9764067f7e4351879f83ce164619e Mon Sep 17 00:00:00 2001 From: dak2 Date: Wed, 6 Nov 2024 21:28:26 +0900 Subject: [PATCH] stdlib: Add types for base64digest of openssl refs: - https://github.com/ruby/openssl/blob/bd647c3b05513fe8782d8246b9b7a03381b67eaf/lib/openssl/hmac.rb#L13-L19 - https://docs.ruby-lang.org/en/master/OpenSSL/HMAC.html#method-i-base64digest - https://github.com/ruby/openssl/blob/bd647c3b05513fe8782d8246b9b7a03381b67eaf/lib/openssl/hmac.rb#L60-L75 - https://docs.ruby-lang.org/en/master/OpenSSL/HMAC.html#method-c-base64digest --- stdlib/openssl/0/openssl.rbs | 25 +++++++++++++++++++++++++ test/stdlib/OpenSSL_test.rb | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/stdlib/openssl/0/openssl.rbs b/stdlib/openssl/0/openssl.rbs index 7e0709910..2cf6d9d2c 100644 --- a/stdlib/openssl/0/openssl.rbs +++ b/stdlib/openssl/0/openssl.rbs @@ -3665,6 +3665,23 @@ module OpenSSL # def self.hexdigest: (String | Digest algo, String key, String data) -> String + # + # Returns the authentication code as a Base64-encoded string. The *digest* + # parameter specifies the digest algorithm to use. This may be a String + # representing the algorithm name or an instance of OpenSSL::Digest. + # + # ### Example + # key = 'key' + # data = 'The quick brown fox jumps over the lazy dog' + # + # hmac = OpenSSL::HMAC.base64digest('SHA1', key, data) + # #=> "3nybhbi3iqa8ino29wqQcBydtNk=" + # + def self.base64digest: (String | Digest algo, String key, String data) -> String + # # Returns *hmac* updated with the message to be authenticated. Can be called # repeatedly with chunks of the message. @@ -3712,6 +3729,14 @@ module OpenSSL # def hexdigest: () -> String + # + # Returns the authentication code an a Base64-encoded string. + # + def base64digest: () -> String + # # Returns the authentication code as a hex-encoded string. The *digest* # parameter specifies the digest algorithm to use. This may be a String diff --git a/test/stdlib/OpenSSL_test.rb b/test/stdlib/OpenSSL_test.rb index 76645ccf7..28a64aadb 100644 --- a/test/stdlib/OpenSSL_test.rb +++ b/test/stdlib/OpenSSL_test.rb @@ -525,6 +525,11 @@ def test_hexdigest assert_send_type "(String, String, String) -> String", OpenSSL::HMAC, :hexdigest, "SHA256", "key", "data" end + + def test_base64digest + assert_send_type "(String, String, String) -> String", + OpenSSL::HMAC, :base64digest, "SHA256", "key", "data" + end end class OpenSSLHMACTest < Test::Unit::TestCase @@ -542,6 +547,11 @@ def test_hexdigest hmac, :hexdigest end + def test_base64digest + assert_send_type "() -> String", + hmac, :base64digest + end + def test_reset assert_send_type "() -> OpenSSL::HMAC", hmac, :reset