/specs/hashes/md5.ds

http://github.com/wilkie/djehuty · Unknown · 32 lines · 25 code · 7 blank · 0 comment · 0 complexity · 6edddfe8bac4250c0e4b3925c56c2e0f MD5 · raw file

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