rbs 1.3.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/core/range.rbs CHANGED
@@ -101,7 +101,9 @@ class Range[out Elem] < Object
101
101
  # ```
102
102
  def begin: () -> Elem # Begin-less ranges have type of Range[Integer?]
103
103
 
104
- def bsearch: [U] () { (Elem) -> boolish } -> U?
104
+ def bsearch: () -> ::Enumerator[Elem, Elem?]
105
+ | () { (Elem) -> (true | false) } -> Elem?
106
+ | () { (Elem) -> ::Integer } -> Elem?
105
107
 
106
108
  def cover?: (untyped obj) -> bool
107
109
 
@@ -132,7 +134,7 @@ class Range[out Elem] < Object
132
134
  # (10..20).first(3) #=> [10, 11, 12]
133
135
  # ```
134
136
  def first: () -> Elem
135
- | (?Integer n) -> ::Array[Elem]
137
+ | (Integer n) -> ::Array[Elem]
136
138
 
137
139
  # Compute a hash-code for this range. Two ranges with equal begin and end
138
140
  # points (using `eql?` ), and the same
@@ -165,7 +167,7 @@ class Range[out Elem] < Object
165
167
  # (10...20).last(3) #=> [17, 18, 19]
166
168
  # ```
167
169
  def last: () -> Elem
168
- | (?Integer n) -> ::Array[Elem]
170
+ | (Integer n) -> ::Array[Elem]
169
171
 
170
172
  # Returns the maximum value in the range. Returns `nil` if the begin value
171
173
  # of the range larger than the end value. Returns `nil` if the begin value
@@ -178,9 +180,9 @@ class Range[out Elem] < Object
178
180
  # (10..20).max #=> 20
179
181
  # ```
180
182
  def max: () -> Elem
181
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
182
- | (?Integer n) -> ::Array[Elem]
183
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
183
+ | () { (Elem a, Elem b) -> Integer } -> Elem
184
+ | (Integer n) -> ::Array[Elem]
185
+ | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
184
186
 
185
187
  # Returns the minimum value in the range. Returns `nil` if the begin value
186
188
  # of the range is larger than the end value. Returns `nil` if the begin
@@ -193,9 +195,9 @@ class Range[out Elem] < Object
193
195
  # (10..20).min #=> 10
194
196
  # ```
195
197
  def min: () -> Elem
196
- | () { (Elem arg0, Elem arg1) -> Integer } -> Elem
197
- | (?Integer n) -> ::Array[Elem]
198
- | (?Integer n) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]
198
+ | () { (Elem a, Elem b) -> Integer } -> Elem
199
+ | (Integer n) -> ::Array[Elem]
200
+ | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
199
201
 
200
202
  # Returns the number of elements in the range. Both the begin and the end
201
203
  # of the [Range](Range.downloaded.ruby_doc) must be
data/core/string_io.rbs CHANGED
@@ -164,10 +164,9 @@ class StringIO
164
164
 
165
165
  # See IO#read.
166
166
  #
167
- def read: (?Integer length, ?String outbuf) -> String?
167
+ def read: (?int? length, ?string outbuf) -> String?
168
168
 
169
- def read_nonblock: (Integer len) -> String
170
- | (Integer len, ?String buf) -> String
169
+ def read_nonblock: (int len, ?string buf) -> String
171
170
 
172
171
  def readbyte: () -> Integer
173
172
 
@@ -179,8 +178,7 @@ class StringIO
179
178
  #
180
179
  def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String]
181
180
 
182
- def readpartial: (Integer maxlen) -> String
183
- | (Integer maxlen, ?String outbuf) -> String
181
+ def readpartial: (int maxlen, ?string outbuf) -> String
184
182
 
185
183
  # Reinitializes the stream with the given *other_StrIO* or *string* and *mode*
186
184
  # (see StringIO#new).
data/core/true_class.rbs CHANGED
@@ -5,13 +5,13 @@
5
5
  class TrueClass
6
6
  public
7
7
 
8
- def !: () -> bool
8
+ def !: () -> false
9
9
 
10
10
  # And---Returns `false` if *obj* is `nil` or `false`, `true` otherwise.
11
11
  #
12
12
  def &: (nil) -> false
13
13
  | (false) -> false
14
- | (untyped obj) -> bool
14
+ | (untyped obj) -> true
15
15
 
16
16
  # Case Equality -- For class Object, effectively the same as calling `#==`, but
