https://issues.dlang.org/show_bug.cgi?id=16947

          Issue ID: 16947
           Summary: The digest function calls the put function
                    incorrectly.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nob...@puremagic.com
          Reporter: lemp...@gmail.com

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);
-----

--

Reply via email to