rbs 3.9.5 → 3.10.0

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 (189) 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/CHANGELOG.md +49 -0
  11. data/README.md +38 -1
  12. data/Rakefile +152 -23
  13. data/config.yml +190 -62
  14. data/core/array.rbs +100 -46
  15. data/core/complex.rbs +32 -21
  16. data/core/dir.rbs +2 -2
  17. data/core/encoding.rbs +6 -9
  18. data/core/enumerable.rbs +90 -3
  19. data/core/enumerator.rbs +18 -1
  20. data/core/errno.rbs +8 -0
  21. data/core/errors.rbs +28 -1
  22. data/core/exception.rbs +2 -2
  23. data/core/fiber.rbs +5 -4
  24. data/core/file.rbs +27 -12
  25. data/core/file_test.rbs +1 -1
  26. data/core/float.rbs +209 -22
  27. data/core/gc.rbs +417 -281
  28. data/core/hash.rbs +1024 -727
  29. data/core/integer.rbs +78 -38
  30. data/core/io/buffer.rbs +18 -7
  31. data/core/io/wait.rbs +11 -33
  32. data/core/io.rbs +14 -12
  33. data/core/kernel.rbs +57 -51
  34. data/core/marshal.rbs +1 -1
  35. data/core/match_data.rbs +1 -1
  36. data/core/math.rbs +42 -3
  37. data/core/method.rbs +14 -6
  38. data/core/module.rbs +88 -17
  39. data/core/nil_class.rbs +3 -3
  40. data/core/numeric.rbs +16 -16
  41. data/core/object.rbs +3 -3
  42. data/core/object_space.rbs +21 -15
  43. data/{stdlib/pathname/0 → core}/pathname.rbs +255 -355
  44. data/core/proc.rbs +15 -8
  45. data/core/process.rbs +2 -2
  46. data/core/ractor.rbs +278 -437
  47. data/core/range.rbs +7 -8
  48. data/core/rational.rbs +37 -24
  49. data/core/rbs/unnamed/argf.rbs +2 -2
  50. data/core/rbs/unnamed/env_class.rbs +1 -1
  51. data/core/rbs/unnamed/random.rbs +4 -2
  52. data/core/regexp.rbs +25 -20
  53. data/core/ruby.rbs +53 -0
  54. data/core/ruby_vm.rbs +6 -4
  55. data/core/rubygems/errors.rbs +3 -70
  56. data/core/rubygems/rubygems.rbs +11 -79
  57. data/core/rubygems/version.rbs +2 -3
  58. data/core/set.rbs +488 -359
  59. data/core/string.rbs +3145 -1231
  60. data/core/struct.rbs +1 -1
  61. data/core/symbol.rbs +4 -4
  62. data/core/thread.rbs +92 -29
  63. data/core/time.rbs +35 -9
  64. data/core/trace_point.rbs +7 -4
  65. data/core/unbound_method.rbs +14 -6
  66. data/docs/aliases.md +79 -0
  67. data/docs/collection.md +2 -2
  68. data/docs/encoding.md +56 -0
  69. data/docs/gem.md +0 -1
  70. data/docs/sigs.md +3 -3
  71. data/ext/rbs_extension/ast_translation.c +1016 -0
  72. data/ext/rbs_extension/ast_translation.h +37 -0
  73. data/ext/rbs_extension/class_constants.c +155 -0
  74. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  75. data/ext/rbs_extension/compat.h +10 -0
  76. data/ext/rbs_extension/extconf.rb +25 -1
  77. data/ext/rbs_extension/legacy_location.c +317 -0
  78. data/ext/rbs_extension/legacy_location.h +45 -0
  79. data/ext/rbs_extension/main.c +357 -14
  80. data/ext/rbs_extension/rbs_extension.h +6 -21
  81. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  82. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  83. data/include/rbs/ast.h +687 -0
  84. data/include/rbs/defines.h +86 -0
  85. data/include/rbs/lexer.h +199 -0
  86. data/include/rbs/location.h +59 -0
  87. data/include/rbs/parser.h +135 -0
  88. data/include/rbs/string.h +47 -0
  89. data/include/rbs/util/rbs_allocator.h +59 -0
  90. data/include/rbs/util/rbs_assert.h +20 -0
  91. data/include/rbs/util/rbs_buffer.h +83 -0
  92. data/include/rbs/util/rbs_constant_pool.h +6 -67
  93. data/include/rbs/util/rbs_encoding.h +282 -0
  94. data/include/rbs/util/rbs_unescape.h +24 -0
  95. data/include/rbs.h +1 -2
  96. data/lib/rbs/annotate/formatter.rb +3 -13
  97. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  98. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  99. data/lib/rbs/cli/validate.rb +2 -2
  100. data/lib/rbs/cli.rb +1 -1
  101. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  102. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  103. data/lib/rbs/environment.rb +64 -59
  104. data/lib/rbs/environment_loader.rb +1 -1
  105. data/lib/rbs/errors.rb +1 -1
  106. data/lib/rbs/parser_aux.rb +5 -0
  107. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  108. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  109. data/lib/rbs/test/type_check.rb +14 -0
  110. data/lib/rbs/types.rb +3 -1
  111. data/lib/rbs/version.rb +1 -1
  112. data/lib/rbs.rb +1 -1
  113. data/lib/rdoc/discover.rb +1 -1
  114. data/lib/rdoc_plugin/parser.rb +3 -3
  115. data/sig/annotate/formatter.rbs +2 -2
  116. data/sig/annotate/rdoc_annotater.rbs +1 -1
  117. data/sig/environment.rbs +57 -6
  118. data/sig/manifest.yaml +0 -1
  119. data/sig/parser.rbs +20 -0
  120. data/sig/resolver/type_name_resolver.rbs +38 -7
  121. data/sig/types.rbs +4 -1
  122. data/src/ast.c +1256 -0
  123. data/src/lexer.c +2956 -0
  124. data/src/lexer.re +147 -0
  125. data/src/lexstate.c +205 -0
  126. data/src/location.c +71 -0
  127. data/src/parser.c +3507 -0
  128. data/src/string.c +41 -0
  129. data/src/util/rbs_allocator.c +152 -0
  130. data/src/util/rbs_assert.c +19 -0
  131. data/src/util/rbs_buffer.c +54 -0
  132. data/src/util/rbs_constant_pool.c +18 -88
  133. data/src/util/rbs_encoding.c +21308 -0
  134. data/src/util/rbs_unescape.c +167 -0
  135. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  136. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  137. data/stdlib/cgi/0/core.rbs +2 -396
  138. data/stdlib/cgi/0/manifest.yaml +1 -0
  139. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  140. data/stdlib/coverage/0/coverage.rbs +3 -1
  141. data/stdlib/date/0/date.rbs +67 -59
  142. data/stdlib/date/0/date_time.rbs +1 -1
  143. data/stdlib/delegate/0/delegator.rbs +10 -7
  144. data/stdlib/erb/0/erb.rbs +737 -347
  145. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  146. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  147. data/stdlib/json/0/json.rbs +68 -48
  148. data/stdlib/net-http/0/net-http.rbs +3 -0
  149. data/stdlib/objspace/0/objspace.rbs +9 -4
  150. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  151. data/stdlib/openssl/0/openssl.rbs +331 -228
  152. data/stdlib/optparse/0/optparse.rbs +3 -3
  153. data/stdlib/psych/0/psych.rbs +3 -3
  154. data/stdlib/rdoc/0/code_object.rbs +2 -2
  155. data/stdlib/rdoc/0/comment.rbs +2 -0
  156. data/stdlib/rdoc/0/options.rbs +76 -0
  157. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  158. data/stdlib/rdoc/0/store.rbs +1 -1
  159. data/stdlib/resolv/0/resolv.rbs +25 -68
  160. data/stdlib/ripper/0/ripper.rbs +5 -2
  161. data/stdlib/singleton/0/singleton.rbs +3 -0
  162. data/stdlib/socket/0/socket.rbs +13 -1
  163. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  164. data/stdlib/stringio/0/stringio.rbs +1176 -85
  165. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  166. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  167. data/stdlib/time/0/time.rbs +1 -1
  168. data/stdlib/timeout/0/timeout.rbs +63 -7
  169. data/stdlib/tsort/0/cyclic.rbs +3 -0
  170. data/stdlib/uri/0/common.rbs +11 -2
  171. data/stdlib/uri/0/file.rbs +1 -1
  172. data/stdlib/uri/0/generic.rbs +17 -16
  173. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  174. data/stdlib/zlib/0/zstream.rbs +1 -0
  175. metadata +43 -18
  176. data/ext/rbs_extension/lexer.c +0 -2728
  177. data/ext/rbs_extension/lexer.h +0 -179
  178. data/ext/rbs_extension/lexer.re +0 -147
  179. data/ext/rbs_extension/lexstate.c +0 -175
  180. data/ext/rbs_extension/location.c +0 -325
  181. data/ext/rbs_extension/location.h +0 -85
  182. data/ext/rbs_extension/parser.c +0 -2982
  183. data/ext/rbs_extension/parser.h +0 -18
  184. data/ext/rbs_extension/parserstate.c +0 -411
  185. data/ext/rbs_extension/parserstate.h +0 -163
  186. data/ext/rbs_extension/unescape.c +0 -32
  187. data/include/rbs/ruby_objs.h +0 -72
  188. data/src/constants.c +0 -153
  189. data/src/ruby_objs.c +0 -799
