https://d.puremagic.com/issues/show_bug.cgi?id=11757
Summary: toHexString doesn't support dynamic array
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Mathias LANG <[email protected]> 2013-12-17
04:23:30 PST ---
import std.digest.md;
import std.digest.sha;
ubyte[] hmac_md5(ubyte[] key, string msg)
{
immutable auto blocksize = 64;
if (key.length > blocksize)
key = md5Of(key);
if (key.length < blocksize)
key.length = blocksize;
ubyte[blocksize] okp = 0x5c;
ubyte[blocksize] ikp = 0x36;
for (size_t i = 0; i < blocksize; ++i)
okp[i] ^= key[i];
for (size_t i = 0; i < blocksize; ++i)
ikp[i] ^= key[i];
return md5Of(okp ~ md5Of(ikp ~ cast(ubyte[])(msg)));
}
ubyte[] hmac_md5(string key, string msg)
{
return hmac_md5(cast(ubyte[])(key), msg);
}
unittest {
auto md5hmac = hmac_md5("key", "The quick brown fox jumps over the lazy
dog");
assert(toHexString(md5hmac) == "80070713463E7749B90C2DC24911E275");
}
This unittest will fail (toHexString returns
'E0166C00000000000000000000000000'), but if you replace ubyte[] with ubyte[16]
-or auto-, it'll pass.
DMD 2.064.2
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------