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, ...).

Constructors

this
this()

Initializes the digest.

Members

Functions

finish
ubyte[] finish()

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.

finish
ubyte[] finish(ubyte[] 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
ubyte[] peek(ubyte[] buf)
ubyte[] peek()

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
void put(const(ubyte)[] data)

Use this to feed the digest with data. Also implements the std.range.primitives.isOutputRange interface for ubyte and const(ubyte)[].

reset
void reset()

Resets the internal state of the digest. Note: finish calls this internally, so it's not necessary to call reset manually after a call to finish.

Properties

length
size_t length [@property getter]

This 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.

Inherited Members

From Digest

put
void put(const(ubyte)[] data)

Use this to feed the digest with data. Also implements the std.range.primitives.isOutputRange interface for ubyte and const(ubyte)[].

reset
void reset()

Resets the internal state of the digest. Note: finish calls this internally, so it's not necessary to call reset manually after a call to finish.

length
size_t length [@property getter]

This 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
ubyte[] finish()
ubyte[] finish(ubyte[] 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 be at least length bytes big.

digest
ubyte[] digest(const(void[])[] data)

This is a convenience function to calculate the hash of a value using the OOP API.

Examples

import std.digest.md;
//Simple example
auto hash = new WrapperDigest!MD5();
hash.put(cast(ubyte) 0);
auto result = hash.finish();
//using a supplied buffer
import std.digest.md;
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
//length

Meta