parseHash

Parses a string that was encoded by Hash.toString.

Only OO-style digests are used since the digest is specified in the string and therefore only known at runtime.

Throws ConvException if the string is malformed.

To support additional digests besides the built-in (Phobos's CRC32, MD5, RIPEMD160 and SHA), supply a custom delegate for digestFromDAuthCode. You can defer to DAuth's defaultDigestFromCode to handle the built-in digests.

Similarly, to extend crypt(3)-style to support additional digests beyond DAuth's crypt(3) support, supply a custom delegate for digestFromCryptCode. The default implementation is defaultDigestFromCryptCode.

  1. Hash!Digest parseHash(string str, Digest delegate(string) digestFromDAuthCode, Digest delegate(string) digestFromCryptCode)
    Hash!Digest
    parseHash
    (
    string str
    ,
    Digest delegate
    (
    string
    )
    digestFromDAuthCode = toDelegate(&defaultDigestFromCode)
    ,
    Digest delegate
    (
    string
    )
    digestFromCryptCode = toDelegate(&defaultDigestFromCryptCode)
    )
  2. Hash!Digest parseDAuthHash(string str, Digest delegate(string) digestFromDAuthCode)
  3. Hash!Digest parseCryptHash(string str, Digest delegate(string) digestFromCryptCode)

Examples

import std.digest.digest;
import dauth;

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

Digest customDigestFromCode(string digestCode)
{
    switch(digestCode)
    {
    case "BBQ42": return new BBQ42Digest();
    case "FAQ17": return new FAQ17Digest();
    default:
        return defaultDigestFromCode(digestCode);
    }
}

void doStuff(string hashString)
{
    auto hash = parseHash(hashString, &customDigestFromCode);
}

Optional Params

digestFromDAuthCode - Default value is 'toDelegate(&defaultDigestFromCode)'

digestFromCryptCode - Default value is 'toDelegate(&defaultDigestFromCryptCode)'

Meta