PageRenderTime 13ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/specs/hashes/md5.ds

http://github.com/wilkie/djehuty
Unknown | 32 lines | 25 code | 7 blank | 0 comment | 0 complexity | 6edddfe8bac4250c0e4b3925c56c2e0f MD5 | raw file
 1module specs.hashes.md5;
 2
 3import testing.support;
 4
 5import hashes.md5;
 6
 7describe MD5() {
 8	describe hash() {
 9		it should_hash_as_expected_for_string_literals() {
10			string s = HashMD5.hash("Hashing Hashing Hashing").toString();
11			should(s == "7ba85cd90a910d790172b15e895f8e56");
12		}
13
14		it should_respect_leading_zeroes() {
15			// Testing: leading 0s on parts, note that there is a 0 on the 9th value from the left
16			string s = HashMD5.hash("d").toString();
17			should(s == "8277e0910d750195b448797616e091ad");
18		}
19
20		it should_work_on_byte_arrays() {
21			// Testing a classic MD5 Collision
22			ubyte[] filea = cast(ubyte[])import("testmd5a.bin");
23			ubyte[] fileb = cast(ubyte[])import("testmd5b.bin");
24
25			string a = HashMD5.hash(filea).toString();
26			string b = HashMD5.hash(fileb).toString();
27
28			should(a == b);
29			should(a == "da5c61e1edc0f18337e46418e48c1290");
30		}
31	}
32}