[Issue 16947] New: The digest function calls the put function incorrectly.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Dec 4 05:57:08 PST 2016


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

--


More information about the Digitalmars-d-bugs mailing list