add odd numbers for hex_decode
This commit is contained in:
parent
cf6d3ce892
commit
c795f607ef
@ -209,7 +209,12 @@ unsigned char *hex_decode(const char *orig, size_t *sz) {
|
||||
}
|
||||
|
||||
char *buf = malloc(sizeof(char) * buf_sz);
|
||||
strcpy(buf, orig);
|
||||
if (strlen(orig) % 2 != 0) {
|
||||
strcpy(buf + 1, orig);
|
||||
buf[0] = '0';
|
||||
} else {
|
||||
strcpy(buf, orig);
|
||||
}
|
||||
buf[buf_sz - 1] = '\0';
|
||||
|
||||
*sz = buf_sz / 2;
|
||||
|
@ -335,6 +335,16 @@ void test_crypto() {
|
||||
assert(s[i] == h[i]);
|
||||
}
|
||||
free(s);
|
||||
|
||||
// Odd number of characters
|
||||
s = hex_decode("f00f5", &s_sz);
|
||||
unsigned char h2[4] = {
|
||||
0x0F, 0x00, 0xF5
|
||||
};
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
assert(s[i] == h2[i]);
|
||||
}
|
||||
free(s);
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) || defined(__MACH__)
|
||||
|
Loading…
x
Reference in New Issue
Block a user