@@ -367,7 +367,7 @@
367
367
  # ## SSL and TLS Connections
368
368
  #
369
369
  # Using our created key and certificate we can create an SSL or TLS connection.
370
- # An SSLContext is used to set up an SSL session.
370
+ # An OpenSSL::SSL::SSLContext is used to set up an SSL session.
371
371
  #
372
372
  # context = OpenSSL::SSL::SSLContext.new
373
373
  #
@@ -379,8 +379,8 @@
379
379
  # context.cert = cert
380
380
  # context.key = key
381
381
  #
382
- # Then create an SSLServer with a TCP server socket and the context. Use the
383
- # SSLServer like an ordinary TCP server.
382
+ # Then create an OpenSSL::SSL::SSLServer with a TCP server socket and the
383
+ # context. Use the SSLServer like an ordinary TCP server.
384
384
  #
385
385
  # require 'socket'
386
386
  #
@@ -401,12 +401,13 @@
401
401
  #
402
402
  # ### SSL client
403
403
  #
404
- # An SSL client is created with a TCP socket and the context. SSLSocket#connect
405
- # must be called to initiate the SSL handshake and start encryption. A key and
406
- # certificate are not required for the client socket.
404
+ # An SSL client is created with a TCP socket and the context.
405
+ # OpenSSL::SSL::SSLSocket#connect must be called to initiate the SSL handshake
406
+ # and start encryption. A key and certificate are not required for the client
407
+ # socket.
407
408
  #
408
- # Note that SSLSocket#close doesn't close the underlying socket by default. Set
409
- # SSLSocket#sync_close to true if you want.
409
+ # Note that OpenSSL::SSL::SSLSocket#close doesn't close the underlying socket by
410
+ # default. Set OpenSSL::SSL::SSLSocket#sync_close to true if you want.
410
411
  #
411
412
  # require 'socket'
412
413
  #
@@ -455,7 +456,7 @@ module OpenSSL
455
456
  # OpenSSL::Digest("MD5")
456
457
  # # => OpenSSL::Digest::MD5
457
458
  #
458
- # Digest("Foo")
459
+ # OpenSSL::Digest("Foo")
459
460
  # # => NameError: wrong constant name Foo
460
461
  #
461
462
  def self.Digest: (String name) -> singleton(Digest)
@@ -464,12 +465,13 @@ module OpenSSL
464
465
  # rdoc-file=ext/openssl/ossl.c
465
466
  # - OpenSSL.debug -> true | false
466
467
  # -->
468
+ # Returns whether Ruby/OpenSSL's debug mode is currently enabled.
467
469
  #
468
470
  def self.debug: () -> bool
469
471
 
470
472
  # <!--
471
473
  # rdoc-file=ext/openssl/ossl.c
472
- # - OpenSSL.debug = boolean -> boolean
474
+ # - OpenSSL.debug = boolean
473
475
  # -->
474
476
  # Turns on or off debug mode. With debug mode, all errors added to the OpenSSL
475
477
  # error queue will be printed to stderr.
@@ -480,10 +482,14 @@ module OpenSSL
480
482
  # rdoc-file=ext/openssl/ossl.c
481
483
  # - OpenSSL.errors -> [String...]
482
484
  # -->
483
- # See any remaining errors held in queue.
485
+ # Returns any remaining errors held in the OpenSSL thread-local error queue and
486
+ # clears the queue. This should normally return an empty array.
484
487
  #
485
- # Any errors you see here are probably due to a bug in Ruby's OpenSSL
486
- # implementation.
488
+ # This is intended for debugging Ruby/OpenSSL. If you see any errors here, it
489
+ # likely indicates a bug in the extension. Please file an issue at
490
+ # https://github.com/ruby/openssl.
491
+ #
492
+ # For debugging your program, OpenSSL.debug= may be useful.
487
493
  #
488
494
  def self.errors: () -> Array[String]
489
495
 
@@ -491,12 +497,13 @@ module OpenSSL
491
497
  # rdoc-file=ext/openssl/ossl.c
492
498
  # - OpenSSL.fips_mode -> true | false
493
499
  # -->
500
+ # Returns whether the FIPS mode is currently enabled.
494
501
  #
495
502
  def self.fips_mode: () -> bool
496
503
 
497
504
  # <!--
498
505
  # rdoc-file=ext/openssl/ossl.c
499
- # - OpenSSL.fips_mode = boolean -> boolean
506
+ # - OpenSSL.fips_mode = boolean
500
507
  # -->
501
508
  # Turns FIPS mode on or off. Turning on FIPS mode will obviously only have an
502
509
  # effect for FIPS-capable installations of the OpenSSL library. Trying to do so
@@ -510,57 +517,74 @@ module OpenSSL
510
517
 
511
518
  # <!--
512
519
  # rdoc-file=ext/openssl/ossl.c
513
- # - OpenSSL.fixed_length_secure_compare(string, string) -> boolean
520
+ # - OpenSSL.fixed_length_secure_compare(string, string) -> true or false
514
521
  # -->
515
522
  # Constant time memory comparison for fixed length strings, such as results of
516
523
  # HMAC calculations.
517
524
  #
518
525
  # Returns `true` if the strings are identical, `false` if they are of the same
519
- # length but not identical. If the length is different, `ArgumentError` is
520
- # raised.
526
+ # length but not identical. If the length is different, ArgumentError is raised.
521
527
  #
522
528
  def self.fixed_length_secure_compare: (String, String) -> bool
523
529
 
524
530
  # <!--
525
531
  # rdoc-file=ext/openssl/lib/openssl.rb
526
- # - OpenSSL.secure_compare(string, string) -> boolean
532
+ # - OpenSSL.secure_compare(string, string) -> true or false
527
533
  # -->
528
534
  # Constant time memory comparison. Inputs are hashed using SHA-256 to mask the
529
535
  # length of the secret. Returns `true` if the strings are identical, `false`
530
536
  # otherwise.
531
537
  #
538
+ # This method is expensive due to the SHA-256 hashing. In most cases, where the
539
+ # input lengths are known to be equal or are not sensitive,
540
+ # OpenSSL.fixed_length_secure_compare should be used instead.
541
+ #
532
542
  def self.secure_compare: (String a, String b) -> bool
