[Issue 11757] New: toHexString doesn't support dynamic array
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 17 04:23:32 PST 2013
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: nobody at puremagic.com
ReportedBy: pro.mathias.lang at gmail.com
--- Comment #0 from Mathias LANG <pro.mathias.lang at gmail.com> 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: -------
More information about the Digitalmars-d-bugs
mailing list