www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16947] New: The digest function calls the put function

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: nobody puremagic.com
          Reporter: lempiji 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);
-----

--
Dec 04 2016