rbs 3.9.5 → 3.10.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/ruby.yml +34 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/README.md +38 -1
  11. data/Rakefile +152 -23
  12. data/config.yml +190 -62
  13. data/core/array.rbs +44 -43
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +3 -2
  16. data/core/enumerable.rbs +89 -2
  17. data/core/errno.rbs +8 -0
  18. data/core/errors.rbs +28 -1
  19. data/core/exception.rbs +2 -2
  20. data/core/fiber.rbs +3 -3
  21. data/core/file.rbs +26 -11
  22. data/core/float.rbs +1 -1
  23. data/core/gc.rbs +422 -281
  24. data/core/hash.rbs +1024 -727
  25. data/core/io/wait.rbs +11 -33
  26. data/core/io.rbs +6 -4
  27. data/core/kernel.rbs +49 -43
  28. data/core/marshal.rbs +1 -1
  29. data/core/match_data.rbs +1 -1
  30. data/core/math.rbs +42 -3
  31. data/core/method.rbs +14 -6
  32. data/core/module.rbs +71 -11
  33. data/core/nil_class.rbs +3 -3
  34. data/core/numeric.rbs +8 -8
  35. data/core/object.rbs +3 -3
  36. data/core/object_space.rbs +13 -0
  37. data/{stdlib/pathname/0 → core}/pathname.rbs +253 -352
  38. data/core/proc.rbs +15 -8
  39. data/core/process.rbs +2 -2
  40. data/core/ractor.rbs +278 -437
  41. data/core/range.rbs +6 -7
  42. data/core/rbs/unnamed/argf.rbs +1 -1
  43. data/core/rbs/unnamed/env_class.rbs +1 -1
  44. data/core/rbs/unnamed/random.rbs +4 -2
  45. data/core/regexp.rbs +22 -17
  46. data/core/ruby_vm.rbs +6 -4
  47. data/core/rubygems/errors.rbs +3 -70
  48. data/core/rubygems/rubygems.rbs +11 -79
  49. data/core/set.rbs +439 -332
  50. data/core/string.rbs +2897 -1117
  51. data/core/struct.rbs +1 -1
  52. data/core/symbol.rbs +4 -4
  53. data/core/thread.rbs +83 -20
  54. data/core/time.rbs +35 -9
  55. data/core/unbound_method.rbs +14 -6
  56. data/docs/aliases.md +79 -0
  57. data/docs/collection.md +2 -2
  58. data/docs/gem.md +0 -1
  59. data/docs/sigs.md +3 -3
  60. data/ext/rbs_extension/ast_translation.c +1016 -0
  61. data/ext/rbs_extension/ast_translation.h +37 -0
  62. data/ext/rbs_extension/class_constants.c +157 -0
  63. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  64. data/ext/rbs_extension/compat.h +10 -0
  65. data/ext/rbs_extension/extconf.rb +25 -1
  66. data/ext/rbs_extension/legacy_location.c +317 -0
  67. data/ext/rbs_extension/legacy_location.h +45 -0
  68. data/ext/rbs_extension/main.c +365 -14
  69. data/ext/rbs_extension/rbs_extension.h +6 -21
  70. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  71. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  72. data/include/rbs/ast.h +687 -0
  73. data/include/rbs/defines.h +86 -0
  74. data/include/rbs/lexer.h +199 -0
  75. data/include/rbs/location.h +59 -0
  76. data/include/rbs/parser.h +135 -0
  77. data/include/rbs/string.h +49 -0
  78. data/include/rbs/util/rbs_allocator.h +59 -0
  79. data/include/rbs/util/rbs_assert.h +20 -0
  80. data/include/rbs/util/rbs_buffer.h +83 -0
  81. data/include/rbs/util/rbs_constant_pool.h +6 -67
  82. data/include/rbs/util/rbs_encoding.h +282 -0
  83. data/include/rbs/util/rbs_unescape.h +23 -0
  84. data/include/rbs.h +1 -2
  85. data/lib/rbs/annotate/formatter.rb +3 -13
  86. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  87. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  88. data/lib/rbs/cli/validate.rb +2 -2
  89. data/lib/rbs/cli.rb +1 -1
  90. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  91. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  92. data/lib/rbs/environment.rb +64 -59
  93. data/lib/rbs/environment_loader.rb +1 -1
  94. data/lib/rbs/errors.rb +1 -1
  95. data/lib/rbs/parser_aux.rb +5 -0
  96. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  97. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  98. data/lib/rbs/test/type_check.rb +13 -0
  99. data/lib/rbs/types.rb +3 -1
  100. data/lib/rbs/version.rb +1 -1
  101. data/lib/rbs.rb +1 -1
  102. data/lib/rdoc/discover.rb +1 -1
  103. data/lib/rdoc_plugin/parser.rb +3 -3
  104. data/sig/annotate/formatter.rbs +2 -2
  105. data/sig/annotate/rdoc_annotater.rbs +1 -1
  106. data/sig/environment.rbs +57 -6
  107. data/sig/manifest.yaml +0 -1
  108. data/sig/parser.rbs +20 -0
  109. data/sig/resolver/type_name_resolver.rbs +38 -7
  110. data/sig/types.rbs +4 -1
  111. data/src/ast.c +1256 -0
  112. data/src/lexer.c +2956 -0
  113. data/src/lexer.re +147 -0
  114. data/src/lexstate.c +205 -0
  115. data/src/location.c +71 -0
  116. data/src/parser.c +3495 -0
  117. data/src/string.c +90 -0
  118. data/src/util/rbs_allocator.c +152 -0
  119. data/src/util/rbs_assert.c +21 -0
  120. data/src/util/rbs_buffer.c +54 -0
  121. data/src/util/rbs_constant_pool.c +16 -86
  122. data/src/util/rbs_encoding.c +21308 -0
  123. data/src/util/rbs_unescape.c +131 -0
  124. data/stdlib/cgi/0/core.rbs +2 -396
  125. data/stdlib/cgi/0/manifest.yaml +1 -0
  126. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  127. data/stdlib/coverage/0/coverage.rbs +3 -1
  128. data/stdlib/delegate/0/delegator.rbs +10 -7
  129. data/stdlib/erb/0/erb.rbs +737 -347
  130. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  131. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  132. data/stdlib/json/0/json.rbs +67 -48
  133. data/stdlib/net-http/0/net-http.rbs +3 -0
  134. data/stdlib/objspace/0/objspace.rbs +8 -3
  135. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  136. data/stdlib/openssl/0/openssl.rbs +182 -149
  137. data/stdlib/optparse/0/optparse.rbs +3 -3
  138. data/stdlib/rdoc/0/code_object.rbs +2 -2
  139. data/stdlib/rdoc/0/comment.rbs +2 -0
  140. data/stdlib/rdoc/0/options.rbs +76 -0
  141. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  142. data/stdlib/rdoc/0/store.rbs +1 -1
  143. data/stdlib/resolv/0/resolv.rbs +25 -68
  144. data/stdlib/ripper/0/ripper.rbs +5 -2
  145. data/stdlib/singleton/0/singleton.rbs +3 -0
  146. data/stdlib/socket/0/socket.rbs +13 -1
  147. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  148. data/stdlib/stringio/0/stringio.rbs +412 -80
  149. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  150. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  151. data/stdlib/tsort/0/cyclic.rbs +3 -0
  152. data/stdlib/uri/0/common.rbs +11 -2
  153. data/stdlib/uri/0/file.rbs +1 -1
  154. data/stdlib/uri/0/generic.rbs +16 -15
  155. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  156. data/stdlib/zlib/0/zstream.rbs +1 -0
  157. metadata +41 -18
  158. data/ext/rbs_extension/lexer.c +0 -2728
  159. data/ext/rbs_extension/lexer.h +0 -179
  160. data/ext/rbs_extension/lexer.re +0 -147
  161. data/ext/rbs_extension/lexstate.c +0 -175
  162. data/ext/rbs_extension/location.c +0 -325
  163. data/ext/rbs_extension/location.h +0 -85
  164. data/ext/rbs_extension/parser.c +0 -2982
  165. data/ext/rbs_extension/parser.h +0 -18
  166. data/ext/rbs_extension/parserstate.c +0 -411
  167. data/ext/rbs_extension/parserstate.h +0 -163
  168. data/ext/rbs_extension/unescape.c +0 -32
  169. data/include/rbs/ruby_objs.h +0 -72
  170. data/src/constants.c +0 -153
  171. data/src/ruby_objs.c +0 -799
