| 253 | } |
| 254 | |
| 255 | char *octet_string_hex_string(const void *s, int length) |
| 256 | { |
| 257 | const uint8_t *str = (const uint8_t *)s; |
| 258 | int i; |
| 259 | |
| 260 | /* double length, since one octet takes two hex characters */ |
| 261 | length *= 2; |
| 262 | |
| 263 | /* truncate string if it would be too long */ |
| 264 | if (length > MAX_PRINT_STRING_LEN) { |
| 265 | length = MAX_PRINT_STRING_LEN; |
| 266 | } |
| 267 | |
| 268 | for (i = 0; i < length; i += 2) { |
| 269 | bit_string[i] = nibble_to_hex_char(*str >> 4); |
| 270 | bit_string[i + 1] = nibble_to_hex_char(*str++ & 0xF); |
| 271 | } |
| 272 | bit_string[i] = 0; /* null terminate string */ |
| 273 | return bit_string; |
| 274 | } |
| 275 | |
| 276 | static const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 277 | "abcdefghijklmnopqrstuvwxyz0123456789+/"; |