View source code
Display the source code in std/digest/package.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Class std.digest.WrapperDigest

Wraps a template API hash struct into a Digest interface. Modules providing digest implementations will usually provide an alias for this template (e.g. MD5Digest, SHA1Digest, ...).

class WrapperDigest(T)
if (isDigest!T);


this () Initializes the digest.


length[get] size_tThis is the length in bytes of the hash value which is returned by finish. It's also the required size of a buffer passed to finish.


finish (buf) The finish function returns the hash value. It takes an optional buffer to copy the data into. If a buffer is passed, it must have a length at least length bytes.
peek (buf) Works like finish but does not reset the internal state, so it's possible to continue putting data into this WrapperDigest after a call to peek.
put () Use this to feed the digest with data. Also implements the isOutputRange interface for ubyte and const(ubyte)[].
reset () Resets the internal state of the digest.
factory (classname) Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor.
opCmp (o) Compare with another Object obj.
opEquals (o) Test whether this is equal to o. The default implementation only compares by identity (using the is operator). Generally, overrides and overloads for opEquals should attempt to compare objects by their contents. A class will most likely want to add an overload that takes your specific type as the argument and does the content comparison. Then you can override this and forward it to your specific typed overload with a cast. Remember to check for null on the typed overload.
toHash () Compute hash function for Object.
toString () Convert Object to a human readable string.


//Simple example
auto hash = new WrapperDigest!MD5();
hash.put(cast(ubyte) 0);
auto result = hash.finish();


//using a supplied buffer
ubyte[16] buf;
auto hash = new WrapperDigest!MD5();
hash.put(cast(ubyte) 0);
auto result = hash.finish(buf[]);
//The result is now in result (and in buf). If you pass a buffer which is bigger than
//necessary, result will have the correct length, but buf will still have it's original


Johannes Pfau


Boost License 1.0.