@@ -536,6 +536,9 @@ module OpenSSL
536
536
  #
537
537
  OPENSSL_FIPS: bool
538
538
 
539
+ # <!-- rdoc-file=ext/openssl/ossl.c -->
540
+ # Version of OpenSSL the ruby OpenSSL extension is running with
541
+ #
539
542
  OPENSSL_LIBRARY_VERSION: String
540
543
 
541
544
  # <!-- rdoc-file=ext/openssl/ossl.c -->
@@ -2428,24 +2431,28 @@ module OpenSSL
2428
2431
  # prevents malicious modifications of the ciphertext that could otherwise be
2429
2432
  # exploited to modify ciphertexts in ways beneficial to potential attackers.
2430
2433
  #
2431
- # An associated data is used where there is additional information, such as
2432
- # headers or some metadata, that must be also authenticated but not necessarily
2433
- # need to be encrypted. If no associated data is needed for encryption and later
2434
- # decryption, the OpenSSL library still requires a value to be set - "" may be
2435
- # used in case none is available.
2434
+ # Associated data, also called additional authenticated data (AAD), is
2435
+ # optionally used where there is additional information, such as headers or some
2436
+ # metadata, that must be also authenticated but not necessarily need to be
2437
+ # encrypted.
2436
2438
  #
2437
2439
  # An example using the GCM (Galois/Counter Mode). You have 16 bytes *key*, 12
2438
2440
  # bytes (96 bits) *nonce* and the associated data *auth_data*. Be sure not to
2439
2441
  # reuse the *key* and *nonce* pair. Reusing an nonce ruins the security
2440
2442
  # guarantees of GCM mode.
2441
2443
  #
2444
+ # key = OpenSSL::Random.random_bytes(16)
2445
+ # nonce = OpenSSL::Random.random_bytes(12)
2446
+ # auth_data = "authenticated but unencrypted data"
2447
+ # data = "encrypted data"
2448
+ #
2442
2449
  # cipher = OpenSSL::Cipher.new('aes-128-gcm').encrypt
2443
2450
  # cipher.key = key
2444
2451
  # cipher.iv = nonce
2445
2452
  # cipher.auth_data = auth_data
2446
2453
  #
2447
2454
  # encrypted = cipher.update(data) + cipher.final
2448
- # tag = cipher.auth_tag # produces 16 bytes tag by default
2455
+ # tag = cipher.auth_tag(16)
2449
2456
  #
2450
2457
  # Now you are the receiver. You know the *key* and have received *nonce*,
2451
2458
  # *auth_data*, *encrypted* and *tag* through an untrusted network. Note that GCM
@@ -2458,13 +2465,17 @@ module OpenSSL
2458
2465
  # decipher = OpenSSL::Cipher.new('aes-128-gcm').decrypt
2459
2466
  # decipher.key = key
2460
2467
  # decipher.iv = nonce
