summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/certtool-common.c4
-rw-r--r--src/common.c22
-rw-r--r--src/common.h1
3 files changed, 24 insertions, 3 deletions
diff --git a/src/certtool-common.c b/src/certtool-common.c
index 2003188b57..9c223ec94d 100644
--- a/src/certtool-common.c
+++ b/src/certtool-common.c
@@ -1215,14 +1215,14 @@ static void privkey_info_int(FILE *outfile, common_info_st * cinfo,
raw_to_base64(lbuffer, size));
fprintf(outfile, "Public Key ID:\n\tsha256:%s\n",
- raw_to_string(lbuffer, size));
+ raw_to_hex(lbuffer, size));
size = lbuffer_size;
ret =
gnutls_x509_privkey_get_key_id(key, GNUTLS_KEYID_USE_SHA1, lbuffer, &size);
if (ret >= 0) {
fprintf(outfile, "\tsha1:%s\n",
- raw_to_string(lbuffer, size));
+ raw_to_hex(lbuffer, size));
}
}
fprintf(outfile, "\n");
diff --git a/src/common.c b/src/common.c
index 0c2844d82d..9bd68c2631 100644
--- a/src/common.c
+++ b/src/common.c
@@ -53,7 +53,7 @@
const char str_unknown[] = "(unknown)";
-/* Hex encodes the given data.
+/* Hex encodes the given data adding a semicolon between hex bytes.
*/
const char *raw_to_string(const unsigned char *raw, size_t raw_size)
{
@@ -74,6 +74,26 @@ const char *raw_to_string(const unsigned char *raw, size_t raw_size)
return buf;
}
+/* Hex encodes the given data.
+ */
+const char *raw_to_hex(const unsigned char *raw, size_t raw_size)
+{
+ static char buf[1024];
+ size_t i;
+ if (raw_size == 0)
+ return "(empty)";
+
+ if (raw_size * 2 + 1 >= sizeof(buf))
+ return "(too large)";
+
+ for (i = 0; i < raw_size; i++) {
+ sprintf(&(buf[i * 2]), "%02x", raw[i]);
+ }
+ buf[sizeof(buf) - 1] = '\0';
+
+ return buf;
+}
+
const char *raw_to_base64(const unsigned char *raw, size_t raw_size)
{
static char buf[1024];
diff --git a/src/common.h b/src/common.h
index e1d9de5071..f1c828ce40 100644
--- a/src/common.h
+++ b/src/common.h
@@ -67,6 +67,7 @@ void print_list(const char *priorities, int verbose);
int cert_verify(gnutls_session_t session, const char *hostname, const char *purpose);
const char *raw_to_string(const unsigned char *raw, size_t raw_size);
+const char *raw_to_hex(const unsigned char *raw, size_t raw_size);
const char *raw_to_base64(const unsigned char *raw, size_t raw_size);
int check_command(gnutls_session_t session, const char *str);