The key output is usually short, but for signature it is more
readable to output it in several lines.
Implement line splitting. Set line limit hardcoded to 20 hex
numbers (not characters).
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
+ int j;
+ const size_t line_limit = 20;
+ size_t str_len;
+ str_len = len * 3; /* XX: or XX\0 */
+ str_len += ((str_len + line_limit - 1) / line_limit - 1) * 3; /* \n\t\t */
+
+ str = malloc(str_len);
if (str == NULL)
return NULL;
if (str == NULL)
return NULL;
- for (i = 0; i < (int)len; i++) {
- sprintf(str + i * 3, "%02X", (unsigned char)hex[i]);
- if (i < (int)len - 1)
- str[i * 3 + 2] = ':';
+ for (i = 0, j = 0; i < (int)len; i++) {
+ j += sprintf(str + j, "%02X", (unsigned char)hex[i]);
+ if (i < (int)len - 1) {
+ str[j++] = ':';
+
+ if ((i + 1) % line_limit == 0)
+ j += sprintf(str + j, "\n\t\t");
+ }