From fca4c65e7333c33ebe603ac012404e24ff3ba096 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Tue, 18 Jun 2024 18:57:05 +0100 Subject: [PATCH] use optional record keys for several API options --- stdlib/cgi/0/core.rbs | 8 ++- stdlib/csv/0/csv.rbs | 40 +++++++++-- stdlib/date/0/date.rbs | 16 +++-- stdlib/json/0/json.rbs | 2 +- stdlib/net-http/0/manifest.yaml | 1 + stdlib/net-http/0/net-http.rbs | 25 ++++++- stdlib/openssl/0/openssl.rbs | 123 ++++++++++++++++++++++++++++++-- stdlib/resolv/0/resolv.rbs | 18 +++-- stdlib/uri/0/file.rbs | 7 +- stdlib/uri/0/generic.rbs | 20 ++++-- stdlib/uri/0/http.rbs | 11 ++- stdlib/uri/0/ldap.rbs | 12 +++- stdlib/uri/0/mailto.rbs | 11 ++- test/stdlib/Date_test.rb | 12 ++-- test/stdlib/resolv/DNS_test.rb | 6 +- 15 files changed, 267 insertions(+), 45 deletions(-) diff --git a/stdlib/cgi/0/core.rbs b/stdlib/cgi/0/core.rbs index aea53b09a..4fbeec26c 100644 --- a/stdlib/cgi/0/core.rbs +++ b/stdlib/cgi/0/core.rbs @@ -273,6 +273,12 @@ class CGI extend CGI::Util + type options_hash = { + ?accept_charset: String, + ?tag_maker: String, + ?max_multipart_length: Integer | ^() -> Integer + } + # # The base exception for JSON errors. diff --git a/stdlib/net-http/0/manifest.yaml b/stdlib/net-http/0/manifest.yaml index ff82a251c..5c902cc28 100644 --- a/stdlib/net-http/0/manifest.yaml +++ b/stdlib/net-http/0/manifest.yaml @@ -1,3 +1,4 @@ dependencies: - name: net-protocol - name: uri + - name: openssl diff --git a/stdlib/net-http/0/net-http.rbs b/stdlib/net-http/0/net-http.rbs index ad3732c75..6064837bc 100644 --- a/stdlib/net-http/0/net-http.rbs +++ b/stdlib/net-http/0/net-http.rbs @@ -913,6 +913,27 @@ module Net # def self.https_default_port: () -> Integer + type start_options = { + ?ca_file: String, + ?ca_path: String, + ?cert: OpenSSL::X509::Certificate, + ?cert_store: OpenSSL::X509::Store, + ?ciphers: Array[String], + ?close_on_empty_response: bool, + ?ipaddr: String, + ?keep_alive_timeout: Numeric, + ?key: OpenSSL::PKey::PKey, + ?open_timeout: Numeric, + ?read_timeout: Numeric, + ?ssl_timeout: Numeric, + ?ssl_version: OpenSSL::SSL::tls_version, + ?use_ssl: bool, + ?verify_callback: ^(bool preverify_ok, OpenSSL::X509::StoreContext store_ctx) -> boolish, + ?verify_depth: Integer, + ?verify_mode: OpenSSL::SSL::verify_mode, + ?write_timeout: Numeric + } + # + # Sets the list of available TLSv1.3 cipher suites for this context. + # + def ciphersuites=: (Array[[ String, String, Integer, Integer ]] ciphers) -> void + | (Array[String] ciphers) -> void + | (String colon_sep_ciphers) -> void + # # A certificate or Array of certificates that will be sent to the client. # @@ -8139,6 +8191,50 @@ module OpenSSL # def key=: (PKey::PKey) -> PKey::PKey + # + # A callback invoked when TLS key material is generated or received, in order to + # allow applications to store this keying material for debugging purposes. + # + # The callback is invoked with an SSLSocket and a string containing the key + # material in the format used by NSS for its SSLKEYLOGFILE debugging output. + # + # It is only compatible with OpenSSL >= 1.1.1. Even if LibreSSL implements + # SSL_CTX_set_keylog_callback() from v3.4.2, it does nothing (see + # https://github.com/libressl-portable/openbsd/commit/648d39f0f035835d0653342d13 + # 9883b9661e9cb6). + # + # ### Example + # + # context.keylog_cb = proc do |_sock, line| + # File.open('ssl_keylog_file', "a") do |f| + # f.write("#{line}\n") + # end + # end + # + def keylog_cb: () -> (^(SSLSocket sock, String line) -> void)? + + # + # A callback invoked when TLS key material is generated or received, in order to + # allow applications to store this keying material for debugging purposes. + # + # The callback is invoked with an SSLSocket and a string containing the key + # material in the format used by NSS for its SSLKEYLOGFILE debugging output. + # + # It is only compatible with OpenSSL >= 1.1.1. Even if LibreSSL implements + # SSL_CTX_set_keylog_callback() from v3.4.2, it does nothing (see + # https://github.com/libressl-portable/openbsd/commit/648d39f0f035835d0653342d13 + # 9883b9661e9cb6). + # + # ### Example + # + # context.keylog_cb = proc do |_sock, line| + # File.open('ssl_keylog_file', "a") do |f| + # f.write("#{line}\n") + # end + # end + # + def keylog_cb=: (^(SSLSocket sock, String line) -> void) -> ^(SSLSocket sock, String line) -> void + # # An Enumerable of Strings. Each String represents a protocol to be advertised @@ -8195,7 +8291,7 @@ module OpenSSL # # ctx.npn_protocols = ["http/1.1", "spdy/2"] # - def npn_protocols=: (untyped) -> untyped + def npn_protocols=: (Array[String]? protos) -> Array[String] # # A callback invoked on the client side when the client needs to select a @@ -8213,7 +8309,7 @@ module OpenSSL # protocols.first # end # - def npn_select_cb: () -> untyped + def npn_select_cb: () -> (^(Array[String]) -> String? | nil) # # A callback invoked on the client side when the client needs to select a @@ -8231,7 +8327,7 @@ module OpenSSL # protocols.first # end # - def npn_select_cb=: (untyped) -> untyped + def npn_select_cb=: (^(Array[String]) -> String? alpn_select_callback) -> void # # A callback invoked on a server when a session is proposed by the client but @@ -8504,7 +8613,7 @@ module OpenSSL # If the verify_mode is not VERIFY_NONE and ca_file, ca_path and cert_store are # not set then the system default certificate store is used. # - def set_params: (?untyped params) -> untyped + def set_params: (context_params params) -> untyped # diff --git a/stdlib/uri/0/file.rbs b/stdlib/uri/0/file.rbs index 2579819de..b55a5af1c 100644 --- a/stdlib/uri/0/file.rbs +++ b/stdlib/uri/0/file.rbs @@ -4,6 +4,11 @@ module URI # The "file" URI is defined by RFC8089. # class File < Generic + type build_opts = { + ?host: String?, + ?path: String? + } + # # A Default port of nil for URI::File. # @@ -47,7 +52,7 @@ module URI # uri3.to_s # => "file:///path/my%20file.txt" # def self.build: (Array[String] args) -> URI::File - | ({ host: String?, path: String? }) -> URI::File + | (build_opts args) -> URI::File # # A Default port of nil for URI::Generic. # @@ -153,8 +165,8 @@ module URI # URI::Generic::build. But, if exception URI::InvalidComponentError is raised, # then it does URI::Escape.escape all URI components and tries again. # - def self.build2: (Array[nil | String | Integer]) -> URI::Generic - | ({ scheme: String?, userinfo: String?, host: String?, port: Integer?, registry: String?, path: String?, opaque: String?, query: String?, fragment: String? }) -> instance + def self.build2: (Array[nil | String | Integer] args) -> URI::Generic + | (build_opts args) -> instance # # A Default port of 80 for URI::HTTP. # @@ -46,7 +55,7 @@ module URI # URIs as per RFC 1738. # def self.build: (Array[String | Integer] args) -> instance - | ({ userinfo: String?, host: String?, port: Integer?, path: String?, query: String?, fragment: String? }) -> instance + | (build_opts args) -> instance # # A Default port of 389 for URI::LDAP. # @@ -50,7 +60,7 @@ module URI # "/dc=example;dc=com", "query", nil, nil, nil]) # def self.build: (Array[nil | String | Integer] args) -> URI::LDAP - | ({ host: String?, port: Integer?, dn: String?, attributes: String?, scope: String?, filter: String?, extensions: String? }) -> URI::LDAP + | (build_opts args) -> URI::LDAP # # E-mail headers set by the URL, as an Array of Arrays. diff --git a/test/stdlib/Date_test.rb b/test/stdlib/Date_test.rb index ce4ccb01c..c40bb25f4 100644 --- a/test/stdlib/Date_test.rb +++ b/test/stdlib/Date_test.rb @@ -21,17 +21,17 @@ def test_new end def test__httpdate - assert_send_type "(::String str) -> ::Hash[Symbol, Integer]", + assert_send_type "(::String str, ?limit: Integer) -> Date::datetime_with_timezone_record", Date, :_httpdate, "Sat Aug 15 00:00:00 2020" end def test__iso8601 - assert_send_type "(::String str) -> ::Hash[Symbol, Integer]", + assert_send_type "(::String str, ?limit: Integer) -> ::Hash[Symbol, Integer]", Date, :_iso8601, "2020-08-15" end def test__jisx0301 - assert_send_type "(::String str) -> ::Hash[Symbol, Integer]", + assert_send_type "(::String str, ?limit: Integer) -> ::Hash[Symbol, Integer]", Date, :_jisx0301, "2020-08-15" end @@ -43,17 +43,17 @@ def test__parse end def test__rfc2822 - assert_send_type "(::String str) -> ::Hash[Symbol, Integer | String]", + assert_send_type "(::String str, ?limit: Integer) -> Date::datetime_with_timezone_record", Date, :_rfc2822, "Sat Aug 15 2020 00:00:00 +09:00" end def test__rfc3339 - assert_send_type "(::String str) -> ::Hash[Symbol, Integer | String]", + assert_send_type "(::String str, ?limit: Integer) -> Date::datetime_with_timezone_record", Date, :_rfc3339, "2020-08-15T00:00:00+09:00" end def test__rfc822 - assert_send_type "(::String str) -> ::Hash[Symbol, Integer | String]", + assert_send_type "(::String str, ?limit: Integer) -> Date::datetime_with_timezone_record", Date, :_rfc822, "Sat Aug 15 2020 00:00:00 +09:00" end diff --git a/test/stdlib/resolv/DNS_test.rb b/test/stdlib/resolv/DNS_test.rb index e79b62b9e..f3c466c13 100644 --- a/test/stdlib/resolv/DNS_test.rb +++ b/test/stdlib/resolv/DNS_test.rb @@ -163,14 +163,14 @@ class ResolvDNSConfigSingletonTest < Test::Unit::TestCase testing 'singleton(::Resolv::DNS::Config)' def test_default_config_hash - assert_send_type '() -> Hash[Symbol, untyped]', + assert_send_type '() -> ::Resolv::DNS::config_options', Resolv::DNS::Config, :default_config_hash - assert_send_type '(String) -> Hash[Symbol, untyped]', + assert_send_type '(String) -> ::Resolv::DNS::config_options', Resolv::DNS::Config, :default_config_hash, "/etc/resolv.conf" end def test_parse_resolv_conf - assert_send_type '(String) -> Hash[Symbol, untyped]', + assert_send_type '(String) -> ::Resolv::DNS::config_options', Resolv::DNS::Config, :parse_resolv_conf, "/etc/resolv.conf" end end