17
17
  # typically overridden by descendants to provide meaningful semantics in `case`
@@ -24,7 +24,7 @@ class TrueClass
24
24
  #
25
25
  def ^: (nil) -> true
26
26
  | (false) -> true
27
- | (untyped obj) -> bool
27
+ | (untyped obj) -> false
28
28
 
29
29
  alias inspect to_s
30
30
 
@@ -42,5 +42,5 @@ class TrueClass
42
42
  #
43
43
  # or
44
44
  #
45
- def |: (boolish obj) -> bool
45
+ def |: (untyped obj) -> true
46
46
  end
data/lib/rbs.rb CHANGED
@@ -44,6 +44,7 @@ require "rbs/factory"
44
44
  require "rbs/repository"
45
45
  require "rbs/ancestor_graph"
46
46
  require "rbs/locator"
47
+ require "rbs/type_alias_dependency"
47
48
 
48
49
  begin
49
50
  require "rbs/parser"
data/lib/rbs/cli.rb CHANGED
@@ -451,6 +451,7 @@ EOU
451
451
  builder.expand_alias(name).tap do |type|
452
452
  validator.validate_type type, context: [Namespace.root]
453
453
  end
454
+ validator.validate_type_alias(entry: decl)
454
455
  end
455
456
  end
456
457
 
data/lib/rbs/errors.rb CHANGED
@@ -386,4 +386,20 @@ module RBS
386
386
  end
387
387
  end
388
388
  end
389
+
390
+ class RecursiveTypeAliasError < LoadingError
391
+ attr_reader :alias_names
392
+ attr_reader :location
393
+
394
+ def initialize(alias_names:, location:)
395
+ @alias_names = alias_names
396
+ @location = location
397
+
398
+ super "#{Location.to_string location}: Recursive type alias definition found for: #{name}"
399
+ end
400
+
401
+ def name
402
+ @alias_names.map(&:name).join(', ')
403
+ end
404
+ end
389
405
  end
data/lib/rbs/parser.rb CHANGED
@@ -326,7 +326,7 @@ def next_token
326
326
  new_token(:tUKEYWORD, input.matched.chop.to_sym)
327
327
  when input.scan(/[A-Z]\w*[?!]:/)
328
328
  new_token(:tUKEYWORD_Q_E, input.matched.chop.to_sym)
