diff --git a/Gemfile b/Gemfile index a605ac476..7ddc41d1b 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "json-schema" gem 'stackprof' gem "goodcheck" gem "dbm" +gem 'digest' # Test gems gem "rbs-amber", path: "test/assets/test-gem" diff --git a/stdlib/digest/0/digest.rbs b/stdlib/digest/0/digest.rbs new file mode 100644 index 000000000..11fd0b095 --- /dev/null +++ b/stdlib/digest/0/digest.rbs @@ -0,0 +1,400 @@ +# This module provides a framework for message digest libraries. +# +# You may want to look at OpenSSL::Digest as it supports more algorithms. +# +# A cryptographic hash function is a procedure that takes data and returns a +# fixed bit string: the hash value, also known as *digest*. Hash functions are +# also called one-way functions, it is easy to compute a digest from a message, +# but it is infeasible to generate a message from a digest. +# +# ## Examples +# +# require 'digest' +# +# # Compute a complete digest +# Digest::SHA256.digest 'message' #=> "\xABS\n\x13\xE4Y..." +# +# sha256 = Digest::SHA256.new +# sha256.digest 'message' #=> "\xABS\n\x13\xE4Y..." +# +# # Other encoding formats +# Digest::SHA256.hexdigest 'message' #=> "ab530a13e459..." +# Digest::SHA256.base64digest 'message' #=> "q1MKE+RZFJgr..." +# +# # Compute digest by chunks +# md5 = Digest::MD5.new +# md5.update 'message1' +# md5 << 'message2' # << is an alias for update +# +# md5.hexdigest #=> "94af09c09bb9..." +# +# # Compute digest for a file +# sha256 = Digest::SHA256.file 'testfile' +# sha256.hexdigest +# +# Additionally digests can be encoded in "bubble babble" format as a sequence of +# consonants and vowels which is more recognizable and comparable than a +# hexadecimal digest. +# +# require 'digest/bubblebabble' +# +# Digest::SHA256.bubblebabble 'message' #=> "xopoh-fedac-fenyh-..." +# +# See the bubble babble specification at +# http://web.mit.edu/kenta/www/one/bubblebabble/spec/jrtrjwzi/draft-huima-01.txt +# . +# +# ## Digest algorithms +# +# Different digest algorithms (or hash functions) are available: +# +# MD5 +# : See RFC 1321 The MD5 Message-Digest Algorithm +# RIPEMD-160 +# : As Digest::RMD160. See +# http://homes.esat.kuleuven.be/~bosselae/ripemd160.html. +# SHA1 +# : See FIPS 180 Secure Hash Standard. +# SHA2 family +# : See FIPS 180 Secure Hash Standard which defines the following algorithms: +# * SHA512 +# * SHA384 +# * SHA256 +# +# +# +# The latest versions of the FIPS publications can be found here: +# http://csrc.nist.gov/publications/PubsFIPS.html. +module Digest + # Returns a BubbleBabble encoded version of a given *string*. + # + def self.bubblebabble: (String) -> String + + def self.const_missing: (Symbol name) -> singleton(::Digest::Base) + + # Generates a hex-encoded version of a given *string*. + # + def self.hexencode: (String) -> String + + private + + def bubblebabble: (String) -> String + + def hexencode: (String) -> String +end + +# A mutex for Digest(). +Digest::REQUIRE_MUTEX: Thread::Mutex + +# This module provides instance methods for a digest implementation object to +# calculate message digest values. +module Digest::Instance + public + + # Updates the digest using a given *string* and returns self. + # + # The update() method and the left-shift operator are overridden by each + # implementation subclass. (One should be an alias for the other) + # + def <<: (String) -> self + + # If a string is given, checks whether it is equal to the hex-encoded hash value + # of the digest object. If another digest instance is given, checks whether + # they have the same hash value. Otherwise returns false. + # + def ==: (::Digest::Instance | String) -> bool + + # If none is given, returns the resulting hash value of the digest in a base64 + # encoded form, keeping the digest's state. + # + # If a `string` is given, returns the hash value for the given `string` in a + # base64 encoded form, resetting the digest to the initial state before and + # after the process. + # + # In either case, the return value is properly padded with '=' and contains no + # line feeds. + # + def base64digest: (?String? str) -> String + + # Returns the resulting hash value and resets the digest to the initial state. + # + def base64digest!: () -> String + + # Returns the block length of the digest. + # + # This method is overridden by each implementation subclass. + # + def block_length: () -> Integer + + # Returns the resulting hash value in a Bubblebabble encoded form. + # + def bubblebabble: () -> String + + # If none is given, returns the resulting hash value of the digest, keeping the + # digest's state. + # + # If a *string* is given, returns the hash value for the given *string*, + # resetting the digest to the initial state before and after the process. + # + def digest: (?String) -> String + + # Returns the resulting hash value and resets the digest to the initial state. + # + def digest!: () -> String + + # Returns the length of the hash value of the digest. + # + # This method should be overridden by each implementation subclass. If not, + # digest_obj.digest().length() is returned. + # + def digest_length: () -> Integer + + # Updates the digest with the contents of a given file *name* and returns self. + # + def file: (String name) -> self + + # If none is given, returns the resulting hash value of the digest in a + # hex-encoded form, keeping the digest's state. + # + # If a *string* is given, returns the hash value for the given *string* in a + # hex-encoded form, resetting the digest to the initial state before and after + # the process. + # + def hexdigest: (?String) -> String + + # Returns the resulting hash value in a hex-encoded form and resets the digest + # to the initial state. + # + def hexdigest!: () -> String + + # Creates a printable version of the digest object. + # + def inspect: () -> String + + # Returns digest_obj.digest_length(). + # + def length: () -> Integer + + # Returns a new, initialized copy of the digest object. Equivalent to + # digest_obj.clone().reset(). + # + def new: () -> ::Digest::Base + + # Resets the digest to the initial state and returns self. + # + # This method is overridden by each implementation subclass. + # + def reset: () -> self + + # Returns digest_obj.digest_length(). + # + def size: () -> Integer + + # Returns digest_obj.hexdigest(). + # + def to_s: () -> String + + # Updates the digest using a given *string* and returns self. + # + # The update() method and the left-shift operator are overridden by each + # implementation subclass. (One should be an alias for the other) + # + def update: (String) -> self + + private + + # Finishes the digest and returns the resulting hash value. + # + # This method is overridden by each implementation subclass and often made + # private, because some of those subclasses may leave internal data + # uninitialized. Do not call this method from outside. Use #digest!() instead, + # which ensures that internal data be reset for security reasons. + # + def finish: () -> self +end + +# This module stands as a base class for digest implementation classes. +class Digest::Class + include ::Digest::Instance + + # Returns the base64 encoded hash value of a given *string*. The return value + # is properly padded with '=' and contains no line feeds. + # + def self.base64digest: (String str, *untyped) -> String + + # Returns the BubbleBabble encoded hash value of a given *string*. + # + def self.bubblebabble: (String, *untyped) -> String + + # Returns the hash value of a given *string*. This is equivalent to + # Digest::Class.new(*parameters).digest(string), where extra *parameters*, if + # any, are passed through to the constructor and the *string* is passed to + # #digest(). + # + def self.digest: (String, *untyped) -> String + + # Creates a digest object and reads a given file, *name*. Optional arguments are + # passed to the constructor of the digest class. + # + # p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest + # # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534" + # + def self.file: (String name, *untyped) -> ::Digest::Class + + # Returns the hex-encoded hash value of a given *string*. This is almost + # equivalent to Digest.hexencode(Digest::Class.new(*parameters).digest(string)). + # + def self.hexdigest: (String, *untyped) -> String + + private + + def initialize: () -> self +end + +# This abstract class provides a common interface to message digest +# implementation classes written in C. +# +# ## Write a Digest subclass in C +# Digest::Base provides a common interface to message digest classes written in +# C. These classes must provide a struct of type rb_digest_metadata_t: +# typedef int (*rb_digest_hash_init_func_t)(void *); +# typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t); +# typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *); +# +# typedef struct { +# int api_version; +# size_t digest_len; +# size_t block_len; +# size_t ctx_size; +# rb_digest_hash_init_func_t init_func; +# rb_digest_hash_update_func_t update_func; +# rb_digest_hash_finish_func_t finish_func; +# } rb_digest_metadata_t; +# +# This structure must be set as an instance variable named `metadata` (without +# the +@+ in front of the name). By example: +# static const rb_digest_metadata_t sha1 = { +# RUBY_DIGEST_API_VERSION, +# SHA1_DIGEST_LENGTH, +# SHA1_BLOCK_LENGTH, +# sizeof(SHA1_CTX), +# (rb_digest_hash_init_func_t)SHA1_Init, +# (rb_digest_hash_update_func_t)SHA1_Update, +# (rb_digest_hash_finish_func_t)SHA1_Finish, +# }; +# +# rb_ivar_set(cDigest_SHA1, rb_intern("metadata"), +# Data_Wrap_Struct(0, 0, 0, (void *)&sha1)); +class Digest::Base < Digest::Class + public + + # Update the digest using given *string* and return `self`. + # + def <<: (String) -> self + + # Return the block length of the digest in bytes. + # + def block_length: () -> Integer + + # Return the length of the hash value in bytes. + # + def digest_length: () -> Integer + + # Reset the digest to its initial state and return `self`. + # + def reset: () -> self + + # Update the digest using given *string* and return `self`. + # + def update: (String) -> self + + private + + def finish: () -> String + + def initialize_copy: (::Digest::Base) -> self +end + +# A class for calculating message digests using the SHA-1 Secure Hash Algorithm +# by NIST (the US' National Institute of Standards and Technology), described in +# FIPS PUB 180-1. +# +# See Digest::Instance for digest API. +# +# SHA-1 calculates a digest of 160 bits (20 bytes). +# +# ## Examples +# require 'digest' +# +# # Compute a complete digest +# Digest::SHA1.hexdigest 'abc' #=> "a9993e36..." +# +# # Compute digest by chunks +# sha1 = Digest::SHA1.new # =># +# sha1.update "ab" +# sha1 << "c" # alias for #update +# sha1.hexdigest # => "a9993e36..." +# +# # Use the same object to compute another digest +# sha1.reset +# sha1 << "message" +# sha1.hexdigest # => "6f9b9af3..." +class Digest::SHA1 < Digest::Base +end + +# A class for calculating message digests using the MD5 Message-Digest Algorithm +# by RSA Data Security, Inc., described in RFC1321. +# +# MD5 calculates a digest of 128 bits (16 bytes). +# +# ## Examples +# require 'digest' +# +# # Compute a complete digest +# Digest::MD5.hexdigest 'abc' #=> "90015098..." +# +# # Compute digest by chunks +# md5 = Digest::MD5.new # =># +# md5.update "ab" +# md5 << "c" # alias for #update +# md5.hexdigest # => "90015098..." +# +# # Use the same object to compute another digest +# md5.reset +# md5 << "message" +# md5.hexdigest # => "78e73102..." +class Digest::MD5 < Digest::Base +end + +# A class for calculating message digests using RIPEMD-160 cryptographic hash +# function, designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel. +# +# RMD160 calculates a digest of 160 bits (20 bytes). +# +# ## Examples +# require 'digest' +# +# # Compute a complete digest +# Digest::RMD160.hexdigest 'abc' #=> "8eb208f7..." +# +# # Compute digest by chunks +# rmd160 = Digest::RMD160.new # =># +# rmd160.update "ab" +# rmd160 << "c" # alias for #update +# rmd160.hexdigest # => "8eb208f7..." +# +# # Use the same object to compute another digest +# rmd160.reset +# rmd160 << "message" +# rmd160.hexdigest # => "1dddbe1b..." +class Digest::RMD160 < Digest::Base +end + +class Digest::SHA256 < Digest::Base +end + +class Digest::SHA384 < Digest::Base +end + +class Digest::SHA512 < Digest::Base +end diff --git a/test/stdlib/digest/DigestMD5_test.rb b/test/stdlib/digest/DigestMD5_test.rb new file mode 100644 index 000000000..d1057bbe6 --- /dev/null +++ b/test/stdlib/digest/DigestMD5_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestMD5SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::MD5)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::MD5, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::MD5, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::MD5, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::MD5, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::MD5, :hexdigest, '_hexdigest_' + end +end + +class DigestMD5InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::MD5' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::MD5.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::MD5.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::MD5.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::MD5.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::MD5.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::MD5.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::MD5.new, :initialize_copy, ::Digest::MD5.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::MD5.new, :==, ::Digest::MD5.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::MD5.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::MD5.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::MD5.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::MD5.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::MD5.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::MD5.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::MD5.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::MD5.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::MD5.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::MD5.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::MD5.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::MD5.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::MD5.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::MD5.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::MD5.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::MD5.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::MD5.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::MD5.new, :to_s + end +end diff --git a/test/stdlib/digest/DigestRMD160_test.rb b/test/stdlib/digest/DigestRMD160_test.rb new file mode 100644 index 000000000..276fef368 --- /dev/null +++ b/test/stdlib/digest/DigestRMD160_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestRMD160SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::RMD160)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::RMD160, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::RMD160, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::RMD160, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::RMD160, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::RMD160, :hexdigest, '_hexdigest_' + end +end + +class DigestRMD160InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::RMD160' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::RMD160.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::RMD160.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::RMD160.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::RMD160.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::RMD160.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::RMD160.new, :initialize_copy, ::Digest::RMD160.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::RMD160.new, :==, ::Digest::RMD160.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::RMD160.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::RMD160.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::RMD160.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::RMD160.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::RMD160.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::RMD160.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::RMD160.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::RMD160.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::RMD160.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::RMD160.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::RMD160.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::RMD160.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::RMD160.new, :to_s + end +end diff --git a/test/stdlib/digest/DigestSHA1_test.rb b/test/stdlib/digest/DigestSHA1_test.rb new file mode 100644 index 000000000..7d8af8024 --- /dev/null +++ b/test/stdlib/digest/DigestSHA1_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestSHA1SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::SHA1)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::SHA1, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::SHA1, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::SHA1, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::SHA1, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::SHA1, :hexdigest, '_hexdigest_' + end +end + +class DigestSHA1InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::SHA1' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::SHA1.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::SHA1.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::SHA1.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::SHA1.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::SHA1.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::SHA1.new, :initialize_copy, ::Digest::SHA1.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA1.new, :==, ::Digest::SHA1.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA1.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA1.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA1.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA1.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA1.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA1.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::SHA1.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA1.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA1.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::SHA1.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::SHA1.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::SHA1.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::SHA1.new, :to_s + end +end diff --git a/test/stdlib/digest/DigestSHA256_test.rb b/test/stdlib/digest/DigestSHA256_test.rb new file mode 100644 index 000000000..75eb24a3d --- /dev/null +++ b/test/stdlib/digest/DigestSHA256_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestSHA256SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::SHA256)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::SHA256, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::SHA256, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::SHA256, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::SHA256, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::SHA256, :hexdigest, '_hexdigest_' + end +end + +class DigestSHA256InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::SHA256' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::SHA256.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::SHA256.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::SHA256.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::SHA256.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::SHA256.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::SHA256.new, :initialize_copy, ::Digest::SHA256.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA256.new, :==, ::Digest::SHA256.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA256.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA256.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA256.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA256.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA256.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA256.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::SHA256.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA256.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA256.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::SHA256.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::SHA256.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::SHA256.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::SHA256.new, :to_s + end +end diff --git a/test/stdlib/digest/DigestSHA384_test.rb b/test/stdlib/digest/DigestSHA384_test.rb new file mode 100644 index 000000000..922b6b89e --- /dev/null +++ b/test/stdlib/digest/DigestSHA384_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestSHA384SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::SHA384)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::SHA384, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::SHA384, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::SHA384, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::SHA384, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::SHA384, :hexdigest, '_hexdigest_' + end +end + +class DigestSHA384InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::SHA384' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::SHA384.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::SHA384.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::SHA384.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::SHA384.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::SHA384.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::SHA384.new, :initialize_copy, ::Digest::SHA384.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA384.new, :==, ::Digest::SHA384.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA384.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA384.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA384.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA384.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA384.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA384.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::SHA384.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA384.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA384.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::SHA384.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::SHA384.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::SHA384.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::SHA384.new, :to_s + end +end diff --git a/test/stdlib/digest/DigestSHA512_test.rb b/test/stdlib/digest/DigestSHA512_test.rb new file mode 100644 index 000000000..da33f449e --- /dev/null +++ b/test/stdlib/digest/DigestSHA512_test.rb @@ -0,0 +1,162 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestSHA512SingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest::SHA512)' + + def test_base64digest + assert_send_type '(::String str) -> ::String', + ::Digest::SHA512, :base64digest, '_base64digest_' + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest::SHA512, :bubblebabble, '_bubblebabble_' + end + + def test_digest + assert_send_type '(::String) -> ::String', + ::Digest::SHA512, :digest, '_digest_' + end + + def test_file + assert_send_type '(::String) -> ::Digest::Class', + ::Digest::SHA512, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(::String) -> ::String', + ::Digest::SHA512, :hexdigest, '_hexdigest_' + end +end + +class DigestSHA512InstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest::SHA512' + + def test_left_shift + assert_send_type '(::String) -> self', + ::Digest::SHA512.new, :<<, '_binary_left_shift_' + end + + def test_block_length + assert_send_type '() -> ::Integer', + ::Digest::SHA512.new, :block_length + end + + def test_digest_length + assert_send_type '() -> ::Integer', + ::Digest::SHA512.new, :digest_length + end + + def test_reset + assert_send_type '() -> self', + ::Digest::SHA512.new, :reset + end + + def test_update + assert_send_type '(::String) -> self', + ::Digest::SHA512.new, :update, '_update_' + end + + def test_finish + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :finish + end + + def test_initialize_copy + assert_send_type '(::Digest::Base) -> self', + ::Digest::SHA512.new, :initialize_copy, ::Digest::SHA512.new + end + + def test_equal + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA512.new, :==, ::Digest::SHA512.new + + assert_send_type '(::Digest::Instance | ::String) -> bool', + ::Digest::SHA512.new, :==, '_equal_' + end + + def test_base64digest + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA512.new, :base64digest + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA512.new, :base64digest, nil + + assert_send_type '(?::String? str) -> ::String', + ::Digest::SHA512.new, :base64digest, '_base64digest_' + end + + def test_base64digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :base64digest! + end + + def test_bubblebabble + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :bubblebabble + end + + def test_digest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA512.new, :digest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA512.new, :digest, '_digest_' + end + + def test_digest_bang + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :digest + end + + def test_file + assert_send_type '(::String) -> self', + ::Digest::SHA512.new, :file, 'README.md' + end + + def test_hexdigest + assert_send_type '(?::String) -> ::String', + ::Digest::SHA512.new, :hexdigest + + assert_send_type '(?::String) -> ::String', + ::Digest::SHA512.new, :hexdigest, '_hexdigest_' + end + + def test_hexdigest_bang + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :hexdigest! + end + + def test_inspect + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :inspect + end + + def test_length + assert_send_type '() -> ::Integer', + ::Digest::SHA512.new, :length + end + + def test_new + assert_send_type '() -> ::Digest::Base', + ::Digest::SHA512.new, :new + end + + def test_size + assert_send_type '() -> ::Integer', + ::Digest::SHA512.new, :size + end + + def test_to_s + assert_send_type '() -> ::String', + ::Digest::SHA512.new, :to_s + end +end diff --git a/test/stdlib/digest/Digest_test.rb b/test/stdlib/digest/Digest_test.rb new file mode 100644 index 000000000..0bba249cd --- /dev/null +++ b/test/stdlib/digest/Digest_test.rb @@ -0,0 +1,60 @@ +require_relative '../test_helper' +require 'digest' +require 'digest/bubblebabble' + +class DigestSingletonTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing 'singleton(::Digest)' + + + def test_const_missing + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :SHA1 + + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :MD5 + + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :RMD160 + + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :SHA256 + + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :SHA384 + + assert_send_type '(::Symbol name) -> singleton(::Digest::Base)', + ::Digest, :const_missing, :SHA512 + end + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + ::Digest, :bubblebabble, '_bubblebabble_' + end + + def test_hexencode + assert_send_type '(::String) -> ::String', + ::Digest, :hexencode, '_hexencode_' + end +end + +class DigestInstanceTest < Test::Unit::TestCase + include TypeAssertions + + library 'digest' + testing '::Digest' + + def test_bubblebabble + assert_send_type '(::String) -> ::String', + Class.new.include(Digest).new, + :bubblebabble, '_bubblebabble_' + end + + def test_hexencode + assert_send_type '(::String) -> ::String', + Class.new.include(Digest).new, + :hexencode, '_hexencode_' + end +end