2461
- # decipher.auth_tag = tag
2468
+ # decipher.auth_tag = tag # could be called at any time before #final
2462
2469
  # decipher.auth_data = auth_data
2463
2470
  #
2464
2471
  # decrypted = decipher.update(encrypted) + decipher.final
2465
2472
  #
2466
2473
  # puts data == decrypted #=> true
2467
2474
  #
2475
+ # Note that other AEAD ciphers may require additional steps, such as setting the
2476
+ # expected tag length (#auth_tag_len=) or the total data length (#ccm_data_len=)
2477
+ # in advance. Make sure to read the relevant man page for details.
2478
+ #
2468
2479
  class Cipher
2469
2480
  # <!--
2470
2481
  # rdoc-file=ext/openssl/ossl_cipher.c
@@ -2476,21 +2487,22 @@ module OpenSSL
2476
2487
 
2477
2488
  # <!--
2478
2489
  # rdoc-file=ext/openssl/ossl_cipher.c
2479
- # - cipher.auth_data = string -> string
2480
- # -->
2481
- # Sets the cipher's additional authenticated data. This field must be set when
2482
- # using AEAD cipher modes such as GCM or CCM. If no associated data shall be
2483
- # used, this method must **still** be called with a value of "". The contents of
2484
- # this field should be non-sensitive data which will be added to the ciphertext
2485
- # to generate the authentication tag which validates the contents of the
2486
- # ciphertext.
2487
- #
2488
- # The AAD must be set prior to encryption or decryption. In encryption mode, it
2489
- # must be set after calling Cipher#encrypt and setting Cipher#key= and
2490
- # Cipher#iv=. When decrypting, the authenticated data must be set after key, iv
2491
- # and especially **after** the authentication tag has been set. I.e. set it only
2492
- # after calling Cipher#decrypt, Cipher#key=, Cipher#iv= and Cipher#auth_tag=
2493
- # first.
2490
+ # - cipher.auth_data = string
2491
+ # -->
2492
+ # Sets additional authenticated data (AAD), also called associated data, for
2493
+ # this Cipher. This method is available for AEAD ciphers.
2494
+ #
2495
+ # The contents of this field should be non-sensitive data which will be added to
2496
+ # the ciphertext to generate the authentication tag which validates the contents
2497
+ # of the ciphertext.
2498
+ #
2499
+ # This method must be called after #key= and #iv= have been set, but before
2500
+ # starting actual encryption or decryption with #update. In some cipher modes,
2501
+ # #auth_tag_len= and #ccm_data_len= may also need to be called before this
2502
+ # method.
2503
+ #
2504
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2505
+ # method internally calls EVP_CipherUpdate() with the output buffer set to NULL.
2494
2506
  #
2495
2507
  def auth_data=: (String) -> String
2496
2508
 
@@ -2498,42 +2510,54 @@ module OpenSSL
2498
2510
  # rdoc-file=ext/openssl/ossl_cipher.c
2499
2511
  # - cipher.auth_tag(tag_len = 16) -> String
2500
2512
  # -->
2501
- # Gets the authentication tag generated by Authenticated Encryption Cipher modes
2502
- # (GCM for example). This tag may be stored along with the ciphertext, then set
2503
- # on the decryption cipher to authenticate the contents of the ciphertext
2504
- # against changes. If the optional integer parameter *tag_len* is given, the
2505
- # returned tag will be *tag_len* bytes long. If the parameter is omitted, the
2506
- # default length of 16 bytes or the length previously set by #auth_tag_len= will
2507
- # be used. For maximum security, the longest possible should be chosen.
2513
+ # Gets the generated authentication tag. This method is available for AEAD
2514
+ # ciphers, and should be called after encryption has been finalized by calling
2515
+ # #final.
2516
+ #
2517
+ # The returned tag will be *tag_len* bytes long. Some cipher modes require the
2518
+ # desired length in advance using a separate call to #auth_tag_len=, before
2519
+ # starting encryption.
2508
2520
  #
2509
- # The tag may only be retrieved after calling Cipher#final.
2521
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2522
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_GET_TAG.
2510
2523
  #
2511
2524
  def auth_tag: (?Integer tag_len) -> String
2512
2525
 
2513
2526
  # <!--
2514
2527
  # rdoc-file=ext/openssl/ossl_cipher.c
2515
- # - cipher.auth_tag = string -> string
2528
+ # - cipher.auth_tag = string
2516
2529
  # -->
2517
- # Sets the authentication tag to verify the integrity of the ciphertext. This
2518
- # can be called only when the cipher supports AE. The tag must be set after
2519
- # calling Cipher#decrypt, Cipher#key= and Cipher#iv=, but before calling
2520
- # Cipher#final. After all decryption is performed, the tag is verified
2521
- # automatically in the call to Cipher#final.
2530
+ # Sets the authentication tag to verify the integrity of the ciphertext.
2531
+ #
2532
+ # The authentication tag must be set before #final is called. The tag is
2533
+ # verified during the #final call.
2534
+ #
2535
+ # Note that, for CCM mode and OCB mode, the expected length of the tag must be
2536
+ # set before starting decryption by a separate call to #auth_tag_len=. The
2537
+ # content of the tag can be provided at any time before #final is called.
2522
2538
  #
2523
- # For OCB mode, the tag length must be supplied with #auth_tag_len= beforehand.
2539
+ # **NOTE**: The caller must ensure that the String passed to this method has the
2540
+ # desired length. Some cipher modes support variable tag lengths, and this
2541
+ # method may accept a truncated tag without raising an exception.
2542
+ #
2543
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2544
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_TAG.
2524
2545
  #
2525
2546
  def auth_tag=: (String) -> String
2526
2547
 
2527
2548
  # <!--