329
- when input.scan(/\$[A-Za-z_]\w*/)
329
+ when input.scan(/\$([A-Za-z_]\w*|[~*$?!@\/\\;,.=:<>"&`'+]|\d+|-[0-9_A-Za-z])/)
330
330
  new_token(:tGLOBALIDENT)
331
331
  when input.scan(/@[a-zA-Z_]\w*/)
332
332
  new_token(:tIVAR, input.matched.to_sym)
data/lib/rbs/parser.y CHANGED
@@ -1708,7 +1708,7 @@ def next_token
1708
1708
  new_token(:tUKEYWORD, input.matched.chop.to_sym)
1709
1709
  when input.scan(/[A-Z]\w*[?!]:/)
1710
1710
  new_token(:tUKEYWORD_Q_E, input.matched.chop.to_sym)
1711
- when input.scan(/\$[A-Za-z_]\w*/)
1711
+ when input.scan(/\$([A-Za-z_]\w*|[~*$?!@\/\\;,.=:<>"&`'+]|\d+|-[0-9_A-Za-z])/)
1712
1712
  new_token(:tGLOBALIDENT)
1713
1713
  when input.scan(/@[a-zA-Z_]\w*/)
1714
1714
  new_token(:tIVAR, input.matched.to_sym)
@@ -319,9 +319,16 @@ module RBS
319
319
  const_to_name(node.children[0])
320
320
  end
321
321
 
322
+ value_node = node.children.last
323
+ type = if value_node.nil?
324
+ # Give up type prediction when node is MASGN.
325
+ Types::Bases::Any.new(location: nil)
326
+ else
327
+ node_type(value_node)
328
+ end
322
329
  decls << AST::Declarations::Constant.new(
323
330
  name: const_name,
324
- type: node_type(node.children.last),
331
+ type: type,
325
332
  location: nil,
326
333
  comment: comments[node.first_lineno - 1]
327
334
  )
@@ -87,7 +87,7 @@ module RBS
87
87
  unless const_name(mix)
88
88
  RBS.logger.warn("Skipping anonymous module #{mix} included in #{mod}")
89
89
  else
90
- module_name = module_full_name = to_type_name(const_name(mix))
90
+ module_name = module_full_name = to_type_name(const_name(mix), full_name: true)
91
91
  if module_full_name.namespace == type_name.namespace
92
92
  module_name = TypeName.new(name: module_full_name.name, namespace: Namespace.empty)
93
93
  end
@@ -0,0 +1,88 @@
1
+ module RBS
2
+ class TypeAliasDependency
3
+ attr_reader :env
4
+
5
+ # Direct dependencies corresponds to a directed graph
6
+ # with vertices as types and directions based on assignment of types
7
+ attr_reader :direct_dependencies
8
+ # A hash which stores the transitive closure
9
+ # of the directed graph
10
+ attr_reader :dependencies
11
+
12
+ def initialize(env:)
13
+ @env = env
14
+ end
15
+
16
+ # Check if an alias type definition is circular & prohibited
17
+ def circular_definition?(alias_name)
18
+ # Construct transitive closure, if not constructed already
19
+ transitive_closure() unless @dependencies
20
+
21
+ # Check for recursive type alias
22
+ @dependencies[alias_name][alias_name]
23
+ end
24
+
25
+ def build_dependencies
26
+ return if @direct_dependencies
27
+
28
+ # Initialize hash(a directed graph)
29
+ @direct_dependencies = {}
30
+ # Initialize dependencies as an empty hash
31
+ @dependencies = {}
32
+ # Iterate over alias declarations inserted into environment
33
+ env.alias_decls.each do |name, entry|
34
+ # Construct a directed graph by recursively extracting type aliases
35
+ @direct_dependencies[name] = direct_dependency(entry.decl.type)
36
+ # Initialize dependencies with an empty hash
37
+ @dependencies[name] = {}
38
+ end
39
+ end
40
+
41
+ def transitive_closure
42
+ # Construct a graph of direct dependencies
43
+ build_dependencies()
44
+ # Construct transitive closure by using DFS(recursive technique)
45
+ @direct_dependencies.each_key do |name|
46
+ dependency(name, name)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ # Constructs directed graph recursively
53
+ def direct_dependency(type, result = Set[])
54
+ case type
55
+ when RBS::Types::Union, RBS::Types::Intersection, RBS::Types::Optional
56
+ # Iterate over nested types & extract type aliases recursively
57
+ type.each_type do |nested_type|
58
+ direct_dependency(nested_type, result)
59
+ end
60
+ when RBS::Types::Alias
61
+ # Append type name if the type is an alias
62
+ result << type.name
63
+ end
64
+
65
+ result
66
+ end
67
+
68
+ # Recursive function to construct transitive closure
69
+ def dependency(start, vertex, nested = nil)
70
+ if (start == vertex)
71
+ if (@direct_dependencies[start].include?(vertex) || nested)
72
+ # Mark a vertex as connected to itself
73
+ # if it is connected as an edge || a path(traverse multiple edges)
74
+ @dependencies[start][vertex] = true
75
+ end
76
+ else
77
+ # Mark a pair of vertices as connected while recursively performing DFS
78
+ @dependencies[start][vertex] = true
79
+ end
80
+
81
+ # Iterate over the direct dependencies of the vertex
82
+ @direct_dependencies[vertex]&.each do |type_name|
83
+ # Invoke the function unless it is already checked
84
+ dependency(start, type_name, start == type_name) unless @dependencies[start][type_name]
85
+ end
86
+ end
87
+ end
88
+ end
data/lib/rbs/validator.rb CHANGED
@@ -53,5 +53,10 @@ module RBS
53
53
  validate_type(type, context: context)
54
54
  end
55
55
  end
56
+
57
+ def validate_type_alias(entry:)
58
+ @type_alias_dependency ||= TypeAliasDependency.new(env: env)
59
+ raise RecursiveTypeAliasError.new(alias_names: [entry.decl.name], location: entry.decl.location) if @type_alias_dependency.circular_definition?(entry.decl.name)
60
+ end
56
61
  end
57
62
  end
data/lib/rbs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RBS
2
- VERSION = "1.3.2"
2
+ VERSION = "1.5.1"
3
3
  end
data/sig/errors.rbs CHANGED
@@ -196,4 +196,13 @@ module RBS
196
196
 
197
197
  def mixin_name: () -> String
198
198
  end
199
+
200
+ class RecursiveTypeAliasError < LoadingError
201
+ attr_reader alias_names: Array[TypeName]
202
+ attr_reader location: Location
203
+
204
+ def initialize: (alias_names: Array[TypeName], location: Location) -> void
205
+
206
+ def name: () -> String
207
+ end
199
208
  end
@@ -0,0 +1,22 @@
1
+ module RBS
2
+ class TypeAliasDependency
3
+ attr_reader env: Environment
4
+
5
+ attr_reader direct_dependencies: Hash[TypeName, Set[TypeName]]
6
+ attr_reader dependencies: Hash[TypeName, Hash[TypeName, bool]]
7
+
8
+ def initialize: (env: Environment) -> void
9
+
10
+ def circular_definition?: (TypeName alias_name) -> bool
11
+
12
+ def build_dependencies: () -> void
13
+
14
+ def transitive_closure: () -> void
15
+
16
+ private
17
+
18
+ def direct_dependency: (Types::t `type`, ?Set[TypeName] result) -> Set[TypeName]
19
+
20
+ def dependency: (TypeName start, TypeName vertex, ?boolish nested) -> void
21
+ end
22
+ end
data/sig/validator.rbs CHANGED
@@ -8,5 +8,7 @@ module RBS
8
8
  def absolute_type: (Types::t, context: TypeNameResolver::context) { (Types::t) -> TypeName } -> Types::t
9
9
 
10
10
  def validate_type: (Types::t, context: TypeNameResolver::context) -> void
11
+
12
+ def validate_type_alias: (entry: Environment::SingleEntry[TypeName, AST::Declarations::Alias]) -> void
11
13
  end
12
14
  end
@@ -0,0 +1,418 @@
1
+ # This module provides a framework for message digest libraries.
2
+ #
3
+ # You may want to look at OpenSSL::Digest as it supports more algorithms.
4
+ #
5
+ # A cryptographic hash function is a procedure that takes data and returns a
6
+ # fixed bit string: the hash value, also known as *digest*. Hash functions are
7
+ # also called one-way functions, it is easy to compute a digest from a message,
8
+ # but it is infeasible to generate a message from a digest.
9
+ #
10
+ # ## Examples
11
+ #
12
+ # require 'digest'
13
+ #
14
+ # # Compute a complete digest
15
+ # Digest::SHA256.digest 'message' #=> "\xABS\n\x13\xE4Y..."
16
+ #
17
+ # sha256 = Digest::SHA256.new
18
+ # sha256.digest 'message' #=> "\xABS\n\x13\xE4Y..."
19
+ #
20
+ # # Other encoding formats
21
+ # Digest::SHA256.hexdigest 'message' #=> "ab530a13e459..."
22
+ # Digest::SHA256.base64digest 'message' #=> "q1MKE+RZFJgr..."
23
+ #
24
+ # # Compute digest by chunks
25
+ # md5 = Digest::MD5.new
26
+ # md5.update 'message1'
27
+ # md5 << 'message2' # << is an alias for update
28
+ #
29
+ # md5.hexdigest #=> "94af09c09bb9..."
30
+ #
31
+ # # Compute digest for a file
32
+ # sha256 = Digest::SHA256.file 'testfile'
33
+ # sha256.hexdigest
34
+ #
35
+ # Additionally digests can be encoded in "bubble babble" format as a sequence of
36
+ # consonants and vowels which is more recognizable and comparable than a
37
+ # hexadecimal digest.
38
+ #
39
+ # require 'digest/bubblebabble'
40
+ #
41
+ # Digest::SHA256.bubblebabble 'message' #=> "xopoh-fedac-fenyh-..."
42
+ #
43
+ # See the bubble babble specification at
44
+ # http://web.mit.edu/kenta/www/one/bubblebabble/spec/jrtrjwzi/draft-huima-01.txt
45
+ # .
46
+ #
47
+ # ## Digest algorithms
48
+ #
49
+ # Different digest algorithms (or hash functions) are available:
50
+ #
51
+ # MD5
52
+ # : See RFC 1321 The MD5 Message-Digest Algorithm
53
+ # RIPEMD-160
54
+ # : As Digest::RMD160. See
55
+ # http://homes.esat.kuleuven.be/~bosselae/ripemd160.html.
56
+ # SHA1
57
+ # : See FIPS 180 Secure Hash Standard.
58
+ # SHA2 family
59
+ # : See FIPS 180 Secure Hash Standard which defines the following algorithms:
60
+ # * SHA512
61
+ # * SHA384
62
+ # * SHA256
63
+ #
64
+ #
65
+ #
66
+ # The latest versions of the FIPS publications can be found here:
67
+ # http://csrc.nist.gov/publications/PubsFIPS.html.
68
+ module Digest
69
+ # Returns a BubbleBabble encoded version of a given *string*.
70
+ #
71
+ def self.bubblebabble: (String) -> String
72
+
73
+ def self.const_missing: (Symbol name) -> singleton(::Digest::Base)
74
+
75
+ # Generates a hex-encoded version of a given *string*.
76
+ #
77
+ def self.hexencode: (String) -> String
78
+
79
+ private
80
+
81
+ def bubblebabble: (String) -> String
82
+
83
+ def hexencode: (String) -> String
84
+ end
85
+
86
+ # A mutex for Digest().
87
+ Digest::REQUIRE_MUTEX: Thread::Mutex
88
+
89
+ # This module provides instance methods for a digest implementation object to
90
+ # calculate message digest values.
91
+ module Digest::Instance
92
+ public
93
+
94
+ # Updates the digest using a given *string* and returns self.
95
+ #
96
+ # The update() method and the left-shift operator are overridden by each
97
+ # implementation subclass. (One should be an alias for the other)
98
+ #
99
+ def <<: (String) -> self
100
+
101
+ # If a string is given, checks whether it is equal to the hex-encoded hash value
102
+ # of the digest object. If another digest instance is given, checks whether
103
+ # they have the same hash value. Otherwise returns false.
104
+ #
105
+ def ==: (::Digest::Instance | String) -> bool
106
+
107
+ # If none is given, returns the resulting hash value of the digest in a base64
108
+ # encoded form, keeping the digest's state.
109
+ #
110
+ # If a `string` is given, returns the hash value for the given `string` in a
111
+ # base64 encoded form, resetting the digest to the initial state before and
112
+ # after the process.
113
+ #
114
+ # In either case, the return value is properly padded with '=' and contains no
115
+ # line feeds.
116
+ #
117
+ def base64digest: (?String? str) -> String
118
+
119
+ # Returns the resulting hash value and resets the digest to the initial state.
120
+ #
121
+ def base64digest!: () -> String
122
+
123
+ # Returns the block length of the digest.
124
+ #
125
+ # This method is overridden by each implementation subclass.
126
+ #
127
+ def block_length: () -> Integer
128
+
129
+ # Returns the resulting hash value in a Bubblebabble encoded form.
130
+ #
131
+ def bubblebabble: () -> String
132
+
133
+ # If none is given, returns the resulting hash value of the digest, keeping the
134
+ # digest's state.
135
+ #
136
+ # If a *string* is given, returns the hash value for the given *string*,
137
+ # resetting the digest to the initial state before and after the process.
138
+ #
139
+ def digest: (?String) -> String
140
+
141
+ # Returns the resulting hash value and resets the digest to the initial state.
142
+ #
143
+ def digest!: () -> String
144
+
145
+ # Returns the length of the hash value of the digest.
146
+ #
147
+ # This method should be overridden by each implementation subclass. If not,
148
+ # digest_obj.digest().length() is returned.
149
+ #
150
+ def digest_length: () -> Integer
151
+
152
+ # Updates the digest with the contents of a given file *name* and returns self.
153
+ #
154
+ def file: (String name) -> self
155
+
156
+ # If none is given, returns the resulting hash value of the digest in a
157
+ # hex-encoded form, keeping the digest's state.
158
+ #
159
+ # If a *string* is given, returns the hash value for the given *string* in a
160
+ # hex-encoded form, resetting the digest to the initial state before and after
161
+ # the process.
162
+ #
163
+ def hexdigest: (?String) -> String
164
+
165
+ # Returns the resulting hash value in a hex-encoded form and resets the digest
166
+ # to the initial state.
167
+ #
168
+ def hexdigest!: () -> String
169
+
170
+ # Creates a printable version of the digest object.
171
+ #
172
+ def inspect: () -> String
173
+
174
+ # Returns digest_obj.digest_length().
175
+ #
176
+ def length: () -> Integer
177
+
178
+ # Returns a new, initialized copy of the digest object. Equivalent to
179
+ # digest_obj.clone().reset().
180
+ #
181
+ def new: () -> ::Digest::Base
182
+
183
+ # Resets the digest to the initial state and returns self.
184
+ #
185
+ # This method is overridden by each implementation subclass.
186
+ #
187
+ def reset: () -> self
188
+
189
+ # Returns digest_obj.digest_length().
190
+ #
191
+ def size: () -> Integer
192
+
193
+ # Returns digest_obj.hexdigest().
194
+ #
195
+ def to_s: () -> String
196
+
197
+ # Updates the digest using a given *string* and returns self.
198
+ #
199
+ # The update() method and the left-shift operator are overridden by each
200
+ # implementation subclass. (One should be an alias for the other)
201
+ #
202
+ def update: (String) -> self
203
+
204
+ private
205
+
206
+ # Finishes the digest and returns the resulting hash value.
207
+ #
208
+ # This method is overridden by each implementation subclass and often made
209
+ # private, because some of those subclasses may leave internal data
210
+ # uninitialized. Do not call this method from outside. Use #digest!() instead,
211
+ # which ensures that internal data be reset for security reasons.
212
+ #
213
+ def finish: () -> self
214
+ end
215
+
216
+ # This module stands as a base class for digest implementation classes.
217
+ class Digest::Class
218
+ include ::Digest::Instance
219
+
220
+ # Returns the base64 encoded hash value of a given *string*. The return value
221
+ # is properly padded with '=' and contains no line feeds.
222
+ #
223
+ def self.base64digest: (String str, *untyped) -> String
224
+
225
+ # Returns the BubbleBabble encoded hash value of a given *string*.
226
+ #
227
+ def self.bubblebabble: (String, *untyped) -> String
228
+
229
+ # Returns the hash value of a given *string*. This is equivalent to
230
+ # Digest::Class.new(*parameters).digest(string), where extra *parameters*, if
231
+ # any, are passed through to the constructor and the *string* is passed to
232
+ # #digest().
233
+ #
234
+ def self.digest: (String, *untyped) -> String
235
+
236
+ # Creates a digest object and reads a given file, *name*. Optional arguments are
237
+ # passed to the constructor of the digest class.
238
+ #
239
+ # p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
240
+ # # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
241
+ #
242
+ def self.file: (String name, *untyped) -> ::Digest::Class
243
+
244
+ # Returns the hex-encoded hash value of a given *string*. This is almost
245
+ # equivalent to Digest.hexencode(Digest::Class.new(*parameters).digest(string)).
246
+ #
247
+ def self.hexdigest: (String, *untyped) -> String
248
+
249
+ private
250
+
251
+ def initialize: () -> self
252
+ end
253
+
254
+ # This abstract class provides a common interface to message digest
255
+ # implementation classes written in C.
256
+ #
257
+ # ## Write a Digest subclass in C
258
+ # Digest::Base provides a common interface to message digest classes written in
259
+ # C. These classes must provide a struct of type rb_digest_metadata_t:
260
+ # typedef int (*rb_digest_hash_init_func_t)(void *);
261
+ # typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
262
+ # typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
263
+ #
264
+ # typedef struct {
265
+ # int api_version;
266
+ # size_t digest_len;
267
+ # size_t block_len;
268
+ # size_t ctx_size;
269
+ # rb_digest_hash_init_func_t init_func;
270
+ # rb_digest_hash_update_func_t update_func;
271
+ # rb_digest_hash_finish_func_t finish_func;
272
+ # } rb_digest_metadata_t;
273
+ #
274
+ # This structure must be set as an instance variable named `metadata` (without
275
+ # the +@+ in front of the name). By example:
276
+ # static const rb_digest_metadata_t sha1 = {
277
+ # RUBY_DIGEST_API_VERSION,
278
+ # SHA1_DIGEST_LENGTH,
279
+ # SHA1_BLOCK_LENGTH,
280
+ # sizeof(SHA1_CTX),
281
+ # (rb_digest_hash_init_func_t)SHA1_Init,
282
+ # (rb_digest_hash_update_func_t)SHA1_Update,
283
+ # (rb_digest_hash_finish_func_t)SHA1_Finish,
284
+ # };
285
+ #
286
+ # rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
287
+ # Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
288
+ class Digest::Base < Digest::Class
289
+ public
290
+
291
+ # Update the digest using given *string* and return `self`.
292
+ #
293
+ def <<: (String) -> self
294
+
295
+ # Return the block length of the digest in bytes.
296
+ #
297
+ def block_length: () -> Integer
298
+
299
+ # Return the length of the hash value in bytes.
300
+ #
301
+ def digest_length: () -> Integer
302
+
303
+ # Reset the digest to its initial state and return `self`.
304
+ #
305
+ def reset: () -> self
306
+
307
+ # Update the digest using given *string* and return `self`.
308
+ #
309
+ def update: (String) -> self
310
+
311
+ private
312
+
313
+ def finish: () -> String
314
+
315
+ def initialize_copy: (::Digest::Base) -> self
316
+ end
317
+
318
+ # A class for calculating message digests using the SHA-1 Secure Hash Algorithm
319
+ # by NIST (the US' National Institute of Standards and Technology), described in
320
+ # FIPS PUB 180-1.
321
+ #
322
+ # See Digest::Instance for digest API.
323
+ #
324
+ # SHA-1 calculates a digest of 160 bits (20 bytes).
325
+ #
326
+ # ## Examples
327
+ # require 'digest'
328
+ #
329
+ # # Compute a complete digest
330
+ # Digest::SHA1.hexdigest 'abc' #=> "a9993e36..."
331
+ #
332
+ # # Compute digest by chunks
333
+ # sha1 = Digest::SHA1.new # =>#<Digest::SHA1>
334
+ # sha1.update "ab"
335
+ # sha1 << "c" # alias for #update
336
+ # sha1.hexdigest # => "a9993e36..."
337
+ #
338
+ # # Use the same object to compute another digest
339
+ # sha1.reset
340
+ # sha1 << "message"
341
+ # sha1.hexdigest # => "6f9b9af3..."
342
+ class Digest::SHA1 < Digest::Base
343
+ end
344
+
345
+ # A class for calculating message digests using the MD5 Message-Digest Algorithm
346
+ # by RSA Data Security, Inc., described in RFC1321.
347
+ #
348
+ # MD5 calculates a digest of 128 bits (16 bytes).
349
+ #
350
+ # ## Examples
351
+ # require 'digest'
352
+ #
353
+ # # Compute a complete digest
354
+ # Digest::MD5.hexdigest 'abc' #=> "90015098..."
355
+ #
356
+ # # Compute digest by chunks
357
+ # md5 = Digest::MD5.new # =>#<Digest::MD5>
358
+ # md5.update "ab"
359
+ # md5 << "c" # alias for #update
360
+ # md5.hexdigest # => "90015098..."
361
+ #
362
+ # # Use the same object to compute another digest
363
+ # md5.reset
364
+ # md5 << "message"
365
+ # md5.hexdigest # => "78e73102..."
366
+ class Digest::MD5 < Digest::Base
367
+ end
368
+
369
+ # A class for calculating message digests using RIPEMD-160 cryptographic hash
370
+ # function, designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel.
371
+ #
372
+ # RMD160 calculates a digest of 160 bits (20 bytes).
373
+ #
374
+ # ## Examples
375
+ # require 'digest'
376
+ #
377
+ # # Compute a complete digest
378
+ # Digest::RMD160.hexdigest 'abc' #=> "8eb208f7..."
379
+ #
380
+ # # Compute digest by chunks
381
+ # rmd160 = Digest::RMD160.new # =>#<Digest::RMD160>
382
+ # rmd160.update "ab"
383
+ # rmd160 << "c" # alias for #update
384
+ # rmd160.hexdigest # => "8eb208f7..."
385
+ #
386
+ # # Use the same object to compute another digest
387
+ # rmd160.reset
388
+ # rmd160 << "message"
389
+ # rmd160.hexdigest # => "1dddbe1b..."
390
+ class Digest::RMD160 < Digest::Base
391
+ end
392
+
393
+ class Digest::SHA256 < Digest::Base
394
+ end
395
+
396
+ class Digest::SHA384 < Digest::Base
397
+ end
398
+
399
+ class Digest::SHA512 < Digest::Base
400
+ end
401
+
402
+ class Object
403
+ # Returns a Digest subclass by `name` in a thread-safe manner even when
404
+ # on-demand loading is involved.
405
+ #
406
+ # require 'digest'
407
+ #
408
+ # Digest("MD5")
409
+ # # => Digest::MD5
410
+ #
411
+ # Digest(:SHA256)
412
+ # # => Digest::SHA256
413
+ #
414
+ # Digest(:Foo)
415
+ # # => LoadError: library not found for class Digest::Foo -- digest/foo
416
+ #
417
+ def Digest: (String | Symbol name) -> singleton(::Digest::Base)
418
+ end