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