2528
2549
  # rdoc-file=ext/openssl/ossl_cipher.c
2529
- # - cipher.auth_tag_len = Integer -> Integer
2550
+ # - cipher.auth_tag_len = integer
2530
2551
  # -->
2531
- # Sets the length of the authentication tag to be generated or to be given for
2532
- # AEAD ciphers that requires it as in input parameter. Note that not all AEAD
2533
- # ciphers support this method.
2552
+ # Sets the length of the expected authentication tag for this Cipher. This
2553
+ # method is available for some of AEAD ciphers that require the length to be set
2554
+ # before starting encryption or decryption, such as CCM mode or OCB mode.
2555
+ #
2556
+ # For CCM mode and OCB mode, the tag length must be set before #iv= is set.
2534
2557
  #
2535
- # In OCB mode, the length must be supplied both when encrypting and when
2536
- # decrypting, and must be before specifying an IV.
2558
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2559
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_TAG and a
2560
+ # NULL buffer.
2537
2561
  #
2538
2562
  def auth_tag_len=: (Integer) -> Integer
2539
2563
 
@@ -2541,7 +2565,7 @@ module OpenSSL
2541
2565
  # rdoc-file=ext/openssl/ossl_cipher.c
2542
2566
  # - cipher.authenticated? -> true | false
2543
2567
  # -->
2544
- # Indicated whether this Cipher instance uses an Authenticated Encryption mode.
2568
+ # Indicates whether this Cipher instance uses an AEAD mode.
2545
2569
  #
2546
2570
  def authenticated?: () -> bool
2547
2571
 
@@ -2559,11 +2583,9 @@ module OpenSSL
2559
2583
  # -->
2560
2584
  # Initializes the Cipher for decryption.
2561
2585
  #
2562
- # Make sure to call Cipher#encrypt or Cipher#decrypt before using any of the
2563
- # following methods:
2586
+ # Make sure to call either #encrypt or #decrypt before using the Cipher for any
2587
+ # operation or setting any parameters.
2564
2588
  #
2565
- # #key=, #iv=, #random_key, #random_iv, #pkcs5_keyivgen
2566
- # :
2567
2589
  # Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 0).
2568
2590
  #
2569
2591
  def decrypt: () -> self
@@ -2574,11 +2596,9 @@ module OpenSSL
2574
2596
  # -->
2575
2597
  # Initializes the Cipher for encryption.
2576
2598
  #
2577
- # Make sure to call Cipher#encrypt or Cipher#decrypt before using any of the
2578
- # following methods:
2599
+ # Make sure to call either #encrypt or #decrypt before using the Cipher for any
2600
+ # operation or setting any parameters.
2579
2601
  #
2580
- # #key=, #iv=, #random_key, #random_iv, #pkcs5_keyivgen
2581
- # :
2582
2602
  # Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 1).
2583
2603
  #
2584
2604
  def encrypt: () -> self
@@ -2588,28 +2608,37 @@ module OpenSSL
2588
2608
  # - cipher.final -> string
2589
2609
  # -->
2590
2610
  # Returns the remaining data held in the cipher object. Further calls to
2591
- # Cipher#update or Cipher#final will return garbage. This call should always be
2592
- # made as the last call of an encryption or decryption operation, after having
2593
- # fed the entire plaintext or ciphertext to the Cipher instance.
2611
+ # Cipher#update or Cipher#final are invalid. This call should always be made as
2612
+ # the last call of an encryption or decryption operation, after having fed the
2613
+ # entire plaintext or ciphertext to the Cipher instance.
2594
2614
  #
2595
- # If an authenticated cipher was used, a CipherError is raised if the tag could
2596
- # not be authenticated successfully. Only call this method after setting the
2597
- # authentication tag and passing the entire contents of the ciphertext into the
2598
- # cipher.
2615
+ # When encrypting using an AEAD cipher, the authentication tag can be retrieved
2616
+ # by #auth_tag after #final has been called.
2617
+ #
2618
+ # When decrypting using an AEAD cipher, this method will verify the integrity of
2619
+ # the ciphertext and the associated data with the authentication tag, which must
2620
+ # be set by #auth_tag= prior to calling this method. If the verification fails,
2621
+ # CipherError will be raised.
2599
2622
  #
2600
2623
  def final: () -> String
2601
2624
 
2602
2625
  # <!--
2603
2626
  # rdoc-file=ext/openssl/ossl_cipher.c
2604
- # - cipher.iv = string -> string
2627
+ # - cipher.iv = string
2605
2628
  # -->
2606
2629
  # Sets the cipher IV. Please note that since you should never be using ECB mode,
2607
2630
  # an IV is always explicitly required and should be set prior to encryption. The
2608
- # IV itself can be safely transmitted in public, but it should be unpredictable
2609
- # to prevent certain kinds of attacks. You may use Cipher#random_iv to create a
2610
- # secure random IV.
2631
+ # IV itself can be safely transmitted in public.
2611
2632
  #
2612
- # Only call this method after calling Cipher#encrypt or Cipher#decrypt.
2633
+ # This method expects the String to have the length equal to #iv_len. To use a
2634
+ # different IV length with an AEAD cipher, #iv_len= must be set prior to calling
2635
+ # this method.
2636
+ #
2637
+ # **NOTE**: In OpenSSL API conventions, the IV value may correspond to the
2638
+ # "nonce" instead in some cipher modes. Refer to the OpenSSL man pages for
2639
+ # details.
2640
+ #
2641
+ # See also the man page EVP_CipherInit_ex(3).
2613
2642
  #
2614
2643
  def iv=: (String iv) -> String
2615
2644
 
@@ -2623,17 +2652,20 @@ module OpenSSL
2623
2652
 
