diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-18 20:27:21 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-29 11:56:03 +0200 |
commit | 526a05d6f2a6808677fb813b122c7c7d4c93cda3 (patch) | |
tree | 76dc321c2012ebda531fbcceb1ceec65196bd984 | |
parent | 7e0a09418700af94bac441c1a438b17b2d8f428a (diff) | |
download | NetworkManager-526a05d6f2a6808677fb813b122c7c7d4c93cda3.tar.gz |
glib-aux: add _nm_utils_bin2hexstr() and use from nm_utils_bin2hexstr()
nm_utils_bin2hexstr() is part of public libnm API.
That means, if we want to use this function, we need to link with
libnm-core-impl.
This is used by "nm-crypto.c". That file is currently part of
libnm-core, but that will change.
Move the implementation to libnm-glib-aux, so that we can use this code
from all our glib-based code (because all our glib-based code is allowed
to link with libnm-glib-aux).
-rw-r--r-- | src/libnm-core-impl/nm-utils.c | 11 | ||||
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.c | 21 | ||||
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.h | 2 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 55b01c159b..7135b04325 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -3795,22 +3795,13 @@ nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize length) char * nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len) { - char *result; gsize buflen = (len * 2) + 1; g_return_val_if_fail(src != NULL, NULL); g_return_val_if_fail(len > 0 && (buflen - 1) / 2 == len, NULL); g_return_val_if_fail(final_len < 0 || (gsize) final_len < buflen, NULL); - result = g_malloc(buflen); - - nm_utils_bin2hexstr_full(src, len, '\0', FALSE, result); - - /* Cut converted key off at the correct length for this cipher type */ - if (final_len >= 0 && (gsize) final_len < buflen) - result[final_len] = '\0'; - - return result; + return _nm_utils_bin2hexstr(src, len, final_len); } /** diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 3b5bc6f92b..7c93615ed8 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -4851,6 +4851,27 @@ nm_utils_bin2hexstr_full(gconstpointer addr, return out0; } +char * +_nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len) +{ + char *result; + gsize buflen = (len * 2) + 1; + + nm_assert(src); + nm_assert(len > 0 && (buflen - 1) / 2 == len); + nm_assert(final_len < 0 || (gsize) final_len < buflen); + + result = g_malloc(buflen); + + nm_utils_bin2hexstr_full(src, len, '\0', FALSE, result); + + /* Cut converted key off at the correct length for this cipher type */ + if (final_len >= 0 && (gsize) final_len < buflen) + result[final_len] = '\0'; + + return result; +} + guint8 * nm_utils_hexstr2bin_full(const char *hexstr, gboolean allow_0x_prefix, diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 6070bb0e0c..d0c7434b3c 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -2710,6 +2710,8 @@ char *nm_utils_bin2hexstr_full(gconstpointer addr, gboolean upper_case, char *out); +char *_nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len); + #define nm_utils_bin2hexstr_a(addr, length, delimiter, upper_case, str_to_free) \ ({ \ gconstpointer _addr = (addr); \ |