Skip to content

Commit

Permalink
Merge pull request #4690 from wilzbach/hexstring_safe
Browse files Browse the repository at this point in the history
std.digest.digest: make toHexString @safe
  • Loading branch information
schveiguy committed Jul 29, 2016
2 parents 79d1195 + 7864e43 commit 5eb27bc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions std/digest/digest.d
Expand Up @@ -774,7 +774,8 @@ string toHexString(Order order = Order.increasing, LetterCase letterCase = Lette
}
}
import std.exception : assumeUnique;
return assumeUnique(result);
// memory was just created, so casting to immutable is safe
return () @trusted { return assumeUnique(result); }();
}

///ditto
Expand All @@ -786,7 +787,7 @@ string toHexString(LetterCase letterCase, Order order = Order.increasing)(in uby
//For more example unittests, see Digest.digest, digest

///
unittest
@safe unittest
{
import std.digest.crc;
//Test with template API:
Expand All @@ -799,7 +800,7 @@ unittest
}

///
unittest
@safe unittest
{
import std.digest.crc;
// With OOP API
Expand All @@ -808,7 +809,7 @@ unittest
assert(toHexString!(Order.decreasing)(crc32) == "414FA339");
}

unittest
@safe unittest
{
ubyte[16] data;
assert(toHexString(data) == "00000000000000000000000000000000");
Expand Down

0 comments on commit 5eb27bc

Please sign in to comment.