Example #1
0
static void
test_util_format_base64_decode_nopad(void *ignored)
{
    (void)ignored;
    int res;
    int i;
    char *src;
    uint8_t *dst;

    src = tor_malloc_zero(256);
    dst = tor_malloc_zero(1000);

    for(i=0; i<256; i++) {
        src[i] = (char)i;
    }

    res = base64_decode_nopad(dst, 1, src, SIZE_T_CEILING);
    tt_int_op(res, OP_EQ, -1);

    res = base64_decode_nopad(dst, 1, src, 5);
    tt_int_op(res, OP_EQ, -1);

done:
    tor_free(src);
    tor_free(dst);
}
Example #2
0
static void
test_util_format_base64_decode_nopad(void *ignored)
{
  (void)ignored;
  int res;
  int i;
  char *src;
  uint8_t *dst, *real_dst;
  uint8_t expected[] = {0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65};
  char real_src[] = "ZXhhbXBsZQ";

  src = tor_malloc_zero(256);
  dst = tor_malloc_zero(1000);
  real_dst = tor_malloc_zero(10);

  for (i=0;i<256;i++) {
    src[i] = (char)i;
  }

  res = base64_decode_nopad(dst, 1, src, SIZE_T_CEILING);
  tt_int_op(res, OP_EQ, -1);

  res = base64_decode_nopad(dst, 1, src, 5);
  tt_int_op(res, OP_EQ, -1);

  const char *s = "SGVsbG8gd29ybGQ";
  res = base64_decode_nopad(dst, 1000, s, strlen(s));
  tt_int_op(res, OP_EQ, 11);
  tt_mem_op(dst, OP_EQ, "Hello world", 11);

  s = "T3BhIG11bmRv";
  res = base64_decode_nopad(dst, 9, s, strlen(s));
  tt_int_op(res, OP_EQ, 9);
  tt_mem_op(dst, OP_EQ, "Opa mundo", 9);

  res = base64_decode_nopad(real_dst, 10, real_src, 10);
  tt_int_op(res, OP_EQ, 7);
  tt_mem_op(real_dst, OP_EQ, expected, 7);

 done:
  tor_free(src);
  tor_free(dst);
  tor_free(real_dst);
}