September 29, 2005 [submision] std.md5 | ||||
---|---|---|---|---|
| ||||
I couldn't find function to to get string from digest so I wrote one. If I haven't duplicated something already created, please consider commiting this little path. Regards, --- /usr/include/phobos/std/md5.d 2005-09-29 17:26:02.000000000 +0200 +++ md5.d 2005-09-29 22:45:11.000000000 +0200 @@ -354,6 +354,29 @@ foreach (ubyte u; digest) printf("%02x", u); } +/* Convert digest to printable form + */ + +char[] digestToString(ubyte digest[16]) +{ + char[] ret = new char[32]; + for (int i = 31, j = 15; i > 0; i--, j--) + { + ret[i] = (digest[j] & 0x0f); + if (ret[i] > 9) + ret[i] += 'a' - 10; + else + ret[i] += '0'; + + i--; + ret[i] = (digest[j] & 0xf0) >> 4; + if (ret[i] > 9) + ret[i] += 'a' - 10; + else + ret[i] += '0'; + } + return ret; +} unittest { @@ -383,6 +406,8 @@ "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890"); assert(digest == cast(ubyte[])x"57edf4a22be3c955ac49da2e2107b67a"); - + + assert(digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b") + == "c3fcd3d76192e4007dfb496cca67e13b"); } -- Dawid Ciężarkiewicz |
Copyright © 1999-2021 by the D Language Foundation