mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
Increase BASE64 encoding size when using system libb64
Remove BASE64 reference testing as it's only libb64 now. Improve the test to ignore \r and \n when comparing BASE-encoded strings to not fail on system (unpatched) libb64.
This commit is contained in:
parent
440f482d01
commit
1d58af5082
5 changed files with 44 additions and 57 deletions
|
@ -229,7 +229,7 @@ AC_ARG_ENABLE([external-b64],
|
|||
[want_external_b64=${enableval}],
|
||||
[want_external_b64=no])
|
||||
if test "x$want_external_b64" != "xno" ; then
|
||||
LIBB64_CFLAGS=""
|
||||
LIBB64_CFLAGS="-DUSE_SYSTEM_B64"
|
||||
LIBB64_LIBS="-lb64"
|
||||
LIBB64_LIBS_QT="-lb64"
|
||||
build_bundled_b64="no"
|
||||
|
|
|
@ -159,6 +159,10 @@ if(MINIUPNPC_VERSION VERSION_LESS 1.7)
|
|||
add_definitions(-DMINIUPNPC_API_VERSION=${MINIUPNPC_API_VERSION})
|
||||
endif()
|
||||
|
||||
if(USE_SYSTEM_B64)
|
||||
add_definitions(-DUSE_SYSTEM_B64)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${PROJECT_BINARY_DIR}
|
||||
|
|
|
@ -193,6 +193,23 @@ test_random (void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
base64_eq (const char * a,
|
||||
const char * b)
|
||||
{
|
||||
for (; ; ++a, ++b)
|
||||
{
|
||||
while (*a == '\r' || *a == '\n')
|
||||
++a;
|
||||
while (*b == '\r' || *b == '\n')
|
||||
++b;
|
||||
if (*a == '\0' || *b == '\0' || *a != *b)
|
||||
break;
|
||||
}
|
||||
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
static int
|
||||
test_base64 (void)
|
||||
{
|
||||
|
@ -201,17 +218,8 @@ test_base64 (void)
|
|||
int i;
|
||||
|
||||
out = tr_base64_encode_str ("YOYO!", &len);
|
||||
check_int_eq (8, len);
|
||||
check_streq ("WU9ZTyE=", out);
|
||||
in = tr_base64_decode_str_ (out, &len);
|
||||
check_int_eq (5, len);
|
||||
check_streq ("YOYO!", in);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode_str_ ("YOYO!", &len);
|
||||
check_int_eq (8, len);
|
||||
check_streq ("WU9ZTyE=", out);
|
||||
check_int_eq (strlen (out), len);
|
||||
check (base64_eq ("WU9ZTyE=", out));
|
||||
in = tr_base64_decode_str (out, &len);
|
||||
check_int_eq (5, len);
|
||||
check_streq ("YOYO!", in);
|
||||
|
@ -222,15 +230,6 @@ test_base64 (void)
|
|||
check_int_eq (0, len);
|
||||
check_streq ("", out);
|
||||
tr_free (out);
|
||||
out = tr_base64_decode_ ("", 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_streq ("", out);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode_ ("", 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_streq ("", out);
|
||||
tr_free (out);
|
||||
out = tr_base64_decode ("", 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_streq ("", out);
|
||||
|
@ -239,20 +238,9 @@ test_base64 (void)
|
|||
out = tr_base64_encode (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check (out == NULL);
|
||||
tr_free (out);
|
||||
out = tr_base64_decode_ (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check (out == NULL);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode_ (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check (out == NULL);
|
||||
tr_free (out);
|
||||
out = tr_base64_decode (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check (out == NULL);
|
||||
tr_free (out);
|
||||
|
||||
#define MAX_BUF_SIZE 1024
|
||||
|
||||
|
@ -265,15 +253,7 @@ test_base64 (void)
|
|||
buf[j] = tr_rand_int_weak (256);
|
||||
|
||||
out = tr_base64_encode (buf, j, &len);
|
||||
check_int_eq ((j + 2) / 3 * 4, len);
|
||||
in = tr_base64_decode_ (out, len, &len);
|
||||
check_int_eq (j, len);
|
||||
check (memcmp (in, buf, len) == 0);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode_ (buf, j, &len);
|
||||
check_int_eq ((j + 2) / 3 * 4, len);
|
||||
check_int_eq (strlen (out), len);
|
||||
in = tr_base64_decode (out, len, &len);
|
||||
check_int_eq (j, len);
|
||||
check (memcmp (in, buf, len) == 0);
|
||||
|
@ -285,15 +265,7 @@ test_base64 (void)
|
|||
buf[j] = '\0';
|
||||
|
||||
out = tr_base64_encode_str (buf, &len);
|
||||
check_int_eq ((j + 2) / 3 * 4, len);
|
||||
in = tr_base64_decode_str_ (out, &len);
|
||||
check_int_eq (j, len);
|
||||
check_streq (in, buf);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode_str_ (buf, &len);
|
||||
check_int_eq ((j + 2) / 3 * 4, len);
|
||||
check_int_eq (strlen (out), len);
|
||||
in = tr_base64_decode_str (out, &len);
|
||||
check_int_eq (j, len);
|
||||
check_streq (in, buf);
|
||||
|
|
|
@ -200,10 +200,15 @@ tr_base64_encode (const void * input,
|
|||
{
|
||||
if (input_length != 0)
|
||||
{
|
||||
size_t ret_length;
|
||||
size_t ret_length = 4 * ((input_length + 2) / 3);
|
||||
base64_encodestate state;
|
||||
|
||||
ret = tr_new (char, 4 * ((input_length + 2) / 3) + 1);
|
||||
#ifdef USE_SYSTEM_B64
|
||||
/* Additional space is needed for newlines if we're using unpatched libb64 */
|
||||
ret_length += ret_length / 72 + 1;
|
||||
#endif
|
||||
|
||||
ret = tr_new (char, ret_length + 1);
|
||||
|
||||
base64_init_encodestate (&state);
|
||||
ret_length = base64_encode_block (input, input_length, ret, &state);
|
||||
|
@ -248,10 +253,10 @@ tr_base64_decode (const void * input,
|
|||
{
|
||||
if (input_length != 0)
|
||||
{
|
||||
size_t ret_length;
|
||||
size_t ret_length = input_length / 4 * 3;
|
||||
base64_decodestate state;
|
||||
|
||||
ret = tr_new (char, input_length / 4 * 3 + 1);
|
||||
ret = tr_new (char, ret_length + 1);
|
||||
|
||||
base64_init_decodestate (&state);
|
||||
ret_length = base64_decode_block (input, input_length, ret, &state);
|
||||
|
|
12
third-party/libb64/cencode.c
vendored
12
third-party/libb64/cencode.c
vendored
|
@ -7,7 +7,9 @@ For details, see http://sourceforge.net/projects/libb64
|
|||
|
||||
#include <b64/cencode.h>
|
||||
|
||||
/*
|
||||
const int CHARS_PER_LINE = 72;
|
||||
*/
|
||||
|
||||
void base64_init_encodestate(base64_encodestate* state_in)
|
||||
{
|
||||
|
@ -72,12 +74,14 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
|
|||
result = (fragment & 0x03f) >> 0;
|
||||
*codechar++ = base64_encode_value(result);
|
||||
|
||||
/* ++(state_in->stepcount);
|
||||
/*
|
||||
++(state_in->stepcount);
|
||||
if (state_in->stepcount == CHARS_PER_LINE/4)
|
||||
{
|
||||
*codechar++ = '\n';
|
||||
state_in->stepcount = 0;
|
||||
} */
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
/* control should not reach here */
|
||||
|
@ -102,7 +106,9 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
|
|||
case step_A:
|
||||
break;
|
||||
}
|
||||
/* *codechar++ = '\n'; */
|
||||
/*
|
||||
*codechar++ = '\n';
|
||||
*/
|
||||
|
||||
return codechar - code_out;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue