Changeset 14429


Ignore:
Timestamp:
Jan 3, 2015, 9:35:20 PM (7 years ago)
Author:
mikedld
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r14422 r14429  
    230230              [want_external_b64=no])
    231231if test "x$want_external_b64" != "xno" ; then
    232     LIBB64_CFLAGS=""
     232    LIBB64_CFLAGS="-DUSE_SYSTEM_B64"
    233233    LIBB64_LIBS="-lb64"
    234234    LIBB64_LIBS_QT="-lb64"
  • trunk/libtransmission/CMakeLists.txt

    r14422 r14429  
    160160endif()
    161161
     162if(USE_SYSTEM_B64)
     163    add_definitions(-DUSE_SYSTEM_B64)
     164endif()
     165
    162166include_directories(
    163167    ${PROJECT_SOURCE_DIR}
  • trunk/libtransmission/crypto-test.c

    r14419 r14429  
    194194}
    195195
     196static bool
     197base64_eq (const char * a,
     198           const char * b)
     199{
     200  for (; ; ++a, ++b)
     201    {
     202      while (*a == '\r' || *a == '\n')
     203        ++a;
     204      while (*b == '\r' || *b == '\n')
     205        ++b;
     206      if (*a == '\0' || *b == '\0' || *a != *b)
     207        break;
     208    }
     209
     210  return *a == *b;
     211}
     212
    196213static int
    197214test_base64 (void)
     
    202219
    203220  out = tr_base64_encode_str ("YOYO!", &len);
    204   check_int_eq (8, len);
    205   check_streq ("WU9ZTyE=", out);
    206   in = tr_base64_decode_str_ (out, &len);
    207   check_int_eq (5, len);
    208   check_streq ("YOYO!", in);
    209   tr_free (in);
    210   tr_free (out);
    211 
    212   out = tr_base64_encode_str_ ("YOYO!", &len);
    213   check_int_eq (8, len);
    214   check_streq ("WU9ZTyE=", out);
     221  check_int_eq (strlen (out), len);
     222  check (base64_eq ("WU9ZTyE=", out));
    215223  in = tr_base64_decode_str (out, &len);
    216224  check_int_eq (5, len);
     
    223231  check_streq ("", out);
    224232  tr_free (out);
    225   out = tr_base64_decode_ ("", 0, &len);
     233  out = tr_base64_decode ("", 0, &len);
    226234  check_int_eq (0, len);
    227235  check_streq ("", out);
    228236  tr_free (out);
    229237
    230   out = tr_base64_encode_ ("", 0, &len);
    231   check_int_eq (0, len);
    232   check_streq ("", out);
    233   tr_free (out);
    234   out = tr_base64_decode ("", 0, &len);
    235   check_int_eq (0, len);
    236   check_streq ("", out);
    237   tr_free (out);
    238 
    239238  out = tr_base64_encode (NULL, 0, &len);
    240239  check_int_eq (0, len);
    241240  check (out == NULL);
    242   tr_free (out);
    243   out = tr_base64_decode_ (NULL, 0, &len);
     241  out = tr_base64_decode (NULL, 0, &len);
    244242  check_int_eq (0, len);
    245243  check (out == NULL);
    246   tr_free (out);
    247 
    248   out = tr_base64_encode_ (NULL, 0, &len);
    249   check_int_eq (0, len);
    250   check (out == NULL);
    251   tr_free (out);
    252   out = tr_base64_decode (NULL, 0, &len);
    253   check_int_eq (0, len);
    254   check (out == NULL);
    255   tr_free (out);
    256244
    257245#define MAX_BUF_SIZE 1024
     
    266254
    267255      out = tr_base64_encode (buf, j, &len);
    268       check_int_eq ((j + 2) / 3 * 4, len);
    269       in = tr_base64_decode_ (out, len, &len);
    270       check_int_eq (j, len);
    271       check (memcmp (in, buf, len) == 0);
    272       tr_free (in);
    273       tr_free (out);
    274 
    275       out = tr_base64_encode_ (buf, j, &len);
    276       check_int_eq ((j + 2) / 3 * 4, len);
     256      check_int_eq (strlen (out), len);
    277257      in = tr_base64_decode (out, len, &len);
    278258      check_int_eq (j, len);
     
    286266
    287267      out = tr_base64_encode_str (buf, &len);
    288       check_int_eq ((j + 2) / 3 * 4, len);
    289       in = tr_base64_decode_str_ (out, &len);
    290       check_int_eq (j, len);
    291       check_streq (in, buf);
    292       tr_free (in);
    293       tr_free (out);
    294 
    295       out = tr_base64_encode_str_ (buf, &len);
    296       check_int_eq ((j + 2) / 3 * 4, len);
     268      check_int_eq (strlen (out), len);
    297269      in = tr_base64_decode_str (out, &len);
    298270      check_int_eq (j, len);
  • trunk/libtransmission/crypto-utils.c

    r14422 r14429  
    201201      if (input_length != 0)
    202202        {
    203           size_t ret_length;
     203          size_t ret_length = 4 * ((input_length + 2) / 3);
    204204          base64_encodestate state;
    205205
    206           ret = tr_new (char, 4 * ((input_length + 2) / 3) + 1);
     206#ifdef USE_SYSTEM_B64
     207          /* Additional space is needed for newlines if we're using unpatched libb64 */
     208          ret_length += ret_length / 72 + 1;
     209#endif
     210
     211          ret = tr_new (char, ret_length + 1);
    207212
    208213          base64_init_encodestate (&state);
     
    249254      if (input_length != 0)
    250255        {
    251           size_t ret_length;
     256          size_t ret_length = input_length / 4 * 3;
    252257          base64_decodestate state;
    253258
    254           ret = tr_new (char, input_length / 4 * 3 + 1);
     259          ret = tr_new (char, ret_length + 1);
    255260
    256261          base64_init_decodestate (&state);
  • trunk/third-party/libb64/cencode.c

    r14422 r14429  
    88#include <b64/cencode.h>
    99
     10/*
    1011const int CHARS_PER_LINE = 72;
     12*/
    1113
    1214void base64_init_encodestate(base64_encodestate* state_in)
     
    7375                        *codechar++ = base64_encode_value(result);
    7476                       
    75                         /* ++(state_in->stepcount);
     77                        /*
     78                        ++(state_in->stepcount);
    7679                        if (state_in->stepcount == CHARS_PER_LINE/4)
    7780                        {
    7881                                *codechar++ = '\n';
    7982                                state_in->stepcount = 0;
    80                         } */
     83                        }
     84                        */
    8185                }
    8286        }
     
    103107                break;
    104108        }
    105         /* *codechar++ = '\n'; */
     109        /*
     110        *codechar++ = '\n';
     111        */
    106112       
    107113        return codechar - code_out;
Note: See TracChangeset for help on using the changeset viewer.