Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib: Add types for base64digest of openssl #2078

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions stdlib/openssl/0/openssl.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3665,6 +3665,23 @@ module OpenSSL
#
def self.hexdigest: (String | Digest algo, String key, String data) -> String

# <!--
# rdoc-file=ext/openssl/lib/openssl/hmac.rb
# - HMAC.base64digest(digest, key, data) -> aString
# -->
# 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

# <!-- rdoc-file=ext/openssl/ossl_hmac.c -->
# Returns *hmac* updated with the message to be authenticated. Can be called
# repeatedly with chunks of the message.
Expand Down Expand Up @@ -3712,6 +3729,14 @@ module OpenSSL
#
def hexdigest: () -> String

# <!--
# rdoc-file=ext/openssl/lib/openssl/hmac.rb
# - hmac.base64digest -> string
# -->
# Returns the authentication code an a Base64-encoded string.
#
def base64digest: () -> String

# <!-- rdoc-file=ext/openssl/lib/openssl/hmac.rb -->
# Returns the authentication code as a hex-encoded string. The *digest*
# parameter specifies the digest algorithm to use. This may be a String
Expand Down
10 changes: 10 additions & 0 deletions test/stdlib/OpenSSL_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading