Report a bug
If you spot a problem with this page, click here to create a GitHub 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 a local clone.

dmd.common.sha

Computes SHA hashes of arbitrary data. SHA hashes are like a checksum or CRC, but are more robust.
This is a copy of std.digest.sha, but stripped of bells and whistles
Compiler implementation of the D programming language.
Authors:

Source

struct SHA(uint hashBlockSize, uint digestSize);
Template API SHA1/SHA2 implementation. Supports: SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.
The hashBlockSize and digestSize are in bits. However, it's likely easier to simply use the convenience aliases: SHA1, SHA224, SHA256, SHA384, SHA512, SHA512_224 and SHA512_256.
See std.digest for differences between template and OOP API.
pure nothrow @nogc @safe void start();
SHA initialization. Begins an SHA1/SHA2 operation.

Note For this SHA Digest implementation calling start after default construction is not necessary. Calling start is only necessary to reset the Digest.

Generic code which deals with different Digest types should always call start though.

Example

SHA1 digest;
//digest.start(); //Not necessary
digest.put(0);

pure nothrow @nogc @trusted void put(scope const(ubyte)[] input...);
Use this to feed the digest with data. Also implements the std.range.primitives.isOutputRange interface for ubyte and const(ubyte)[].
pure nothrow @nogc @trusted ubyte[digestSize / 8] finish();
Returns the finished SHA hash. This also calls start to reset the internal state.