2624
2653
  # <!--
2625
2654
  # rdoc-file=ext/openssl/ossl_cipher.c
2626
- # - cipher.iv_len = integer -> integer
2655
+ # - cipher.iv_len = integer
2627
2656
  # -->
2628
- # Sets the IV/nonce length of the Cipher. Normally block ciphers don't allow
2629
- # changing the IV length, but some make use of IV for 'nonce'. You may need this
2630
- # for interoperability with other applications.
2657
+ # Sets the IV/nonce length for this Cipher. This method is available for AEAD
2658
+ # ciphers that support variable IV lengths. This method can be called if a
2659
+ # different IV length than OpenSSL's default is desired, prior to calling #iv=.
2660
+ #
2661
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2662
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_IVLEN.
2631
2663
  #
2632
2664
  def iv_len=: (Integer) -> Integer
2633
2665
 
2634
2666
  # <!--
2635
2667
  # rdoc-file=ext/openssl/ossl_cipher.c
2636
- # - cipher.key = string -> string
2668
+ # - cipher.key = string
2637
2669
  # -->
2638
2670
  # Sets the cipher key. To generate a key, you should either use a secure random
2639
2671
  # byte string or, if the key is to be derived from a password, you should rely
@@ -2642,6 +2674,8 @@ module OpenSSL
2642
2674
  #
2643
2675
  # Only call this method after calling Cipher#encrypt or Cipher#decrypt.
2644
2676
  #
2677
+ # See also the man page EVP_CipherInit_ex(3).
2678
+ #
2645
2679
  def key=: (String key) -> String
2646
2680
 
2647
2681
  # <!--
@@ -2654,7 +2688,7 @@ module OpenSSL
2654
2688
 
2655
2689
  # <!--
2656
2690
  # rdoc-file=ext/openssl/ossl_cipher.c
2657
- # - cipher.key_len = integer -> integer
2691
+ # - cipher.key_len = integer
2658
2692
  # -->
2659
2693
  # Sets the key length of the cipher. If the cipher is a fixed length cipher
2660
2694
  # then attempting to set the key length to any value other than the fixed value
@@ -2678,7 +2712,7 @@ module OpenSSL
2678
2712
 
2679
2713
  # <!--
2680
2714
  # rdoc-file=ext/openssl/ossl_cipher.c
2681
- # - cipher.padding = integer -> integer
2715
+ # - cipher.padding = 1 or 0
2682
2716
  # -->
2683
2717
  # Enables or disables padding. By default encryption operations are padded using
2684
2718
  # standard block padding and the padding is checked and removed when decrypting.
@@ -2696,19 +2730,16 @@ module OpenSSL
2696
2730
  # -->
2697
2731
  # Generates and sets the key/IV based on a password.
2698
2732
  #
2699
- # **WARNING**: This method is only PKCS5 v1.5 compliant when using RC2, RC4-40,
2700
- # or DES with MD5 or SHA1. Using anything else (like AES) will generate the
2701
- # key/iv using an OpenSSL specific method. This method is deprecated and should
2702
- # no longer be used. Use a PKCS5 v2 key generation method from OpenSSL::PKCS5
2703
- # instead.
2733
+ # **WARNING**: This method is deprecated and should not be used. This method
2734
+ # corresponds to EVP_BytesToKey(), a non-standard OpenSSL extension of the
2735
+ # legacy PKCS #5 v1.5 key derivation function. See OpenSSL::KDF for other
2736
+ # options to derive keys from passwords.
2704
2737
  #
2705
2738
  # ### Parameters
2706
2739
  # * *salt* must be an 8 byte string if provided.
2707
2740
  # * *iterations* is an integer with a default of 2048.
2708
2741
  # * *digest* is a Digest object that defaults to 'MD5'
2709
2742
  #
2710
- # A minimum of 1000 iterations is recommended.
2711
- #
2712
2743
  def pkcs5_keyivgen: (String pass, ?String salt, ?Integer iterations, ?String digest) -> void
2713
2744
 
2714
2745
  # <!--
@@ -2755,6 +2786,9 @@ module OpenSSL
2755
2786
  # If *buffer* is given, the encryption/decryption result will be written to it.
2756
2787
  # *buffer* will be resized automatically.
2757
2788
  #
2789
+ # **NOTE**: When decrypting using an AEAD cipher, the integrity of the output is
2790
+ # not verified until #final has been called.
2791
+ #
2758
2792
  def update: (String data, ?String buffer) -> String
2759
2793
 
2760
2794
  private
@@ -2863,7 +2897,7 @@ module OpenSSL
2863
2897
  # configuration. See the value of OpenSSL::Config::DEFAULT_CONFIG_FILE for the
2864
2898
  # location of the file for your host.
2865
2899
  #
2866
- # See also http://www.openssl.org/docs/apps/config.html
2900
+ # See also https://docs.openssl.org/master/man5/config/
2867
2901
  #
2868
2902
  class Config
2869
2903
  include Enumerable[[ String, String, String ]]
@@ -5642,11 +5676,12 @@ module OpenSSL
5642
5676
  def p: () -> BN
5643
5677
 
5644
5678
  # <!--
5645
- # rdoc-file=ext/openssl/ossl_pkey_dh.c
5679
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
5646
5680
  # - dh.params -> hash
5647
5681
  # -->
5648
- # Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN
5649
- # LEAK OUT!!! Don't use :-)) (I's up to you)
5682
+ # Stores all parameters of key to a Hash.
5683
+ #
5684
+ # The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
5650
5685
  #
5651
5686
  def params: () -> Hash[String, BN?]
5652
5687
 
@@ -5798,7 +5833,8 @@ module OpenSSL
5798
5833
  #
5799
5834
  # If called without arguments, an empty instance without any parameter or key
