diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-07-13 20:06:14 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-07-13 20:06:14 +0000 |
commit | 76d7dae26ab8b56dbafcec710fc42a5fb7d79840 (patch) | |
tree | 513cc8df433c60ad0d6249388a38ade5a651188e /ext/digest/test.rb | |
parent | 6ecd6fe37bf6395850d3825bab3fb88d5d345c82 (diff) |
Import the "digest" module and the submodules, from the Rough Ruby
project.
ext/digest:
This module provides the module Digest and the abstract class
Digest::Base.
ext/digest/md5 (which obsoletes ext/md5):
This module provides the class Digest::MD5 which implements the
MD5 Message-Digest Algorithm.
ext/digest/rmd160:
This module provides the class Digest::RMD160 which implements the
RIPEMD-160 cryptographic hash function.
ext/digest/sha1 (which obsoletes ext/sha1):
This module provides the class Digest::SHA1 which implements the
SHA-1 Secure Hash Algorithm.
ext/digest/sha2:
This module provides the classes Digest::SHA256, Digest::SHA384
and Digest::SHA512 which implement the SHA-256, SHA-384 and
SHA-512 Secure Hash Algorithms, respectively.
lib/md5.rb, lib/sha1.rb:
These files are provided for backward compatibility.
All these classes have the common API, which previously ext/md5 and
ext/sha1 modules provided. While the new API keeps 100% backward
compatibility, it has been enriched with several utility methods.
Read digest.txt for further details.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/test.rb')
-rw-r--r-- | ext/digest/test.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/ext/digest/test.rb b/ext/digest/test.rb new file mode 100644 index 0000000000..2f29948bb6 --- /dev/null +++ b/ext/digest/test.rb @@ -0,0 +1,100 @@ +#!/usr/bin/env ruby +# +# $RoughId: test.rb,v 1.4 2001/07/13 15:38:27 knu Exp $ +# $Id$ + +require 'runit/testcase' +require 'runit/cui/testrunner' + +require 'digest/md5' +require 'digest/rmd160' +require 'digest/sha1' +require 'digest/sha2' +include Digest + +class TestDigest < RUNIT::TestCase + ALGOS = [ + MD5, + SHA1, + SHA256, + SHA384, + SHA512, + RMD160 + ] + + DATA = { + "abc" => { + MD5 => "900150983cd24fb0d6963f7d28e17f72", + SHA1 => "a9993e364706816aba3e25717850c26c9cd0d89d", + SHA256 => "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", + SHA384 => "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", + SHA512 => "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", + RMD160 => "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" + }, + + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" => { + MD5 => "8215ef0796a20bcaaae116d3876c664a", + SHA1 => "84983e441c3bd26ebaae4aa1f95129e5e54670f1", + SHA256 => "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", + SHA384 => "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b", + SHA512 => "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445", + RMD160 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b" + } + } + + def test_s_hexdigest + ALGOS.each do |algo| + DATA.each do |str, table| + assert_equal(table[algo], algo.hexdigest(str)) + end + end + end + + def test_s_digest + ALGOS.each do |algo| + DATA.each do |str, table| + assert_equal([table[algo]].pack("H*"), algo.digest(str)) + end + end + end + + def test_update + # This test is also for digest() and hexdigest() + + str = "ABC" + + ALGOS.each do |algo| + md = algo.new + md.update str + assert_equal(algo.hexdigest(str), md.hexdigest) + assert_equal(algo.digest(str), md.digest) + end + end + + def test_eq + # This test is also for clone() + + ALGOS.each do |algo| + md1 = algo.new("ABC") + + assert_equal(md1, md1.clone) + + md2 = algo.new + md2 << "A" + + assert(md1 != md2) + + md2 << "BC" + + assert_equal(md1, md2) + end + end +end + +if $0 == __FILE__ + suite = RUNIT::TestSuite.new + + suite.add_test(TestDigest.suite) + + RUNIT::CUI::TestRunner.run(suite) +end |