The OpenD Programming Language

ExampleDigest

This documents the general structure of a Digest in the template API. All digest implementations should implement the following members and therefore pass the isDigest test.

Note:

  • A digest must be a struct (value type) to pass the isDigest test.
  • A digest passing the isDigest test is always an OutputRange
version(ExampleDigest)
struct ExampleDigest {}

Members

Functions

finish
ubyte[16] finish()

The finish function returns the final hash sum and resets the 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)[]. The following usages of put must work for any type which passes isDigest:

start
void start()

This function is used to (re)initialize the digest. It must be called before using the digest and it also works as a 'reset' function if the digest has already processed data.

Examples

//Using the OutputRange feature
import std.algorithm.mutation : copy;
import std.digest.md;
import std.range : repeat;

auto oneMillionRange = repeat!ubyte(cast(ubyte)'a', 1000000);
auto ctx = makeDigest!MD5();
copy(oneMillionRange, &ctx); //Note: You must pass a pointer to copy!
assert(ctx.finish().toHexString() == "7707D6AE4E027C70EEA2A935C2296F21");

Meta