533
543
 
534
544
  # <!-- rdoc-file=ext/openssl/ossl.c -->
535
- # Boolean indicating whether OpenSSL is FIPS-capable or not
545
+ # Boolean indicating whether the OpenSSL library is FIPS-capable or not. Always
546
+ # `true` for OpenSSL 3.0 and later.
547
+ #
548
+ # This is obsolete and will be removed in the future. See also
549
+ # OpenSSL.fips_mode.
536
550
  #
537
551
  OPENSSL_FIPS: bool
538
552
 
553
+ # <!-- rdoc-file=ext/openssl/ossl.c -->
554
+ # OpenSSL library version string currently used at runtime.
555
+ #
539
556
  OPENSSL_LIBRARY_VERSION: String
540
557
 
541
558
  # <!-- rdoc-file=ext/openssl/ossl.c -->
542
- # Version of OpenSSL the ruby OpenSSL extension was built with
559
+ # OpenSSL library version string used to compile the Ruby/OpenSSL extension.
560
+ # This may differ from the version used at runtime.
543
561
  #
544
562
  OPENSSL_VERSION: String
545
563
 
546
564
  # <!-- rdoc-file=ext/openssl/ossl.c -->
547
- # Version number of OpenSSL the ruby OpenSSL extension was built with (base 16).
548
- # The formats are below.
565
+ # OpenSSL library version number used to compile the Ruby/OpenSSL extension.
566
+ # This may differ from the version used at runtime.
549
567
  #
550
- # OpenSSL 3
551
- # : `0xMNN00PP0 (major minor 00 patch 0)`
568
+ # The version number is encoded into a single integer value. The number follows
569
+ # the format:
552
570
  #
553
- # OpenSSL before 3
554
- # : `0xMNNFFPPS (major minor fix patch status)`
571
+ # OpenSSL 3.0.0 or later
572
+ # : `0xMNN00PP0` (major minor 00 patch 0)
573
+ #
574
+ # OpenSSL 1.1.1 or earlier
575
+ # : `0xMNNFFPPS` (major minor fix patch status)
555
576
  #
556
577
  # LibreSSL
557
- # : `0x20000000 (fixed value)`
578
+ # : `0x20000000` (a fixed value)
558
579
  #
559
580
  #
560
581
  # See also the man page OPENSSL_VERSION_NUMBER(3).
561
582
  #
562
583
  OPENSSL_VERSION_NUMBER: Integer
563
584
 
585
+ # <!-- rdoc-file=ext/openssl/lib/openssl/version.rb -->
586
+ # The version string of Ruby/OpenSSL.
587
+ #
564
588
  VERSION: String
565
589
 
566
590
  # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
@@ -931,7 +955,7 @@ module OpenSSL
931
955
  # puts int2.value # => 1
932
956
  #
933
957
  class ASN1Data
934
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
958
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
935
959
  # Never `nil`. A boolean value indicating whether the encoding uses indefinite
936
960
  # length (in the case of parsing) or whether an indefinite length form shall be
937
961
  # used (in the encoding case). In DER, every value uses definite length form.
@@ -948,7 +972,7 @@ module OpenSSL
948
972
  #
949
973
  def indefinite_length: () -> bool
950
974
 
951
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
975
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
952
976
  # Never `nil`. A boolean value indicating whether the encoding uses indefinite
953
977
  # length (in the case of parsing) or whether an indefinite length form shall be
954
978
  # used (in the encoding case). In DER, every value uses definite length form.
@@ -965,7 +989,7 @@ module OpenSSL
965
989
  #
966
990
  def indefinite_length=: [U] (boolish) -> U
967
991
 
968
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
992
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
969
993
  # Never `nil`. A boolean value indicating whether the encoding uses indefinite
970
994
  # length (in the case of parsing) or whether an indefinite length form shall be
971
995
  # used (in the encoding case). In DER, every value uses definite length form.
@@ -982,7 +1006,7 @@ module OpenSSL
982
1006
  #
983
1007
  alias infinite_length indefinite_length
984
1008
 
985
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1009
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
986
1010
  # Never `nil`. A boolean value indicating whether the encoding uses indefinite
987
1011
  # length (in the case of parsing) or whether an indefinite length form shall be
988
1012
  # used (in the encoding case). In DER, every value uses definite length form.
@@ -999,24 +1023,24 @@ module OpenSSL
999
1023
  #
1000
1024
  alias infinite_length= indefinite_length=
1001
1025
 
1002
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1026
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1003
1027
  # An Integer representing the tag number of this ASN1Data. Never `nil`.
1004
1028
  #
1005
1029
  def tag: () -> bn
1006
1030
 
1007
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1031
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1008
1032
  # An Integer representing the tag number of this ASN1Data. Never `nil`.
1009
1033
  #
1010
1034
  def tag=: (::Integer) -> ::Integer
1011
1035
  | (BN) -> BN
1012
1036
 
1013
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1037
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1014
1038
  # A Symbol representing the tag class of this ASN1Data. Never `nil`. See
1015
1039
  # ASN1Data for possible values.
1016
1040
  #
1017
1041
  def tag_class: () -> tag_class
1018
1042
 
1019
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1043
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1020
1044
  # A Symbol representing the tag class of this ASN1Data. Never `nil`. See
1021
1045
  # ASN1Data for possible values.
1022
1046
  #
@@ -1033,13 +1057,13 @@ module OpenSSL
1033
1057
  #
1034
1058
  def to_der: () -> String
1035
1059
 
1036
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1060
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1037
1061
  # Carries the value of a ASN.1 type. Please confer Constructive and Primitive
1038
1062
  # for the mappings between ASN.1 data types and Ruby classes.
1039
1063
  #
1040
1064
  def value: () -> untyped
1041
1065
 
1042
- # <!-- rdoc-file=ext/openssl/lib/openssl/asn1.rb -->
1066
+ # <!-- rdoc-file=ext/openssl/ossl_asn1.c -->
1043
1067
  # Carries the value of a ASN.1 type. Please confer Constructive and Primitive
1044
1068
  # for the mappings between ASN.1 data types and Ruby classes.
1045
1069
  #
@@ -1048,7 +1072,7 @@ module OpenSSL
1048
1072
  private
1049
1073
 
1050
1074
  # <!--
1051
- # rdoc-file=ext/openssl/lib/openssl/asn1.rb
1075
+ # rdoc-file=ext/openssl/ossl_asn1.c
1052
1076
  # - OpenSSL::ASN1::ASN1Data.new(value, tag, tag_class) => ASN1Data
1053
1077
  # -->
1054
1078
  # *value*: Please have a look at Constructive and Primitive to see how Ruby
@@ -1120,7 +1144,7 @@ module OpenSSL
1120
1144
  include Enumerable[ASN1Data]
1121
1145
 
1122
1146
  # <!--
1123
- # rdoc-file=ext/openssl/lib/openssl/asn1.rb
1147
+ # rdoc-file=ext/openssl/ossl_asn1.c
1124
1148
  # - asn1_ary.each { |asn1| block } => asn1_ary
1125
1149
  # -->
1126
1150
  # Calls the given block once for each element in self, passing that element as
@@ -2428,24 +2452,28 @@ module OpenSSL
2428
2452
  # prevents malicious modifications of the ciphertext that could otherwise be
2429
2453
  # exploited to modify ciphertexts in ways beneficial to potential attackers.
2430
2454
  #
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.
2455
+ # Associated data, also called additional authenticated data (AAD), is
2456
+ # optionally used where there is additional information, such as headers or some
2457
+ # metadata, that must be also authenticated but not necessarily need to be
2458
+ # encrypted.
2436
2459
  #
2437
2460
  # An example using the GCM (Galois/Counter Mode). You have 16 bytes *key*, 12
2438
2461
  # bytes (96 bits) *nonce* and the associated data *auth_data*. Be sure not to
