Hash.toString

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.

  1. string toString(string delegate(Digest) digestCodeOfObj)
  2. void toString(Sink sink, string delegate(Digest) digestCodeOfObj)
    struct Hash(TDigest)
    void
    toString
    (
    Sink
    )
    (
    ref Sink sink
    ,
    string delegate
    (
    Digest
    )
    digestCodeOfObj = toDelegate(&defaultDigestCodeOfObj)
    )
    if (
    isOutputRange!(Sink, const(char))
    )
    if (
    isAnyDigest!TDigest
    )

Examples

import std.digest.digest;
import dauth;

struct BBQ42 {...}
static assert(isDigest!BBQ42);
alias BBQ42Digest = WrapperDigest!BBQ42;

string customDigestCodeOfObj(Digest digest)
{
    if     (cast(BBQ42Digest)digest) return "BBQ42";
    else if(cast(FAQ17Digest)digest) return "FAQ17";
    else
        return defaultDigestCodeOfObj(digest);
}

void doStuff(Hash!BBQ42 hash)
{
    writeln( hash.toString(&customDigestCodeOfObj) );
}

Optional Params

digestCodeOfObj - Default value is 'toDelegate(&defaultDigestCodeOfObj)'

Meta