5800
5835
  # components is created. Use #set_pqg to manually set the parameters afterwards
5801
- # (and optionally #set_key to set private and public key components).
5836
+ # (and optionally #set_key to set private and public key components). This form
5837
+ # is not compatible with OpenSSL 3.0 or later.
5802
5838
  #
5803
5839
  # If a String is given, tries to parse it as a DER- or PEM- encoded parameters.
5804
5840
  # See also OpenSSL::PKey.read which can parse keys of any kinds.
@@ -5817,14 +5853,15 @@ module OpenSSL
5817
5853
  #
5818
5854
  # Examples:
5819
5855
  # # Creating an instance from scratch
5820
- # # Note that this is deprecated and will not work on OpenSSL 3.0 or later.
5856
+ # # Note that this is deprecated and will result in ArgumentError when
5857
+ # # using OpenSSL 3.0 or later.
5821
5858
  # dh = OpenSSL::PKey::DH.new
5822
5859
  # dh.set_pqg(bn_p, nil, bn_g)
5823
5860
  #
5824
5861
  # # Generating a parameters and a key pair
5825
5862
  # dh = OpenSSL::PKey::DH.new(2048) # An alias of OpenSSL::PKey::DH.generate(2048)
5826
5863
  #
5827
- # # Reading DH parameters
5864
+ # # Reading DH parameters from a PEM-encoded string
5828
5865
  # dh_params = OpenSSL::PKey::DH.new(File.read('parameters.pem')) # loads parameters only
5829
5866
  # dh = OpenSSL::PKey.generate_key(dh_params) # generates a key pair
5830
5867
  #
@@ -5936,11 +5973,12 @@ module OpenSSL
5936
5973
  def p: () -> BN
5937
5974
 
5938
5975
  # <!--
5939
- # rdoc-file=ext/openssl/ossl_pkey_dsa.c
5976
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
5940
5977
  # - dsa.params -> hash
5941
5978
  # -->
5942
- # Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN
5943
- # LEAK OUT!!! Don't use :-)) (I's up to you)
5979
+ # Stores all parameters of key to a Hash.
5980
+ #
5981
+ # The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
5944
5982
  #
5945
5983
  def params: () -> Hash[String, BN?]
5946
5984
 
@@ -6190,7 +6228,8 @@ module OpenSSL
6190
6228
  # Creates a new DSA instance by reading an existing key from *string*.
6191
6229
  #
6192
6230
  # If called without arguments, creates a new instance with no key components
6193
- # set. They can be set individually by #set_pqg and #set_key.
6231
+ # set. They can be set individually by #set_pqg and #set_key. This form is not
6232
+ # compatible with OpenSSL 3.0 or later.
6194
6233
  #
6195
6234
  # If called with a String, tries to parse as DER or PEM encoding of a DSA key.
6196
6235
  # See also OpenSSL::PKey.read which can parse keys of any kinds.
@@ -6850,7 +6889,6 @@ module OpenSSL
6850
6889
  # <!--
6851
6890
  # rdoc-file=ext/openssl/ossl_pkey_ec.c
6852
6891
  # - point.mul(bn1 [, bn2]) => point
6853
- # - point.mul(bns, points [, bn2]) => point
6854
6892
  # -->
6855
6893
  # Performs elliptic curve point multiplication.
6856
6894
  #
@@ -6858,10 +6896,9 @@ module OpenSSL
6858
6896
  # of the group of *point*. *bn2* may be omitted, and in that case, the result is
6859
6897
  # just `bn1 * point`.
6860
6898
  #
6861
- # The second form calculates `bns[0] * point + bns[1] * points[0] + ... +
6862
- # bns[-1] * points[-1] + bn2 * G`. *bn2* may be omitted. *bns* must be an array
6863
- # of OpenSSL::BN. *points* must be an array of OpenSSL::PKey::EC::Point. Please
6864
- # note that `points[0]` is not multiplied by `bns[0]`, but `bns[1]`.
6899
+ # Before version 4.0.0, and when compiled with OpenSSL 1.1.1 or older, this
6900
+ # method allowed another form:
6901
+ # point.mul(bns, points [, bn2]) => point
6865
6902
  #
6866
6903
  def mul: (bn bn1, ?bn bn2) -> self
6867
6904
  | (Array[bn] bns, Array[self], ?bn bn2) -> self
@@ -7103,6 +7140,15 @@ module OpenSSL
7103
7140
  # <!-- rdoc-file=ext/openssl/ossl_pkey.c -->
7104
7141
  # Raised when errors occur during PKey#sign or PKey#verify.
7105
7142
  #
7143
+ # Before version 4.0.0, OpenSSL::PKey::PKeyError had the following subclasses.
7144
+ # These subclasses have been removed and the constants are now defined as
7145
+ # aliases of OpenSSL::PKey::PKeyError.
7146
+ #
7147
+ # * OpenSSL::PKey::DHError
7148
+ # * OpenSSL::PKey::DSAError
7149
+ # * OpenSSL::PKey::ECError
7150
+ # * OpenSSL::PKey::RSAError
7151
+ #
7106
7152
  class PKeyError < OpenSSL::OpenSSLError
7107
7153
  end
7108
7154
 
@@ -7210,15 +7256,12 @@ module OpenSSL
7210
7256
  def p: () -> BN?
7211
7257
 
7212
7258
  # <!--
7213
- # rdoc-file=ext/openssl/ossl_pkey_rsa.c
7214
- # - rsa.params => hash
7259
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
7260
+ # - rsa.params -> hash
7215
7261
  # -->
7216
- # THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
7217
- #
7218
- # Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
7219
- # 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
7262
+ # Stores all parameters of key to a Hash.
7220
7263
  #