2439
2462
  # reuse the *key* and *nonce* pair. Reusing an nonce ruins the security
2440
2463
  # guarantees of GCM mode.
2441
2464
  #
2465
+ # key = OpenSSL::Random.random_bytes(16)
2466
+ # nonce = OpenSSL::Random.random_bytes(12)
2467
+ # auth_data = "authenticated but unencrypted data"
2468
+ # data = "encrypted data"
2469
+ #
2442
2470
  # cipher = OpenSSL::Cipher.new('aes-128-gcm').encrypt
2443
2471
  # cipher.key = key
2444
2472
  # cipher.iv = nonce
2445
2473
  # cipher.auth_data = auth_data
2446
2474
  #
2447
2475
  # encrypted = cipher.update(data) + cipher.final
2448
- # tag = cipher.auth_tag # produces 16 bytes tag by default
2476
+ # tag = cipher.auth_tag(16)
2449
2477
  #
2450
2478
  # Now you are the receiver. You know the *key* and have received *nonce*,
2451
2479
  # *auth_data*, *encrypted* and *tag* through an untrusted network. Note that GCM
@@ -2458,13 +2486,17 @@ module OpenSSL
2458
2486
  # decipher = OpenSSL::Cipher.new('aes-128-gcm').decrypt
2459
2487
  # decipher.key = key
2460
2488
  # decipher.iv = nonce
2461
- # decipher.auth_tag = tag
2489
+ # decipher.auth_tag = tag # could be called at any time before #final
2462
2490
  # decipher.auth_data = auth_data
2463
2491
  #
2464
2492
  # decrypted = decipher.update(encrypted) + decipher.final
2465
2493
  #
2466
2494
  # puts data == decrypted #=> true
2467
2495
  #
2496
+ # Note that other AEAD ciphers may require additional steps, such as setting the
2497
+ # expected tag length (#auth_tag_len=) or the total data length (#ccm_data_len=)
2498
+ # in advance. Make sure to read the relevant man page for details.
2499
+ #
2468
2500
  class Cipher
2469
2501
  # <!--
2470
2502
  # rdoc-file=ext/openssl/ossl_cipher.c
@@ -2476,21 +2508,22 @@ module OpenSSL
2476
2508
 
2477
2509
  # <!--
2478
2510
  # 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.
2511
+ # - cipher.auth_data = string
2512
+ # -->
2513
+ # Sets additional authenticated data (AAD), also called associated data, for
2514
+ # this Cipher. This method is available for AEAD ciphers.
2515
+ #
2516
+ # The contents of this field should be non-sensitive data which will be added to
2517
+ # the ciphertext to generate the authentication tag which validates the contents
2518
+ # of the ciphertext.
2519
+ #
2520
+ # This method must be called after #key= and #iv= have been set, but before
2521
+ # starting actual encryption or decryption with #update. In some cipher modes,
2522
+ # #auth_tag_len= and #ccm_data_len= may also need to be called before this
2523
+ # method.
2524
+ #
2525
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2526
+ # method internally calls EVP_CipherUpdate() with the output buffer set to NULL.
2494
2527
  #
2495
2528
  def auth_data=: (String) -> String
2496
2529
 
@@ -2498,42 +2531,54 @@ module OpenSSL
2498
2531
  # rdoc-file=ext/openssl/ossl_cipher.c
2499
2532
  # - cipher.auth_tag(tag_len = 16) -> String
2500
2533
  # -->
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.
2534
+ # Gets the generated authentication tag. This method is available for AEAD
2535
+ # ciphers, and should be called after encryption has been finalized by calling
2536
+ # #final.
2537
+ #
2538
+ # The returned tag will be *tag_len* bytes long. Some cipher modes require the
2539
+ # desired length in advance using a separate call to #auth_tag_len=, before
2540
+ # starting encryption.
2508
2541
  #
2509
- # The tag may only be retrieved after calling Cipher#final.
2542
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2543
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_GET_TAG.
2510
2544
  #
2511
2545
  def auth_tag: (?Integer tag_len) -> String
2512
2546
 
2513
2547
  # <!--
2514
2548
  # rdoc-file=ext/openssl/ossl_cipher.c
2515
- # - cipher.auth_tag = string -> string
2549
+ # - cipher.auth_tag = string
2516
2550
  # -->
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.
2551
+ # Sets the authentication tag to verify the integrity of the ciphertext.
2552
+ #
2553
+ # The authentication tag must be set before #final is called. The tag is
2554
+ # verified during the #final call.
2555
+ #
2556
+ # Note that, for CCM mode and OCB mode, the expected length of the tag must be
2557
+ # set before starting decryption by a separate call to #auth_tag_len=. The
2558
+ # content of the tag can be provided at any time before #final is called.
2522
2559
  #
2523
- # For OCB mode, the tag length must be supplied with #auth_tag_len= beforehand.
2560
+ # **NOTE**: The caller must ensure that the String passed to this method has the
2561
+ # desired length. Some cipher modes support variable tag lengths, and this
2562
+ # method may accept a truncated tag without raising an exception.
2563
+ #
2564
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2565
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_TAG.
2524
2566
  #
2525
2567
  def auth_tag=: (String) -> String
2526
2568
 
2527
2569
  # <!--
2528
2570
  # rdoc-file=ext/openssl/ossl_cipher.c
2529
- # - cipher.auth_tag_len = Integer -> Integer
2571
+ # - cipher.auth_tag_len = integer
2530
2572
  # -->
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.
2573
+ # Sets the length of the expected authentication tag for this Cipher. This
2574
+ # method is available for some of AEAD ciphers that require the length to be set
2575
+ # before starting encryption or decryption, such as CCM mode or OCB mode.
2576
+ #
2577
+ # For CCM mode and OCB mode, the tag length must be set before #iv= is set.
2534
2578
  #
2535
- # In OCB mode, the length must be supplied both when encrypting and when
2536
- # decrypting, and must be before specifying an IV.
2579
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2580
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_TAG and a
2581
+ # NULL buffer.
2537
2582
  #
2538
2583
  def auth_tag_len=: (Integer) -> Integer
2539
2584
 
@@ -2541,7 +2586,7 @@ module OpenSSL
2541
2586
  # rdoc-file=ext/openssl/ossl_cipher.c
2542
2587
  # - cipher.authenticated? -> true | false
2543
2588
  # -->
2544
- # Indicated whether this Cipher instance uses an Authenticated Encryption mode.
2589
+ # Indicates whether this Cipher instance uses an AEAD mode.
2545
2590
  #
2546
2591
  def authenticated?: () -> bool
2547
2592
 
@@ -2559,11 +2604,9 @@ module OpenSSL
2559
2604
  # -->
2560
2605
  # Initializes the Cipher for decryption.
2561
2606
  #
2562
- # Make sure to call Cipher#encrypt or Cipher#decrypt before using any of the
2563
- # following methods:
2607
+ # Make sure to call either #encrypt or #decrypt before using the Cipher for any
2608
+ # operation or setting any parameters.
2564
2609
  #
2565
- # #key=, #iv=, #random_key, #random_iv, #pkcs5_keyivgen
2566
- # :
2567
2610
  # Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 0).
2568
2611
  #
2569
2612
  def decrypt: () -> self
@@ -2574,11 +2617,9 @@ module OpenSSL
2574
2617
  # -->
2575
2618
  # Initializes the Cipher for encryption.
2576
2619
  #
2577
- # Make sure to call Cipher#encrypt or Cipher#decrypt before using any of the
2578
- # following methods:
2620
+ # Make sure to call either #encrypt or #decrypt before using the Cipher for any
2621
+ # operation or setting any parameters.
2579
2622
  #
2580
- # #key=, #iv=, #random_key, #random_iv, #pkcs5_keyivgen
2581
- # :
2582
2623
  # Internally calls EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, 1).
