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.

Struct std.digest.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.

struct ExampleDigest ;

Methods

NameDescription
finish () The finish function returns the final hash sum and resets the Digest.
put (data) Use this to feed the digest with data. Also implements the isOutputRange interface for ubyte and const(ubyte)[]. The following usages of put must work for any type which passes isDigest:
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.

Note

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

Example

//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!
writeln(ctx.finish().toHexString()); // "7707D6AE4E027C70EEA2A935C2296F21"

Authors

Johannes Pfau

License

Boost License 1.0.