Skip to content

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

stdlib/openssl/0/openssl.rbs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3665,6 +3665,23 @@ module OpenSSL
36653665
#
36663666
def self.hexdigest: (String | Digest algo, String key, String data) -> String
36673667

3668+
# <!--
3669+
# rdoc-file=ext/openssl/lib/openssl/hmac.rb
3670+
# - HMAC.base64digest(digest, key, data) -> aString
3671+
# -->
3672+
# Returns the authentication code as a Base64-encoded string. The *digest*
3673+
# parameter specifies the digest algorithm to use. This may be a String
3674+
# representing the algorithm name or an instance of OpenSSL::Digest.
3675+
#
3676+
# ### Example
3677+
# key = 'key'
3678+
# data = 'The quick brown fox jumps over the lazy dog'
3679+
#
3680+
# hmac = OpenSSL::HMAC.base64digest('SHA1', key, data)
3681+
# #=> "3nybhbi3iqa8ino29wqQcBydtNk="
3682+
#
3683+
def self.base64digest: (String | Digest algo, String key, String data) -> String
3684+
36683685
# <!-- rdoc-file=ext/openssl/ossl_hmac.c -->
36693686
# Returns *hmac* updated with the message to be authenticated. Can be called
36703687
# repeatedly with chunks of the message.
@@ -3712,6 +3729,14 @@ module OpenSSL
37123729
#
37133730
def hexdigest: () -> String
37143731

3732+
# <!--
3733+
# rdoc-file=ext/openssl/lib/openssl/hmac.rb
3734+
# - hmac.base64digest -> string
3735+
# -->
3736+
# Returns the authentication code an a Base64-encoded string.
3737+
#
3738+
def base64digest: () -> String
3739+
37153740
# <!-- rdoc-file=ext/openssl/lib/openssl/hmac.rb -->
37163741
# Returns the authentication code as a hex-encoded string. The *digest*
37173742
# parameter specifies the digest algorithm to use. This may be a String

test/stdlib/OpenSSL_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ def test_hexdigest
525525
assert_send_type "(String, String, String) -> String",
526526
OpenSSL::HMAC, :hexdigest, "SHA256", "key", "data"
527527
end
528+
529+
def test_base64digest
530+
assert_send_type "(String, String, String) -> String",
531+
OpenSSL::HMAC, :base64digest, "SHA256", "key", "data"
532+
end
528533
end
529534

530535
class OpenSSLHMACTest < Test::Unit::TestCase
@@ -542,6 +547,11 @@ def test_hexdigest
542547
hmac, :hexdigest
543548
end
544549

550+
def test_base64digest
551+
assert_send_type "() -> String",
552+
hmac, :base64digest
553+
end
554+
545555
def test_reset
546556
assert_send_type "() -> OpenSSL::HMAC",
547557
hmac, :reset

0 commit comments

Comments
 (0)