7221
- # Don't use :-)) (It's up to you)
7264
+ # The hash has keys 'n', 'e', 'd', 'p', 'q', 'dmp1', 'dmq1', and 'iqmp'.
7222
7265
  #
7223
7266
  def params: () -> Hash[String, BN?]
7224
7267
 
@@ -7343,7 +7386,7 @@ module OpenSSL
7343
7386
  # Signs *data* using the Probabilistic Signature Scheme (RSA-PSS) and returns
7344
7387
  # the calculated signature.
7345
7388
  #
7346
- # RSAError will be raised if an error occurs.
7389
+ # PKeyError will be raised if an error occurs.
7347
7390
  #
7348
7391
  # See #verify_pss for the verification operation.
7349
7392
  #
@@ -7517,7 +7560,7 @@ module OpenSSL
7517
7560
  # Verifies *data* using the Probabilistic Signature Scheme (RSA-PSS).
7518
7561
  #
7519
7562
  # The return value is `true` if the signature is valid, `false` otherwise.
7520
- # RSAError will be raised if an error occurs.
7563
+ # PKeyError will be raised if an error occurs.
7521
7564
  #
7522
7565
  # See #sign_pss for the signing operation and an example code.
7523
7566
  #
@@ -7551,7 +7594,7 @@ module OpenSSL
7551
7594
  #
7552
7595
  # If called without arguments, creates a new instance with no key components
7553
7596
  # set. They can be set individually by #set_key, #set_factors, and
7554
- # #set_crt_params.
7597
+ # #set_crt_params. This form is not compatible with OpenSSL 3.0 or later.
7555
7598
  #
7556
7599
  # If called with a String, tries to parse as DER or PEM encoding of an RSA key.
7557
7600
  # Note that if *password* is not specified, but the key is encrypted with a
@@ -7586,10 +7629,17 @@ module OpenSSL
7586
7629
  SSLV23_PADDING: Integer
7587
7630
  end
7588
7631
 
7589
- # <!-- rdoc-file=ext/openssl/ossl_pkey_rsa.c -->
7590
- # Generic exception that is raised if an operation on an RSA PKey fails
7591
- # unexpectedly or in case an instantiation of an instance of RSA fails due to
7592
- # non-conformant input data.
7632
+ # <!-- rdoc-file=ext/openssl/ossl_pkey.c -->
7633
+ # Raised when errors occur during PKey#sign or PKey#verify.
7634
+ #
7635
+ # Before version 4.0.0, OpenSSL::PKey::PKeyError had the following subclasses.
7636
+ # These subclasses have been removed and the constants are now defined as
7637
+ # aliases of OpenSSL::PKey::PKeyError.
7638
+ #
7639
+ # * OpenSSL::PKey::DHError
7640
+ # * OpenSSL::PKey::DSAError
7641
+ # * OpenSSL::PKey::ECError
7642
+ # * OpenSSL::PKey::RSAError
7593
7643
  #
7594
7644
  class RSAError < OpenSSL::PKey::PKeyError
7595
7645
  end
@@ -8029,9 +8079,14 @@ module OpenSSL
8029
8079
  # - ctx.ciphers = [name, ...]
8030
8080
  # - ctx.ciphers = [[name, version, bits, alg_bits], ...]
8031
8081
  # -->
8032
- # Sets the list of available cipher suites for this context. Note in a server
8033
- # context some ciphers require the appropriate certificates. For example, an
8034
- # RSA cipher suite can only be chosen when an RSA certificate is available.
8082
+ # Sets the list of available cipher suites for TLS 1.2 and below for this
8083
+ # context.
8084
+ #
8085
+ # Note in a server context some ciphers require the appropriate certificates.
8086
+ # For example, an RSA cipher suite can only be chosen when an RSA certificate is
8087
+ # available.
8088
+ #
8089
+ # This method does not affect TLS 1.3 connections. See also #ciphersuites=.
8035
8090
  #
8036
8091
  def ciphers=: (Array[[ String, String, Integer, Integer ]] ciphers) -> void
8037
8092
  | (Array[String] ciphers) -> void
@@ -8067,24 +8122,25 @@ module OpenSSL
8067
8122
  #
8068
8123
  def client_cert_cb=: (^(Session) -> [ X509::Certificate, PKey::PKey ]? client_cert_cb) -> void
8069
8124
 
8070
- # <!--
8071
- # rdoc-file=ext/openssl/ossl_ssl.c
8072
- # - ctx.ecdh_curves = curve_list -> curve_list
8073
- # -->
8074
- # Sets the list of "supported elliptic curves" for this context.
8125
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8126
+ # Sets the list of supported groups for key agreement for this context.
8075
8127
  #
8076
- # For a TLS client, the list is directly used in the Supported Elliptic Curves
8077
- # Extension. For a server, the list is used by OpenSSL to determine the set of
8078
- # shared curves. OpenSSL will pick the most appropriate one from it.
8128
+ # For a TLS client, the list is directly used in the "supported_groups"
8129
+ # extension. For a server, the list is used by OpenSSL to determine the set of
8130
+ # shared supported groups. OpenSSL will pick the most appropriate one from it.
8131
+ #
8132
+ # #ecdh_curves= is a deprecated alias for #groups=.
8133
+ #
8134
+ # See also the man page SSL_CTX_set1_groups_list(3).
8079
8135
  #
8080
8136
  # ### Example
8081
8137
  # ctx1 = OpenSSL::SSL::SSLContext.new
8082
- # ctx1.ecdh_curves = "X25519:P-256:P-224"
8138
+ # ctx1.groups = "X25519:P-256:P-224"
8083
8139
  # svr = OpenSSL::SSL::SSLServer.new(tcp_svr, ctx1)
