diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2018-08-31 23:00:44 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-09-03 04:05:13 +0000 |
commit | 65b342f7497825c2abc4e98c7fd9f4ff6d8ed45c (patch) | |
tree | 3746e1055e28476a4b8ba30df6996fcd16b636c1 /wsutil | |
parent | 42ad60896da6655d89c4e220a36766f121cdb856 (diff) |
epan: Use g_base64_decode_inplace()
Replace ws_base64_decode_inplace() with g_base64_decode_inplace()
or g_base64_decode(), which was introduced in glib 2.12.
The only observed difference is a need for zero-terminate the buffer
after decoding.
Change-Id: Ia102d0d8e9bec575ffeddf448191a3f6de9fb1ed
Reviewed-on: https://code.wireshark.org/review/29382
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/CMakeLists.txt | 2 | ||||
-rw-r--r-- | wsutil/base64.c | 66 | ||||
-rw-r--r-- | wsutil/base64.h | 27 |
3 files changed, 0 insertions, 95 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 2877dad534..488905c0bf 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -15,7 +15,6 @@ add_definitions(-DEXTCAP_DIR=\"${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}\ set(WSUTIL_PUBLIC_HEADERS adler32.h base32.h - base64.h bits_count_ones.h bits_ctz.h bitswap.h @@ -77,7 +76,6 @@ set(WSUTIL_PUBLIC_HEADERS set(WSUTIL_COMMON_FILES adler32.c base32.c - base64.c bitswap.c buffer.c clopts_common.c diff --git a/wsutil/base64.c b/wsutil/base64.c deleted file mode 100644 index 951d20b5b0..0000000000 --- a/wsutil/base64.c +++ /dev/null @@ -1,66 +0,0 @@ -/* base64.c - * Base-64 conversion - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 1998 Gerald Combs - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "config.h" - -#include <string.h> -#include "base64.h" - -/* Decode a base64 string in-place - simple and slow algorithm. - Return length of result. Taken from rproxy/librsync/base64.c by - Andrew Tridgell. */ - -size_t ws_base64_decode_inplace(char *s) -{ - static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"; - int bit_offset, byte_offset, idx, i; - unsigned char *d = (unsigned char *)s; - char *p; - int cr_idx; - - /* we will allow CR and LF - but ignore them */ - cr_idx = (int)(strchr(b64, '\r') - b64); - - i = 0; - - while (*s && (p = strchr(b64, *s))) { - idx = (int)(p - b64); - if (idx < cr_idx) { - byte_offset = (i * 6) / 8; - bit_offset = (i * 6) % 8; - d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1); - if (bit_offset < 3) { - d[byte_offset] |= (idx << (2 - bit_offset)); - } else { - d[byte_offset] |= (idx >> (bit_offset - 2)); - d[byte_offset + 1] = 0; - d[byte_offset + 1] |= (idx << (8 - (bit_offset - 2))) & 0xFF; - } - i++; - } - s++; - } - - d[i*3/4] = 0; - return i*3/4; -} - -/* - * Editor modelines - http://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 8 - * tab-width: 8 - * indent-tabs-mode: t - * End: - * - * vi: set shiftwidth=8 tabstop=8 noexpandtab: - * :indentSize=8:tabSize=8:noTabs=false: - */ diff --git a/wsutil/base64.h b/wsutil/base64.h deleted file mode 100644 index 07b5d118d3..0000000000 --- a/wsutil/base64.h +++ /dev/null @@ -1,27 +0,0 @@ -/* base64.h - * Base-64 conversion - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 1998 Gerald Combs - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ -#ifndef __BASE64_H__ -#define __BASE64_H__ - -#include "ws_symbol_export.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* In-place decoding of a base64 string. Resulting string is NULL terminated */ -WS_DLL_PUBLIC -size_t ws_base64_decode_inplace(char *s); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __BASE64_H__ */ |