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.
std.digest.Digest/digest
- multiple declarations
Function digest
This is a convenience function to calculate a hash using the template API.
Every digest passing the isDigest
test can be used with this function.
DigestType!Hash digest(Hash, Range)
(
auto ref Range range
)
if (!isArray!Range && isDigestibleRange!Range);
Parameters
Name | Description |
---|---|
range | an InputRange with ElementType ubyte , ubyte[] or ubyte[num] |
Example
import std .digest .md;
import std .range : repeat;
auto testRange = repeat!ubyte(cast(ubyte)'a', 100);
auto md5 = digest!MD5(testRange);
Function digest
This overload of the digest function handles arrays.
Parameters
Name | Description |
---|---|
data | one or more arrays of any type |
Example
import std .digest .crc, std .digest .md, std .digest .sha;
auto md5 = digest!MD5( "The quick brown fox jumps over the lazy dog");
auto sha1 = digest!SHA1( "The quick brown fox jumps over the lazy dog");
auto crc32 = digest!CRC32("The quick brown fox jumps over the lazy dog");
writeln(toHexString(crc32)); // "39A34F41"
Example
import std .digest .crc;
auto crc32 = digest!CRC32("The quick ", "brown ", "fox jumps over the lazy dog");
writeln(toHexString(crc32)); // "39A34F41"
Interface Digest
This describes the OOP API. To understand when to use the template API and when to use the OOP API, see the module documentation at the top of this page.
interface Digest
;
The Digest interface is the base interface which is implemented by all digests.
Properties
Name | Type | Description |
---|---|---|
length [get]
|
ulong | 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 .
|
Methods
Name | Description |
---|---|
digest
(data)
|
This is a convenience function to calculate the hash of a value using the OOP API. |
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 be at least length bytes big.
|
put
(data)
|
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. |
Note
A Digest implementation 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 = new MD5Digest();
copy(oneMillionRange, ctx);
writeln(ctx .finish() .toHexString()); // "7707D6AE4E027C70EEA2A935C2296F21"
Example
import std .digest .crc, std .digest .md, std .digest .sha;
ubyte[] md5 = (new MD5Digest()) .digest("The quick brown fox jumps over the lazy dog");
ubyte[] sha1 = (new SHA1Digest()) .digest("The quick brown fox jumps over the lazy dog");
ubyte[] crc32 = (new CRC32Digest()) .digest("The quick brown fox jumps over the lazy dog");
writeln(crcHexString(crc32)); // "414FA339"
Example
import std .digest .crc;
ubyte[] crc32 = (new CRC32Digest()) .digest("The quick ", "brown ", "fox jumps over the lazy dog");
writeln(crcHexString(crc32)); // "414FA339"
Example
void test(Digest dig)
{
dig .put(cast(ubyte) 0); //single ubyte
dig .put(cast(ubyte) 0, cast(ubyte) 0); //variadic
ubyte[10] buf;
dig .put(buf); //buffer
}
Authors
Johannes Pfau
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.