8084
8140
  # Thread.new { svr.accept }
8085
8141
  #
8086
8142
  # ctx2 = OpenSSL::SSL::SSLContext.new
8087
- # ctx2.ecdh_curves = "P-256"
8143
+ # ctx2.groups = "P-256"
8088
8144
  # cli = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx2)
8089
8145
  # cli.connect
8090
8146
  #
@@ -8149,7 +8205,7 @@ module OpenSSL
8149
8205
  def key=: (PKey::PKey) -> PKey::PKey
8150
8206
 
8151
8207
  # <!--
8152
- # rdoc-file=ext/openssl/lib/openssl/ssl.rb
8208
+ # rdoc-file=ext/openssl/ossl_ssl.c
8153
8209
  # - ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
8154
8210
  # - ctx.max_version = :TLS1_2
8155
8211
  # - ctx.max_version = nil
@@ -8160,7 +8216,7 @@ module OpenSSL
8160
8216
  def max_version=: (tls_version version) -> tls_version
8161
8217
 
8162
8218
  # <!--
8163
- # rdoc-file=ext/openssl/lib/openssl/ssl.rb
8219
+ # rdoc-file=ext/openssl/ossl_ssl.c
8164
8220
  # - ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
8165
8221
  # - ctx.min_version = :TLS1_2
8166
8222
  # - ctx.min_version = nil
@@ -8169,9 +8225,6 @@ module OpenSSL
8169
8225
  # may be specified by an integer constant named OpenSSL::SSL::*_VERSION, a
8170
8226
  # Symbol, or `nil` which means "any version".
8171
8227
  #
8172
- # Be careful that you don't overwrite OpenSSL::SSL::OP_NO_{SSL,TLS}v* options by
8173
- # #options= once you have called #min_version= or #max_version=.
8174
- #
8175
8228
  # ### Example
8176
8229
  # ctx = OpenSSL::SSL::SSLContext.new
8177
8230
  # ctx.min_version = OpenSSL::SSL::TLS1_1_VERSION
@@ -8581,7 +8634,7 @@ module OpenSSL
8581
8634
  #
8582
8635
  def timeout=: (Integer) -> Integer
8583
8636
 
8584
- # <!-- rdoc-file=ext/openssl/lib/openssl/ssl.rb -->
8637
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8585
8638
  # A callback invoked when DH parameters are required for ephemeral DH key
8586
8639
  # exchange.
8587
8640
  #
@@ -8595,7 +8648,7 @@ module OpenSSL
8595
8648
  #
8596
8649
  def tmp_dh_callback: () -> (^(Session, Integer, Integer) -> PKey::DH | nil)
8597
8650
 
8598
- # <!-- rdoc-file=ext/openssl/lib/openssl/ssl.rb -->
8651
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8599
8652
  # A callback invoked when DH parameters are required for ephemeral DH key
8600
8653
  # exchange.
8601
8654
  #
@@ -8944,7 +8997,7 @@ module OpenSSL
8944
8997
 
8945
8998
  # <!--
8946
8999
  # rdoc-file=ext/openssl/ossl_ssl.c
8947
- # - ssl.client_ca => [x509name, ...]
9000
+ # - ssl.client_ca => [x509name, ...] or nil
8948
9001
  # -->
8949
9002
  # Returns the list of client CAs. Please note that in contrast to
8950
9003
  # SSLContext#client_ca= no array of X509::Certificate is returned but X509::Name
@@ -9524,38 +9577,22 @@ module OpenSSL
9524
9577
  # of both is present, a TimestampError will be raised when trying to create a
9525
9578
  # Response.
9526
9579
  #
9527
- # call-seq:
9528
- # factory.default_policy_id = "string" -> string
9529
- # factory.default_policy_id -> string or nil
9530
- #
9531
9580
  # ### serial_number
9532
9581
  #
9533
9582
  # Sets or retrieves the serial number to be used for timestamp creation. Must be
9534
9583
  # present for timestamp creation.
9535
9584
  #
9536
- # call-seq:
9537
- # factory.serial_number = number -> number
9538
- # factory.serial_number -> number or nil
9539
- #
9540
9585
  # ### gen_time
9541
9586
  #
9542
9587
  # Sets or retrieves the Time value to be used in the Response. Must be present
9543
9588
  # for timestamp creation.
9544
9589
  #
9545
- # call-seq:
9546
- # factory.gen_time = Time -> Time
9547
- # factory.gen_time -> Time or nil
9548
- #
9549
9590
  # ### additional_certs
9550
9591
  #
9551
9592
  # Sets or retrieves additional certificates apart from the timestamp certificate
9552
9593
  # (e.g. intermediate certificates) to be added to the Response. Must be an Array
9553
9594
  # of OpenSSL::X509::Certificate.
9554
9595
  #
9555
- # call-seq:
9556
- # factory.additional_certs = [cert1, cert2] -> [ cert1, cert2 ]
9557
- # factory.additional_certs -> array or nil
9558
- #
9559
9596
  # ### allowed_digests
9560
9597
  #
9561
9598
  # Sets or retrieves the digest algorithms that the factory is allowed create
@@ -9563,10 +9600,6 @@ module OpenSSL
9563
9600
  # where possible. Must be an Array of String or OpenSSL::Digest subclass
9564
9601
  # instances.
9565
9602
  #
9566
- # call-seq:
9567
- # factory.allowed_digests = ["sha1", OpenSSL::Digest.new('SHA256').new] -> [ "sha1", OpenSSL::Digest) ]
9568
- # factory.allowed_digests -> array or nil
9569
- #
9570
9603
  class Factory
9571
9604
  def additional_certs: () -> Array[X509::Certificate]?
9572
9605