diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2013-03-28 12:10:36 +0100 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2013-03-28 16:59:58 +0100 |
commit | 2109f41cc6cb4e3481c205813fde3d907ebee4d1 (patch) | |
tree | 3e9707b0aa6b8a03122144b71e291129053f1900 /src/settings/plugins/ifcfg-rh | |
parent | bd3c80029dc386fce71a44ab1b838aebd6fc6d00 (diff) | |
download | NetworkManager-2109f41cc6cb4e3481c205813fde3d907ebee4d1.tar.gz |
libnm-util: consolidate hex-string <-> bin conversion functions
and move them to libnm-util's nm-utils.s so that they are easily available.
Diffstat (limited to 'src/settings/plugins/ifcfg-rh')
-rw-r--r-- | src/settings/plugins/ifcfg-rh/reader.c | 2 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/utils.c | 91 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/utils.h | 4 |
3 files changed, 1 insertions, 96 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 7c914c8871..5604740deb 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -3056,7 +3056,7 @@ make_wireless_setting (shvarFile *ifcfg, p++; } - tmp = utils_hexstr2bin (value + 2, value_len - 2); + tmp = nm_utils_hexstr2bin (value + 2, value_len - 2); ssid_len = (value_len - 2) / 2; memcpy (buf, tmp, ssid_len); p = &buf[0]; diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c index 82cb206a26..0c87a7f973 100644 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ b/src/settings/plugins/ifcfg-rh/utils.c @@ -25,97 +25,6 @@ #include "shvar.h" /* - * utils_bin2hexstr - * - * Convert a byte-array into a hexadecimal string. - * - * Code originally by Alex Larsson <alexl@redhat.com> and - * copyright Red Hat, Inc. under terms of the LGPL. - * - */ -char * -utils_bin2hexstr (const char *bytes, int len, int final_len) -{ - static char hex_digits[] = "0123456789abcdef"; - char *result; - int i; - gsize buflen = (len * 2) + 1; - - g_return_val_if_fail (bytes != NULL, NULL); - g_return_val_if_fail (len > 0, NULL); - g_return_val_if_fail (len < 4096, NULL); /* Arbitrary limit */ - if (final_len > -1) - g_return_val_if_fail (final_len < buflen, NULL); - - result = g_malloc0 (buflen); - for (i = 0; i < len; i++) - { - result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf]; - result[2*i+1] = hex_digits[bytes[i] & 0xf]; - } - /* Cut converted key off at the correct length for this cipher type */ - if (final_len > -1) - result[final_len] = '\0'; - else - result[buflen - 1] = '\0'; - - return result; -} - -/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */ - -static int hex2num (char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - return -1; -} - -static int hex2byte (const char *hex) -{ - int a, b; - a = hex2num(*hex++); - if (a < 0) - return -1; - b = hex2num(*hex++); - if (b < 0) - return -1; - return (a << 4) | b; -} - -char * -utils_hexstr2bin (const char *hex, size_t len) -{ - size_t i; - int a; - const char * ipos = hex; - char * buf = NULL; - char * opos; - - /* Length must be a multiple of 2 */ - if ((len % 2) != 0) - return NULL; - - opos = buf = g_malloc0 ((len / 2) + 1); - for (i = 0; i < len; i += 2) { - a = hex2byte (ipos); - if (a < 0) { - g_free (buf); - return NULL; - } - *opos++ = a; - ipos += 2; - } - return buf; -} - -/* End from hostap */ - -/* * utils_single_quote_string * * Put string inside single quotes and remove CR, LF characters. If single quote diff --git a/src/settings/plugins/ifcfg-rh/utils.h b/src/settings/plugins/ifcfg-rh/utils.h index 9262ef720c..2c94aacaa0 100644 --- a/src/settings/plugins/ifcfg-rh/utils.h +++ b/src/settings/plugins/ifcfg-rh/utils.h @@ -26,10 +26,6 @@ #include "shvar.h" #include "common.h" -char *utils_bin2hexstr (const char *bytes, int len, int final_len); - -char *utils_hexstr2bin (const char *hex, size_t len); - char *utils_single_quote_string (const char *str); char *utils_single_unquote_string (const char *str); |