Exemple #1
0
static void
base64_test(const char *str, int options, const char *no_symbols,
	    int no_symbols_len)
{
	plan(3 + no_symbols_len);

	int len = strlen(str);
	int base64_buflen = base64_bufsize(len + 1, options);
	char *base64_buf = malloc(base64_buflen);
	char *strbuf = malloc(len + 1);
	int rc = base64_encode(str, len + 1, base64_buf, base64_buflen,
			       options);
	ok(rc <= base64_buflen, "length");
	for (int i = 0; i < no_symbols_len; ++i) {
		char c = no_symbols[i];
		if (c == '\n') {
			is(memchr(base64_buf, no_symbols[i], base64_buflen),
			   NULL, "no \\n symbols");
		} else {
			is(memchr(base64_buf, no_symbols[i], base64_buflen),
			   NULL, "no %c symbols", no_symbols[i]);
		}
	}

	is(base64_decode(base64_buf, rc, strbuf, len + 1), len + 1,
	   "decode length ok");
	is(strcmp(str, strbuf), 0, "encode/decode");

	free(base64_buf);
	free(strbuf);

	check_plan();
}
static size_t make_msg
(MsgHeader* msg, int type, int encrypted, const void* rawdata, size_t siz)
{
  if(siz > raw_data_len)
    abort();
  
  size_t msgsiz;
  
  msg->type = type;
  msg->encrypted = (encrypted?1:0);
  
  if(!encrypted){
    msgsiz = siz;
    memcpy(msg+1, rawdata, siz);
  }else{
    msgsiz = base64_bufsize(siz);
    base64_encode((char*)(msg+1), msgsiz, rawdata, siz);
  }
  
  return msgsiz;
}
Exemple #3
0
static void
base64_test(const char *str)
{
	header();

	int len = strlen(str);
	int base64_buflen = base64_bufsize(len);
	char *base64_buf = malloc(base64_buflen);
	char *strbuf = malloc(len + 1);

	int res = base64_encode(str, len, base64_buf, base64_buflen);

	fail_unless(strlen(base64_buf) == res);

	base64_decode(base64_buf, strlen(base64_buf), strbuf, len + 1);

	fail_unless(strcmp(str, strbuf) == 0);

	free(base64_buf);
	free(strbuf);

	footer();
}