2583
2624
  #
2584
2625
  def encrypt: () -> self
@@ -2588,28 +2629,37 @@ module OpenSSL
2588
2629
  # - cipher.final -> string
2589
2630
  # -->
2590
2631
  # 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.
2632
+ # Cipher#update or Cipher#final are invalid. This call should always be made as
2633
+ # the last call of an encryption or decryption operation, after having fed the
2634
+ # entire plaintext or ciphertext to the Cipher instance.
2594
2635
  #
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.
2636
+ # When encrypting using an AEAD cipher, the authentication tag can be retrieved
2637
+ # by #auth_tag after #final has been called.
2638
+ #
2639
+ # When decrypting using an AEAD cipher, this method will verify the integrity of
2640
+ # the ciphertext and the associated data with the authentication tag, which must
2641
+ # be set by #auth_tag= prior to calling this method. If the verification fails,
2642
+ # CipherError will be raised.
2599
2643
  #
2600
2644
  def final: () -> String
2601
2645
 
2602
2646
  # <!--
2603
2647
  # rdoc-file=ext/openssl/ossl_cipher.c
2604
- # - cipher.iv = string -> string
2648
+ # - cipher.iv = string
2605
2649
  # -->
2606
2650
  # Sets the cipher IV. Please note that since you should never be using ECB mode,
2607
2651
  # 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.
2652
+ # IV itself can be safely transmitted in public.
2611
2653
  #
2612
- # Only call this method after calling Cipher#encrypt or Cipher#decrypt.
2654
+ # This method expects the String to have the length equal to #iv_len. To use a
2655
+ # different IV length with an AEAD cipher, #iv_len= must be set prior to calling
2656
+ # this method.
2657
+ #
2658
+ # **NOTE**: In OpenSSL API conventions, the IV value may correspond to the
2659
+ # "nonce" instead in some cipher modes. Refer to the OpenSSL man pages for
2660
+ # details.
2661
+ #
2662
+ # See also the man page EVP_CipherInit_ex(3).
2613
2663
  #
2614
2664
  def iv=: (String iv) -> String
2615
2665
 
@@ -2623,17 +2673,20 @@ module OpenSSL
2623
2673
 
2624
2674
  # <!--
2625
2675
  # rdoc-file=ext/openssl/ossl_cipher.c
2626
- # - cipher.iv_len = integer -> integer
2676
+ # - cipher.iv_len = integer
2627
2677
  # -->
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.
2678
+ # Sets the IV/nonce length for this Cipher. This method is available for AEAD
2679
+ # ciphers that support variable IV lengths. This method can be called if a
2680
+ # different IV length than OpenSSL's default is desired, prior to calling #iv=.
2681
+ #
2682
+ # See also the "AEAD Interface" section of the man page EVP_EncryptInit(3). This
2683
+ # method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_IVLEN.
2631
2684
  #
2632
2685
  def iv_len=: (Integer) -> Integer
2633
2686
 
2634
2687
  # <!--
2635
2688
  # rdoc-file=ext/openssl/ossl_cipher.c
2636
- # - cipher.key = string -> string
2689
+ # - cipher.key = string
2637
2690
  # -->
2638
2691
  # Sets the cipher key. To generate a key, you should either use a secure random
2639
2692
  # byte string or, if the key is to be derived from a password, you should rely
@@ -2642,6 +2695,8 @@ module OpenSSL
2642
2695
  #
2643
2696
  # Only call this method after calling Cipher#encrypt or Cipher#decrypt.
2644
2697
  #
2698
+ # See also the man page EVP_CipherInit_ex(3).
2699
+ #
2645
2700
  def key=: (String key) -> String
2646
2701
 
2647
2702
  # <!--
@@ -2654,7 +2709,7 @@ module OpenSSL
2654
2709
 
2655
2710
  # <!--
2656
2711
  # rdoc-file=ext/openssl/ossl_cipher.c
2657
- # - cipher.key_len = integer -> integer
2712
+ # - cipher.key_len = integer
2658
2713
  # -->
2659
2714
  # Sets the key length of the cipher. If the cipher is a fixed length cipher
2660
2715
  # then attempting to set the key length to any value other than the fixed value
@@ -2678,7 +2733,7 @@ module OpenSSL
2678
2733
 
2679
2734
  # <!--
2680
2735
  # rdoc-file=ext/openssl/ossl_cipher.c
2681
- # - cipher.padding = integer -> integer
2736
+ # - cipher.padding = 1 or 0
2682
2737
  # -->
2683
2738
  # Enables or disables padding. By default encryption operations are padded using
2684
2739
  # standard block padding and the padding is checked and removed when decrypting.
@@ -2696,19 +2751,16 @@ module OpenSSL
2696
2751
  # -->
2697
2752
  # Generates and sets the key/IV based on a password.
2698
2753
  #
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.
2754
+ # **WARNING**: This method is deprecated and should not be used. This method
2755
+ # corresponds to EVP_BytesToKey(), a non-standard OpenSSL extension of the
2756
+ # legacy PKCS #5 v1.5 key derivation function. See OpenSSL::KDF for other
2757
+ # options to derive keys from passwords.
2704
2758
  #
2705
2759
  # ### Parameters
2706
2760
  # * *salt* must be an 8 byte string if provided.
2707
2761
  # * *iterations* is an integer with a default of 2048.
2708
2762
  # * *digest* is a Digest object that defaults to 'MD5'
2709
2763
  #
2710
- # A minimum of 1000 iterations is recommended.
2711
- #
2712
2764
  def pkcs5_keyivgen: (String pass, ?String salt, ?Integer iterations, ?String digest) -> void
2713
2765
 
2714
2766
  # <!--
@@ -2755,6 +2807,9 @@ module OpenSSL
2755
2807
  # If *buffer* is given, the encryption/decryption result will be written to it.
2756
2808
  # *buffer* will be resized automatically.
2757
2809
  #
2810
+ # **NOTE**: When decrypting using an AEAD cipher, the integrity of the output is
2811
+ # not verified until #final has been called.
2812
+ #
2758
2813
  def update: (String data, ?String buffer) -> String
2759
2814
 
2760
2815
  private
@@ -2863,7 +2918,7 @@ module OpenSSL
2863
2918
  # configuration. See the value of OpenSSL::Config::DEFAULT_CONFIG_FILE for the
2864
2919
  # location of the file for your host.
2865
2920
  #
2866
- # See also http://www.openssl.org/docs/apps/config.html
2921
+ # See also https://docs.openssl.org/master/man5/config/
2867
2922
  #
2868
2923
  class Config
2869
2924
  include Enumerable[[ String, String, String ]]
@@ -5042,7 +5097,11 @@ module OpenSSL
5042
5097
  end
5043
5098
 
5044
5099
  # <!-- rdoc-file=ext/openssl/ossl.c -->
5045
- # Generic error, common for all classes under OpenSSL module
5100
+ # Generic error class for OpenSSL. All error classes in this library inherit
5101
+ # from this class.
5102
+ #
5103
+ # This class indicates that an error was reported by the underlying OpenSSL
5104
+ # library.
5046
5105
  #
5047
5106
  class OpenSSLError < StandardError
5048
5107
  end
@@ -5642,11 +5701,12 @@ module OpenSSL
5642
5701
  def p: () -> BN
5643
5702
 
5644
5703
  # <!--
5645
- # rdoc-file=ext/openssl/ossl_pkey_dh.c
5704
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
5646
5705
  # - dh.params -> hash
5647
5706
  # -->
5648
- # Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN
5649
- # LEAK OUT!!! Don't use :-)) (I's up to you)
5707
+ # Stores all parameters of key to a Hash.
5708
+ #
5709
+ # The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
5650
5710
  #
5651
5711
  def params: () -> Hash[String, BN?]
5652
5712
 
@@ -5798,7 +5858,8 @@ module OpenSSL
5798
5858
  #
