diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-22 18:58:06 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-22 19:43:49 +0100 |
commit | b1bb8e30b4fd835649b5790895fcd519f1809141 (patch) | |
tree | 256c59922b255d6f451c58318ffee0be87fcefef /libmm-glib/mm-common-helpers.c | |
parent | ca49af0c5d4b649950ef3ed038e70f58a37050f3 (diff) |
broadband-modem: don't assume the returned string is always hex-encoded
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 3f100b68..4694be8d 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -929,6 +929,31 @@ mm_utils_hexstr2bin (const gchar *hex, gsize *out_len) /* End from hostap */ +gboolean +mm_utils_ishexstr (const gchar *hex) +{ + gsize len; + gsize i; + + /* Length not multiple of 2? */ + len = strlen (hex); + if (len % 2 != 0) + return FALSE; + + for (i = 0; i < len; i++) { + /* Non-hex char? */ + if (hex[i] >= '0' && hex[i] <= '9') + continue; + if (hex[i] >= 'a' && hex[i] <= 'f') + continue; + if (hex[i] >= 'A' && hex[i] <= 'F') + continue; + return FALSE; + } + + return TRUE; +} + gchar * mm_utils_bin2hexstr (const guint8 *bin, gsize len) { |