/hashes/all.d

http://github.com/wilkie/djehuty · D · 44 lines · 36 code · 8 blank · 0 comment · 6 complexity · e4ad27ace5c88705739b3b2e00da569e MD5 · raw file

  1. module hashes.all;
  2. import hashes.digest;
  3. import hashes.md5;
  4. import hashes.sha1;
  5. import core.string;
  6. import core.stream;
  7. enum HashType {
  8. MD5,
  9. SHA1,
  10. }
  11. template _HashCall(HashType type) {
  12. static if (type == HashType.MD5) {
  13. const char[] _HashCall = `return HashMD5(msg);`;
  14. }
  15. else static if (type == HashType.SHA1) {
  16. const char[] _HashCall = `return HashSHA1(msg);`;
  17. }
  18. else {
  19. static assert(false, "Hash type not supported.");
  20. }
  21. }
  22. struct Hash(HashType type) {
  23. static:
  24. Digest opCall(StringLiteral msg) {
  25. mixin(_HashCall!(type));
  26. }
  27. Digest opCall(String msg) {
  28. mixin(_HashCall!(type));
  29. }
  30. Digest opCall(ubyte[] msg) {
  31. mixin(_HashCall!(type));
  32. }
  33. Digest opCall(Stream msg) {
  34. mixin(_HashCall!(type));
  35. }
  36. }