static void test_util_bin_to_hex() { unsigned char in[4] = { 0xaf, 0x00, 0xfa, 0x0d }; kstr out; kstr_init(&out); util_bin_to_hex(in, 4, &out); assert(kstr_equal_cstr(&out, "af00fa0d")); kstr_free(&out); }
/* md5 hash */ static char *get_hash(char *data, int len) { struct MD5Context context; unsigned char digest[16]; MD5Init(&context); MD5Update(&context, data, len); MD5Final(digest, &context); return util_bin_to_hex(digest, 16); }