5799
5859
  # If called without arguments, an empty instance without any parameter or key
5800
5860
  # components is created. Use #set_pqg to manually set the parameters afterwards
5801
- # (and optionally #set_key to set private and public key components).
5861
+ # (and optionally #set_key to set private and public key components). This form
5862
+ # is not compatible with OpenSSL 3.0 or later.
5802
5863
  #
5803
5864
  # If a String is given, tries to parse it as a DER- or PEM- encoded parameters.
5804
5865
  # See also OpenSSL::PKey.read which can parse keys of any kinds.
@@ -5817,14 +5878,15 @@ module OpenSSL
5817
5878
  #
5818
5879
  # Examples:
5819
5880
  # # Creating an instance from scratch
5820
- # # Note that this is deprecated and will not work on OpenSSL 3.0 or later.
5881
+ # # Note that this is deprecated and will result in ArgumentError when
5882
+ # # using OpenSSL 3.0 or later.
5821
5883
  # dh = OpenSSL::PKey::DH.new
5822
5884
  # dh.set_pqg(bn_p, nil, bn_g)
5823
5885
  #
5824
5886
  # # Generating a parameters and a key pair
5825
5887
  # dh = OpenSSL::PKey::DH.new(2048) # An alias of OpenSSL::PKey::DH.generate(2048)
5826
5888
  #
5827
- # # Reading DH parameters
5889
+ # # Reading DH parameters from a PEM-encoded string
5828
5890
  # dh_params = OpenSSL::PKey::DH.new(File.read('parameters.pem')) # loads parameters only
5829
5891
  # dh = OpenSSL::PKey.generate_key(dh_params) # generates a key pair
5830
5892
  #
@@ -5936,11 +5998,12 @@ module OpenSSL
5936
5998
  def p: () -> BN
5937
5999
 
5938
6000
  # <!--
5939
- # rdoc-file=ext/openssl/ossl_pkey_dsa.c
6001
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
5940
6002
  # - dsa.params -> hash
5941
6003
  # -->
5942
- # Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN
5943
- # LEAK OUT!!! Don't use :-)) (I's up to you)
6004
+ # Stores all parameters of key to a Hash.
6005
+ #
6006
+ # The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
5944
6007
  #
5945
6008
  def params: () -> Hash[String, BN?]
5946
6009
 
@@ -6190,7 +6253,8 @@ module OpenSSL
6190
6253
  # Creates a new DSA instance by reading an existing key from *string*.
6191
6254
  #
6192
6255
  # 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.
6256
+ # set. They can be set individually by #set_pqg and #set_key. This form is not
6257
+ # compatible with OpenSSL 3.0 or later.
6194
6258
  #
6195
6259
  # If called with a String, tries to parse as DER or PEM encoding of a DSA key.
6196
6260
  # See also OpenSSL::PKey.read which can parse keys of any kinds.
@@ -6638,9 +6702,10 @@ module OpenSSL
6638
6702
 
6639
6703
  # <!--
6640
6704
  # rdoc-file=ext/openssl/ossl_pkey_ec.c
6641
- # - group.curve_name => String
6705
+ # - group.curve_name -> string or nil
6642
6706
  # -->
6643
- # Returns the curve name (sn).
6707
+ # Returns the curve name (short name) corresponding to this group, or `nil` if
6708
+ # OpenSSL does not have an OID associated with the group.
6644
6709
  #
6645
6710
  # See the OpenSSL documentation for EC_GROUP_get_curve_name()
6646
6711
  #
@@ -6850,7 +6915,6 @@ module OpenSSL
6850
6915
  # <!--
6851
6916
  # rdoc-file=ext/openssl/ossl_pkey_ec.c
6852
6917
  # - point.mul(bn1 [, bn2]) => point
6853
- # - point.mul(bns, points [, bn2]) => point
6854
6918
  # -->
6855
6919
  # Performs elliptic curve point multiplication.
6856
6920
  #
@@ -6858,10 +6922,9 @@ module OpenSSL
6858
6922
  # of the group of *point*. *bn2* may be omitted, and in that case, the result is
6859
6923
  # just `bn1 * point`.
