Skip to content

Commit d3bce7f

Browse files
committed
Add signature for Digest::SHA2
1 parent a60a6ad commit d3bce7f

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

stdlib/digest/0/digest.rbs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,116 @@ end
471471
class Digest::SHA1 < Digest::Base
472472
end
473473

474+
# <!-- rdoc-file=ext/digest/sha2/lib/sha2.rb -->
475+
# A meta digest provider class for SHA256, SHA384 and SHA512.
476+
#
477+
# FIPS 180-2 describes SHA2 family of digest algorithms. It defines three
478+
# algorithms:
479+
# * one which works on chunks of 512 bits and returns a 256-bit digest
480+
# (SHA256),
481+
# * one which works on chunks of 1024 bits and returns a 384-bit digest
482+
# (SHA384),
483+
# * and one which works on chunks of 1024 bits and returns a 512-bit digest
484+
# (SHA512).
485+
#
486+
# ## Examples
487+
# require 'digest'
488+
#
489+
# # Compute a complete digest
490+
# Digest::SHA2.hexdigest 'abc' # => "ba7816bf8..."
491+
# Digest::SHA2.new(256).hexdigest 'abc' # => "ba7816bf8..."
492+
# Digest::SHA256.hexdigest 'abc' # => "ba7816bf8..."
493+
#
494+
# Digest::SHA2.new(384).hexdigest 'abc' # => "cb00753f4..."
495+
# Digest::SHA384.hexdigest 'abc' # => "cb00753f4..."
496+
#
497+
# Digest::SHA2.new(512).hexdigest 'abc' # => "ddaf35a19..."
498+
# Digest::SHA512.hexdigest 'abc' # => "ddaf35a19..."
499+
#
500+
# # Compute digest by chunks
501+
# sha2 = Digest::SHA2.new # =>#<Digest::SHA2:256>
502+
# sha2.update "ab"
503+
# sha2 << "c" # alias for #update
504+
# sha2.hexdigest # => "ba7816bf8..."
505+
#
506+
# # Use the same object to compute another digest
507+
# sha2.reset
508+
# sha2 << "message"
509+
# sha2.hexdigest # => "ab530a13e..."
510+
#
511+
class Digest::SHA2 < Digest::Class
512+
# <!--
513+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
514+
# - Digest::SHA2.new(bitlen = 256) -> digest_obj
515+
# -->
516+
# Create a new SHA2 hash object with a given bit length.
517+
#
518+
# Valid bit lengths are 256, 384 and 512.
519+
#
520+
def initialize: (?(256 | 384 | 512) bitlen) -> void
521+
522+
# <!--
523+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
524+
# - digest_obj.reset -> digest_obj
525+
# -->
526+
# Reset the digest to the initial state and return self.
527+
#
528+
def reset: () -> self
529+
530+
# <!--
531+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
532+
# - digest_obj.update(string) -> digest_obj
533+
# - digest_obj << string -> digest_obj
534+
# -->
535+
# Update the digest using a given *string* and return self.
536+
#
537+
def update: (String) -> self
538+
539+
private def finish: () -> String
540+
541+
# <!--
542+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
543+
# - <<(str)
544+
# -->
545+
#
546+
alias << update
547+
548+
# <!--
549+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
550+
# - digest_obj.block_length -> Integer
551+
# -->
552+
# Return the block length of the digest in bytes.
553+
#
554+
# Digest::SHA256.new.block_length * 8
555+
# # => 512
556+
# Digest::SHA384.new.block_length * 8
557+
# # => 1024
558+
# Digest::SHA512.new.block_length * 8
559+
# # => 1024
560+
#
561+
def block_length: () -> Integer
562+
563+
# <!--
564+
# rdoc-file=ext/digest/sha2/lib/sha2.rb
565+
# - digest_obj.digest_length -> Integer
566+
# -->
567+
# Return the length of the hash value (the digest) in bytes.
568+
#
569+
# Digest::SHA256.new.digest_length * 8
570+
# # => 256
571+
# Digest::SHA384.new.digest_length * 8
572+
# # => 384
573+
# Digest::SHA512.new.digest_length * 8
574+
# # => 512
575+
#
576+
# For example, digests produced by Digest::SHA256 will always be 32 bytes (256
577+
# bits) in size.
578+
#
579+
def digest_length: () -> Integer
580+
581+
def initialize_copy: (untyped) -> untyped
582+
end
583+
474584
# <!-- rdoc-file=ext/digest/md5/md5init.c -->
475585
# A class for calculating message digests using the MD5 Message-Digest Algorithm
476586
# by RSA Data Security, Inc., described in RFC1321.

test/raap/digest.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@
5454
end
5555
end
5656

57+
argv << 'Digest::SHA2'
58+
5759
RaaP::CLI.new(argv).load.run

0 commit comments

Comments
 (0)