The digest function calls the put function incorrectly.
This code does not work.
-----
struct MyDigest
{
void put(ubyte data) { }
void put(ubyte a, ubyte b) { }
void start() { }
ubyte[] finish() { return null; }
}
unittest
{
writeln(isOutputRange!(MyDigest, ubyte)); //true
writeln(isOutputRange!(MyDigest, const(ubyte)[])); //true
writeln(isDigest!MyDigest); //true
}
unittest
{
auto d = digest!MyDigest("test"); //compile error!
}
-----
How to fix:
-----
// https://github.com/dlang/phobos/blob/master/std/digest/digest.d#L457
hash.put(cast(const(ubyte[]))datum);
-----
.put(hash, cast(const(ubyte[]))datum);
-----
Comment #1 by john.loughran.colvin — 2016-12-07T23:13:27Z
The documentation says that a digest must implement a put function that takes a variadic number of individual ubytes or a ubyte array. This is a stronger requirement than being an output range for ubyte and ubyte[].
It is possible to argue that std.digest should work for output ranges in general, but that's an enhancement request. It probably wouldn't be a lot of work to implement, but you might be the only person for whom it's a priority...
If you found the documentation confusing or lacking, please feel free to make a pull request to improve it.
If you found the error message confusing or lacking, that's also something that can probably be easily improved, or at least explicitly reported here.
Comment #2 by lempiji — 2016-12-23T15:44:59Z
Thanks for the response.
I understand that this is a rare request.
I reported that it would be should to accept a general OutputRange, but I think that it is a low priority problem.
I would like to make a pull request when improvement is needed.
Comment #3 by greeenify — 2016-12-27T10:35:24Z
>> It probably wouldn't be a lot of work to implement, but you might be the only person for whom it's a priority...
> I would like to make a pull request when improvement is needed.
Please do so :)
Comment #4 by robert.schadek — 2024-12-01T16:28:19Z