6860
6924
  #
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]`.
6925
+ # Before version 4.0.0, and when compiled with OpenSSL 1.1.1 or older, this
6926
+ # method allowed another form:
6927
+ # point.mul(bns, points [, bn2]) => point
6865
6928
  #
6866
6929
  def mul: (bn bn1, ?bn bn2) -> self
6867
6930
  | (Array[bn] bns, Array[self], ?bn bn2) -> self
@@ -7103,6 +7166,15 @@ module OpenSSL
7103
7166
  # <!-- rdoc-file=ext/openssl/ossl_pkey.c -->
7104
7167
  # Raised when errors occur during PKey#sign or PKey#verify.
7105
7168
  #
7169
+ # Before version 4.0.0, OpenSSL::PKey::PKeyError had the following subclasses.
7170
+ # These subclasses have been removed and the constants are now defined as
7171
+ # aliases of OpenSSL::PKey::PKeyError.
7172
+ #
7173
+ # * OpenSSL::PKey::DHError
7174
+ # * OpenSSL::PKey::DSAError
7175
+ # * OpenSSL::PKey::ECError
7176
+ # * OpenSSL::PKey::RSAError
7177
+ #
7106
7178
  class PKeyError < OpenSSL::OpenSSLError
7107
7179
  end
7108
7180
 
@@ -7210,15 +7282,12 @@ module OpenSSL
7210
7282
  def p: () -> BN?
7211
7283
 
7212
7284
  # <!--
7213
- # rdoc-file=ext/openssl/ossl_pkey_rsa.c
7214
- # - rsa.params => hash
7285
+ # rdoc-file=ext/openssl/lib/openssl/pkey.rb
7286
+ # - rsa.params -> hash
7215
7287
  # -->
7216
- # THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
7288
+ # Stores all parameters of key to a Hash.
7217
7289
  #
7218
- # Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
7219
- # 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
7220
- #
7221
- # Don't use :-)) (It's up to you)
7290
+ # The hash has keys 'n', 'e', 'd', 'p', 'q', 'dmp1', 'dmq1', and 'iqmp'.
7222
7291
  #
7223
7292
  def params: () -> Hash[String, BN?]
7224
7293
 
@@ -7343,7 +7412,7 @@ module OpenSSL
7343
7412
  # Signs *data* using the Probabilistic Signature Scheme (RSA-PSS) and returns
7344
7413
  # the calculated signature.
7345
7414
  #
7346
- # RSAError will be raised if an error occurs.
7415
+ # PKeyError will be raised if an error occurs.
7347
7416
  #
7348
7417
  # See #verify_pss for the verification operation.
7349
7418
  #
@@ -7517,7 +7586,7 @@ module OpenSSL
7517
7586
  # Verifies *data* using the Probabilistic Signature Scheme (RSA-PSS).
7518
7587
  #
7519
7588
  # The return value is `true` if the signature is valid, `false` otherwise.
7520
- # RSAError will be raised if an error occurs.
7589
+ # PKeyError will be raised if an error occurs.
7521
7590
  #
7522
7591
  # See #sign_pss for the signing operation and an example code.
7523
7592
  #
@@ -7551,7 +7620,7 @@ module OpenSSL
7551
7620
  #
7552
7621
  # If called without arguments, creates a new instance with no key components
7553
7622
  # set. They can be set individually by #set_key, #set_factors, and
7554
- # #set_crt_params.
7623
+ # #set_crt_params. This form is not compatible with OpenSSL 3.0 or later.
7555
7624
  #
7556
7625
  # If called with a String, tries to parse as DER or PEM encoding of an RSA key.
7557
7626
  # Note that if *password* is not specified, but the key is encrypted with a
@@ -7586,10 +7655,17 @@ module OpenSSL
7586
7655
  SSLV23_PADDING: Integer
7587
7656
  end
7588
7657
 
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.
7658
+ # <!-- rdoc-file=ext/openssl/ossl_pkey.c -->
7659
+ # Raised when errors occur during PKey#sign or PKey#verify.
7660
+ #
7661
+ # Before version 4.0.0, OpenSSL::PKey::PKeyError had the following subclasses.
7662
+ # These subclasses have been removed and the constants are now defined as
7663
+ # aliases of OpenSSL::PKey::PKeyError.
7664
+ #
7665
+ # * OpenSSL::PKey::DHError
7666
+ # * OpenSSL::PKey::DSAError
7667
+ # * OpenSSL::PKey::ECError
7668
+ # * OpenSSL::PKey::RSAError
7593
7669
  #
7594
7670
  class RSAError < OpenSSL::PKey::PKeyError
7595
7671
  end
@@ -8029,9 +8105,14 @@ module OpenSSL
8029
8105
  # - ctx.ciphers = [name, ...]
8030
8106
  # - ctx.ciphers = [[name, version, bits, alg_bits], ...]
8031
8107
  # -->
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.
8108
+ # Sets the list of available cipher suites for TLS 1.2 and below for this
8109
+ # context.
8110
+ #
8111
+ # Note in a server context some ciphers require the appropriate certificates.
8112
+ # For example, an RSA cipher suite can only be chosen when an RSA certificate is
8113
+ # available.
8114
+ #
8115
+ # This method does not affect TLS 1.3 connections. See also #ciphersuites=.
8035
8116
  #
8036
8117
  def ciphers=: (Array[[ String, String, Integer, Integer ]] ciphers) -> void
8037
8118
  | (Array[String] ciphers) -> void
@@ -8067,24 +8148,25 @@ module OpenSSL
8067
8148
  #
8068
8149
  def client_cert_cb=: (^(Session) -> [ X509::Certificate, PKey::PKey ]? client_cert_cb) -> void
8069
8150
 
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.
8151
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8152
+ # Sets the list of supported groups for key agreement for this context.
8153
+ #
8154
+ # For a TLS client, the list is directly used in the "supported_groups"
8155
+ # extension. For a server, the list is used by OpenSSL to determine the set of
8156
+ # shared supported groups. OpenSSL will pick the most appropriate one from it.
8157
+ #
8158
+ # #ecdh_curves= is a deprecated alias for #groups=.
8075
8159
  #
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.
8160
+ # See also the man page SSL_CTX_set1_groups_list(3).
8079
8161
  #
8080
8162
  # ### Example
8081
8163
  # ctx1 = OpenSSL::SSL::SSLContext.new
8082
- # ctx1.ecdh_curves = "X25519:P-256:P-224"
8164
+ # ctx1.groups = "X25519:P-256:P-224"
8083
8165
  # svr = OpenSSL::SSL::SSLServer.new(tcp_svr, ctx1)
8084
8166
  # Thread.new { svr.accept }
8085
8167
  #
8086
8168
  # ctx2 = OpenSSL::SSL::SSLContext.new
8087
- # ctx2.ecdh_curves = "P-256"
8169
+ # ctx2.groups = "P-256"
8088
8170
  # cli = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx2)
8089
8171
  # cli.connect
8090
8172
  #
@@ -8149,7 +8231,7 @@ module OpenSSL
8149
8231
  def key=: (PKey::PKey) -> PKey::PKey
8150
8232
 
8151
8233
  # <!--
8152
- # rdoc-file=ext/openssl/lib/openssl/ssl.rb
8234
+ # rdoc-file=ext/openssl/ossl_ssl.c
8153
8235
  # - ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
8154
8236
  # - ctx.max_version = :TLS1_2
8155
8237
  # - ctx.max_version = nil
@@ -8160,7 +8242,7 @@ module OpenSSL
8160
8242
  def max_version=: (tls_version version) -> tls_version
8161
8243
 
8162
8244
  # <!--
8163
- # rdoc-file=ext/openssl/lib/openssl/ssl.rb
8245
+ # rdoc-file=ext/openssl/ossl_ssl.c
8164
8246
  # - ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
8165
8247
  # - ctx.min_version = :TLS1_2
8166
8248
  # - ctx.min_version = nil
@@ -8169,9 +8251,6 @@ module OpenSSL
8169
8251
  # may be specified by an integer constant named OpenSSL::SSL::*_VERSION, a
8170
8252
  # Symbol, or `nil` which means "any version".
8171
8253
  #
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
8254
  # ### Example
8176
8255
  # ctx = OpenSSL::SSL::SSLContext.new
8177
8256
  # ctx.min_version = OpenSSL::SSL::TLS1_1_VERSION
@@ -8581,7 +8660,7 @@ module OpenSSL
8581
8660
  #
8582
8661
  def timeout=: (Integer) -> Integer
8583
8662
 
8584
- # <!-- rdoc-file=ext/openssl/lib/openssl/ssl.rb -->
8663
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8585
8664
  # A callback invoked when DH parameters are required for ephemeral DH key
8586
8665
  # exchange.
8587
8666
  #
@@ -8595,7 +8674,7 @@ module OpenSSL
8595
8674
  #
8596
8675
  def tmp_dh_callback: () -> (^(Session, Integer, Integer) -> PKey::DH | nil)
8597
8676
 
8598
- # <!-- rdoc-file=ext/openssl/lib/openssl/ssl.rb -->
8677
+ # <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
8599
8678
  # A callback invoked when DH parameters are required for ephemeral DH key
8600
8679
  # exchange.
8601
8680
  #
@@ -8944,7 +9023,7 @@ module OpenSSL
8944
9023
 
8945
9024
  # <!--
8946
9025
  # rdoc-file=ext/openssl/ossl_ssl.c
8947
- # - ssl.client_ca => [x509name, ...]
9026
+ # - ssl.client_ca => [x509name, ...] or nil
8948
9027
  # -->
8949
9028
  # Returns the list of client CAs. Please note that in contrast to
8950
9029
  # SSLContext#client_ca= no array of X509::Certificate is returned but X509::Name
@@ -9515,65 +9594,33 @@ module OpenSSL
9515
9594
  # fac.additional_certificates = [ inter1, inter2 ]
9516
9595
  # timestamp = fac.create_timestamp(p12.key, p12.certificate, req)
9517
9596
  #
9518
- # ## Attributes
9519
- #
9520
- # ### default_policy_id
9521
- #
9522
- # Request#policy_id will always be preferred over this if present in the
9523
- # Request, only if Request#policy_id is nil default_policy will be used. If none
9524
- # of both is present, a TimestampError will be raised when trying to create a
9525
- # Response.
9526
- #
9527
- # call-seq:
9528
- # factory.default_policy_id = "string" -> string
9529
- # factory.default_policy_id -> string or nil
9530
- #
9531
- # ### serial_number
9532
- #
9533
- # Sets or retrieves the serial number to be used for timestamp creation. Must be
9534
- # present for timestamp creation.
9535
- #
9536
- # call-seq:
9537
- # factory.serial_number = number -> number
9538
- # factory.serial_number -> number or nil
9539
- #
9540
- # ### gen_time
9541
- #
9542
- # Sets or retrieves the Time value to be used in the Response. Must be present
9543
- # for timestamp creation.
9544
- #
9545
- # call-seq:
9546
- # factory.gen_time = Time -> Time
9547
- # factory.gen_time -> Time or nil
9548
- #
9549
- # ### additional_certs
9550
- #
9551
- # Sets or retrieves additional certificates apart from the timestamp certificate
9552
- # (e.g. intermediate certificates) to be added to the Response. Must be an Array
9553
- # of OpenSSL::X509::Certificate.
9554
- #
9555
- # call-seq:
9556
- # factory.additional_certs = [cert1, cert2] -> [ cert1, cert2 ]
9557
- # factory.additional_certs -> array or nil
9558
- #
9559
- # ### allowed_digests
9560
- #
9561
- # Sets or retrieves the digest algorithms that the factory is allowed create
9562
- # timestamps for. Known vulnerable or weak algorithms should not be allowed
9563
- # where possible. Must be an Array of String or OpenSSL::Digest subclass
9564
- # instances.
9565
- #
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
9597
  class Factory
9598
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9599
+ # Additional certificates apart from the timestamp certificate (e.g.
9600
+ # intermediate certificates) to be added to the Response. Must be an Array of
9601
+ # OpenSSL::X509::Certificate, or `nil`.
9602
+ #
9571
9603
  def additional_certs: () -> Array[X509::Certificate]?
9572
9604
 
9605
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9606
+ # Additional certificates apart from the timestamp certificate (e.g.
9607
+ # intermediate certificates) to be added to the Response. Must be an Array of
9608
+ # OpenSSL::X509::Certificate, or `nil`.
9609
+ #
9573
9610
  def additional_certs=: (Array[X509::Certificate]? certs) -> Array[X509::Certificate]?
9574
9611
 
9612
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9613
+ # The list of digest algorithms that the factory is allowed create timestamps
9614
+ # for. Known vulnerable or weak algorithms should not be allowed where possible.
9615
+ # Must be an Array of String or OpenSSL::Digest subclass instances.
9616
+ #
9575
9617
  def allowed_digests: () -> Array[String | Digest]?
9576
9618
 
9619
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9620
+ # The list of digest algorithms that the factory is allowed create timestamps
9621
+ # for. Known vulnerable or weak algorithms should not be allowed where possible.
9622
+ # Must be an Array of String or OpenSSL::Digest subclass instances.
9623
+ #
9577
9624
  def allowed_digests=: (Array[String | Digest]) -> Array[String | Digest]
9578
9625
 
9579
9626
  # <!--
@@ -9602,16 +9649,48 @@ module OpenSSL
9602
9649
  #
9603
9650
  def create_timestamp: (PKey::PKey key, X509::Certificate cert, Request request) -> Response
9604
9651
 
9652
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9653
+ # A String representing the default policy object identifier, or `nil`.
9654
+ #
9655
+ # Request#policy_id will always be preferred over this if present in the
9656
+ # Request, only if Request#policy_id is `nil` default_policy will be used. If
9657
+ # none of both is present, a TimestampError will be raised when trying to create
9658
+ # a Response.
9659
+ #
9605
9660
  def default_policy_id: () -> String?
9606
9661
 
9662
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9663
+ # A String representing the default policy object identifier, or `nil`.
9664
+ #
9665
+ # Request#policy_id will always be preferred over this if present in the
9666
+ # Request, only if Request#policy_id is `nil` default_policy will be used. If
9667
+ # none of both is present, a TimestampError will be raised when trying to create
9668
+ # a Response.
9669
+ #
9607
9670
  def default_policy_id=: (String) -> String
9608
9671
 
9672
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9673
+ # The Time value to be used in the Response. Must be present for timestamp
9674
+ # creation.
9675
+ #
9609
9676
  def gen_time: () -> Time?
9610
9677
 
9678
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9679
+ # The Time value to be used in the Response. Must be present for timestamp
9680
+ # creation.
9681
+ #
9611
9682
  def gen_time=: (Time) -> Time
9612
9683
 
9684
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9685
+ # The serial number to be used for timestamp creation. Must be present for
9686
+ # timestamp creation. Must be an instance of OpenSSL::BN or Integer.
9687
+ #
9613
9688
  def serial_number: () -> Integer?
9614
9689
 
9690
+ # <!-- rdoc-file=ext/openssl/ossl_ts.c -->
9691
+ # The serial number to be used for timestamp creation. Must be present for
9692
+ # timestamp creation. Must be an instance of OpenSSL::BN or Integer.
9693
+ #
9615
9694
  def serial_number=: (Integer) -> Integer
9616
9695
  end
9617
9696
 
@@ -10305,8 +10384,10 @@ module OpenSSL
10305
10384
 
10306
10385
  # <!--
10307
10386
  # rdoc-file=ext/openssl/ossl_x509attr.c
10308
- # - attr.oid => string
10387
+ # - attr.oid -> string
10309
10388
  # -->
10389
+ # Returns the OID of the attribute. Returns the short name or the dotted decimal
10390
+ # notation.
10310
10391
  #
10311
10392
  def oid: () -> String
10312
10393
 
@@ -10468,8 +10549,12 @@ module OpenSSL
10468
10549
 
10469
10550
  # <!--
10470
10551
  # rdoc-file=ext/openssl/ossl_x509crl.c
10471
- # - signature_algorithm()
10552
+ # - crl.signature_algorithm -> string
10472
10553
  # -->
10554
+ # Returns the signature algorithm used to sign this CRL.
10555
+ #
10556
+ # Returns the long name of the signature algorithm, or the dotted decimal
10557
+ # notation if OpenSSL does not define a long name for it.
10473
10558
  #
10474
10559
  def signature_algorithm: () -> String
10475
10560
 
@@ -10649,6 +10734,12 @@ module OpenSSL
10649
10734
  # Compares the two certificates. Note that this takes into account all fields,
10650
10735
  # not just the issuer name and the serial number.
10651
10736
  #
10737
+ # This method uses X509_cmp() from OpenSSL, which compares certificates based on
10738
+ # their cached DER encodings. The comparison can be unreliable if a certificate
10739
+ # is incomplete.
10740
+ #
10741
+ # See also the man page X509_cmp(3).
10742
+ #
10652
10743
  def ==: (self other) -> bool
10653
10744
 
10654
10745
  # <!--
@@ -10682,7 +10773,7 @@ module OpenSSL
10682
10773
  def extensions=: (Array[Extension]) -> Array[Extension]
10683
10774
 
10684
10775
  # <!--
10685
- # rdoc-file=ext/openssl/ossl_x509cert.c
10776
+ # rdoc-file=ext/openssl/lib/openssl/x509.rb
10686
10777
  # - inspect()
10687
10778
  # -->
10688
10779
  #
@@ -10776,6 +10867,12 @@ module OpenSSL
10776
10867
  # rdoc-file=ext/openssl/ossl_x509cert.c
10777
10868
  # - cert.signature_algorithm => string
10778
10869
  # -->
10870
+ # Returns the signature algorithm used to sign this certificate. This returns
10871
+ # the algorithm name found in the TBSCertificate structure, not the outer
10872
+ # Certificate structure.
10873
+ #
10874
+ # Returns the long name of the signature algorithm, or the dotted decimal
10875
+ # notation if OpenSSL does not define a long name for it.
10779
10876
  #
10780
10877
  def signature_algorithm: () -> String
10781
10878
 
@@ -10893,8 +10990,10 @@ module OpenSSL
10893
10990
 
10894
10991
  # <!--
10895
10992
  # rdoc-file=ext/openssl/ossl_x509ext.c
10896
- # - oid()
10993
+ # - ext.oid -> string
10897
10994
  # -->
10995
+ # Returns the OID of the extension. Returns the short name or the dotted decimal
10996
+ # notation.
10898
10997
  #
10899
10998
  def oid: () -> String
10900
10999
 
@@ -11547,8 +11646,12 @@ module OpenSSL
11547
11646
 
11548
11647
  # <!--
11549
11648
  # rdoc-file=ext/openssl/ossl_x509req.c
11550
- # - signature_algorithm()
11649
+ # - req.signature_algorithm -> string
11551
11650
  # -->
11651
+ # Returns the signature algorithm used to sign this request.
11652
+ #
11653
+ # Returns the long name of the signature algorithm, or the dotted decimal
11654
+ # notation if OpenSSL does not define a long name for it.
11552
11655
  #
11553
11656
  def signature_algorithm: () -> String
11554
11657