1 import std.digest.digest; 2 import dauth; 3 4 struct BBQ42 {...} 5 static assert(isDigest!BBQ42); 6 alias BBQ42Digest = WrapperDigest!BBQ42; 7 8 string customDigestCodeOfObj(Digest digest) 9 { 10 if (cast(BBQ42Digest)digest) return "BBQ42"; 11 else if(cast(FAQ17Digest)digest) return "FAQ17"; 12 else 13 return defaultDigestCodeOfObj(digest); 14 } 15 16 void doStuff(Hash!BBQ42 hash) 17 { 18 writeln( hash.toString(&customDigestCodeOfObj) ); 19 }
digestCodeOfObj - Default value is 'toDelegate(&defaultDigestCodeOfObj)'
Encodes the digest, salt and hash into a convenient forward-compatible string format, ready for insertion into a database.
To support additional digests besides the built-in (Phobos's CRC32, MD5, RIPEMD160 and SHA), supply a custom delegate for digestCodeOfObj. Your custom digestCodeOfObj only needs to handle OO-style digests. As long as the OO-style digests were created using Phobos's WrapperDigest template, the template-style version will be handled automatically. You can defer to DAuth's defaultDigestCodeOfObj to handle the built-in digests.