From bbc08d3456ce77de1eae63b6f321a9256d54d873 Mon Sep 17 00:00:00 2001 From: Christian Schramm Date: Fri, 28 Mar 2014 09:32:15 +0100 Subject: common: remove gdm_string_hex_{de,en}code() These functions are unused, so there's no reason to keep them around. This commit removes those functions and corresponding test code. https://bugzilla.gnome.org/show_bug.cgi?id=727183 --- common/gdm-common.c | 208 ------------------------------------------------- common/gdm-common.h | 9 --- tests/Makefile.am | 2 - tests/m-common.c | 4 +- tests/s-common-utils.c | 89 --------------------- tests/s-common-utils.h | 28 ------- 6 files changed, 1 insertion(+), 339 deletions(-) delete mode 100644 tests/s-common-utils.c delete mode 100644 tests/s-common-utils.h diff --git a/common/gdm-common.c b/common/gdm-common.c index 88f5419b..4017313b 100644 --- a/common/gdm-common.c +++ b/common/gdm-common.c @@ -211,214 +211,6 @@ gdm_signal_pid (int pid, return status; } -/* hex conversion adapted from D-Bus */ -/** - * Appends a two-character hex digit to a string, where the hex digit - * has the value of the given byte. - * - * @param str the string - * @param byte the byte - */ -static void -_gdm_string_append_byte_as_hex (GString *str, - int byte) -{ - const char hexdigits[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' - }; - - str = g_string_append_c (str, hexdigits[(byte >> 4)]); - - str = g_string_append_c (str, hexdigits[(byte & 0x0f)]); -} - -/** - * Encodes a string in hex, the way MD5 and SHA-1 are usually - * encoded. (Each byte is two hex digits.) - * - * @param source the string to encode - * @param start byte index to start encoding - * @param dest string where encoded data should be placed - * @param insert_at where to place encoded data - * @returns #TRUE if encoding was successful, #FALSE if no memory etc. - */ -gboolean -gdm_string_hex_encode (const GString *source, - int start, - GString *dest, - int insert_at) -{ - GString *result; - const unsigned char *p; - const unsigned char *end; - gboolean retval; - - g_return_val_if_fail (source != NULL, FALSE); - g_return_val_if_fail (dest != NULL, FALSE); - g_return_val_if_fail (source != dest, FALSE); - g_return_val_if_fail (start >= 0, FALSE); - g_return_val_if_fail (dest >= 0, FALSE); - g_assert (start <= source->len); - - result = g_string_new (NULL); - - retval = FALSE; - - p = (const unsigned char*) source->str; - end = p + source->len; - p += start; - - while (p != end) { - _gdm_string_append_byte_as_hex (result, *p); - ++p; - } - - dest = g_string_insert (dest, insert_at, result->str); - - retval = TRUE; - - g_string_free (result, TRUE); - - return retval; -} - -/** - * Decodes a string from hex encoding. - * - * @param source the string to decode - * @param start byte index to start decode - * @param end_return return location of the end of the hex data, or #NULL - * @param dest string where decoded data should be placed - * @param insert_at where to place decoded data - * @returns #TRUE if decoding was successful, #FALSE if no memory. - */ -gboolean -gdm_string_hex_decode (const GString *source, - int start, - int *end_return, - GString *dest, - int insert_at) -{ - GString *result; - const unsigned char *p; - const unsigned char *end; - gboolean retval; - gboolean high_bits; - - g_return_val_if_fail (source != NULL, FALSE); - g_return_val_if_fail (dest != NULL, FALSE); - g_return_val_if_fail (source != dest, FALSE); - g_return_val_if_fail (start >= 0, FALSE); - g_return_val_if_fail (dest >= 0, FALSE); - - g_assert (start <= source->len); - - result = g_string_new (NULL); - - retval = FALSE; - - high_bits = TRUE; - p = (const unsigned char*) source->str; - end = p + source->len; - p += start; - - while (p != end) { - unsigned int val; - - switch (*p) { - case '0': - val = 0; - break; - case '1': - val = 1; - break; - case '2': - val = 2; - break; - case '3': - val = 3; - break; - case '4': - val = 4; - break; - case '5': - val = 5; - break; - case '6': - val = 6; - break; - case '7': - val = 7; - break; - case '8': - val = 8; - break; - case '9': - val = 9; - break; - case 'a': - case 'A': - val = 10; - break; - case 'b': - case 'B': - val = 11; - break; - case 'c': - case 'C': - val = 12; - break; - case 'd': - case 'D': - val = 13; - break; - case 'e': - case 'E': - val = 14; - break; - case 'f': - case 'F': - val = 15; - break; - default: - goto done; - } - - if (high_bits) { - result = g_string_append_c (result, val << 4); - } else { - int len; - unsigned char b; - - len = result->len; - - b = result->str[len - 1]; - - b |= val; - - result->str[len - 1] = b; - } - - high_bits = !high_bits; - - ++p; - } - - done: - dest = g_string_insert (dest, insert_at, result->str); - - if (end_return) { - *end_return = p - (const unsigned char*) source->str; - } - - retval = TRUE; - - g_string_free (result, TRUE); - - return retval; -} - static gboolean _fd_is_character_device (int fd) { diff --git a/common/gdm-common.h b/common/gdm-common.h index 50bf1538..d876b66e 100644 --- a/common/gdm-common.h +++ b/common/gdm-common.h @@ -53,15 +53,6 @@ gboolean gdm_clear_close_on_exec_flag (int fd); const char * gdm_make_temp_dir (char *template); -gboolean gdm_string_hex_encode (const GString *source, - int start, - GString *dest, - int insert_at); -gboolean gdm_string_hex_decode (const GString *source, - int start, - int *end_return, - GString *dest, - int insert_at); char *gdm_generate_random_bytes (gsize size, GError **error); gboolean gdm_goto_login_session (GError **error); diff --git a/tests/Makefile.am b/tests/Makefile.am index 88794983..63fc198c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,8 +21,6 @@ m_common_SOURCES = \ m-common.c \ s-common-address.c \ s-common-address.h \ - s-common-utils.c \ - s-common-utils.h \ $(NULL) m_common_CFLAGS = \ diff --git a/tests/m-common.c b/tests/m-common.c index 0c038054..c5ff2f4a 100644 --- a/tests/m-common.c +++ b/tests/m-common.c @@ -24,7 +24,6 @@ #include #include "s-common-address.h" -#include "s-common-utils.h" static gboolean no_fork = FALSE; static gboolean verbose = FALSE; @@ -57,8 +56,7 @@ main (int argc, char **argv) exit (1); } - r = srunner_create (suite_common_utils ()); - srunner_add_suite (r, suite_common_address ()); + r = srunner_create (suite_common_address ()); if (no_fork) { srunner_set_fork_status (r, CK_NOFORK); diff --git a/tests/s-common-utils.c b/tests/s-common-utils.c deleted file mode 100644 index b8e284a7..00000000 --- a/tests/s-common-utils.c +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Andrew Ziem - * Copyright (C) 2007 William Jon McCann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include "s-common-utils.h" -#include "gdm-common.h" - -START_TEST (test_gdm_string_hex_encode) -{ - GString *a; - GString *b; - - a = g_string_new ("foo"); - b = g_string_sized_new (100); - fail_unless (TRUE == gdm_string_hex_encode (a, 0, b, 0), NULL); - fail_unless (0 == strncmp (b->str, "666f6f", 7), NULL); - -#ifndef NO_INVALID_INPUT - /* invalid input */ - fail_unless (FALSE == gdm_string_hex_encode (a, -1, b, -1), NULL); - fail_unless (FALSE == gdm_string_hex_encode (NULL, 0, NULL, 0), NULL); - fail_unless (FALSE == gdm_string_hex_encode (a, 0, a, 0), NULL); -#endif - - g_string_free (a, TRUE); - g_string_free (b, TRUE); -} -END_TEST - - -START_TEST (test_gdm_string_hex_decode) - GString *a; - GString *b; - - a = g_string_new ("666f6f"); - b = g_string_sized_new (100); - - fail_unless (TRUE == gdm_string_hex_decode (a, 0, NULL, b, 0), NULL); - - fail_unless (0 == strncmp (b->str, "foo", 7), NULL); - -#ifndef NO_INVALID_INPUT - /* invalid input */ - fail_unless (FALSE == gdm_string_hex_decode (a, -1, NULL, b, -1), NULL); - fail_unless (FALSE == gdm_string_hex_decode (NULL, 0, NULL, NULL, 0), NULL); - fail_unless (FALSE == gdm_string_hex_decode (a, 0, NULL, a, 0), NULL); -#endif - - g_string_free (a, TRUE); - g_string_free (b, TRUE); -END_TEST - -Suite * -suite_common_utils (void) -{ - Suite *s; - TCase *tc_core; - - s = suite_create ("gdm-common"); - tc_core = tcase_create ("core"); - - tcase_add_test (tc_core, test_gdm_string_hex_encode); - tcase_add_test (tc_core, test_gdm_string_hex_decode); - - suite_add_tcase (s, tc_core); - - return s; -} diff --git a/tests/s-common-utils.h b/tests/s-common-utils.h deleted file mode 100644 index dfff893f..00000000 --- a/tests/s-common-utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __S_COMMON_UTILS_H -#define __S_COMMON_UTILS_H - -#include - -Suite *suite_common_utils (void); - -#endif /* __S_COMMON_UTILS_H */ -- cgit v1.2.1