2019-11-19 14:31:44 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2020-01-18 18:32:55 +01:00
|
|
|
#include <stdlib.h>
|
2019-11-19 14:31:44 +01:00
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
2020-01-18 18:32:55 +01:00
|
|
|
#define BUF_LEN 255
|
|
|
|
|
2019-11-19 14:31:44 +01:00
|
|
|
static void test_b64_encode(const char *src)
|
|
|
|
{
|
2020-01-18 18:32:55 +01:00
|
|
|
char *dst = malloc(BUF_LEN+1);
|
|
|
|
int r = b64_encode(src, strlen(src), dst, BUF_LEN);
|
2019-11-19 14:31:44 +01:00
|
|
|
fprintf(stdout, "%d %s\n", r, dst);
|
2020-01-18 18:32:55 +01:00
|
|
|
free(dst);
|
2019-11-19 14:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_b64_decode(const char *src)
|
|
|
|
{
|
2020-01-18 18:32:55 +01:00
|
|
|
char *dst = malloc(BUF_LEN+1);
|
|
|
|
int r = b64_decode(src, dst, BUF_LEN);
|
2019-11-19 14:31:44 +01:00
|
|
|
fprintf(stdout, "%d %s\n", r, dst);
|
2020-01-18 18:32:55 +01:00
|
|
|
free(dst);
|
2019-11-19 14:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
test_b64_encode("");
|
|
|
|
test_b64_encode("f");
|
|
|
|
test_b64_encode("fo");
|
|
|
|
test_b64_encode("foo");
|
|
|
|
test_b64_encode("foob");
|
|
|
|
test_b64_encode("fooba");
|
|
|
|
test_b64_encode("foobar");
|
|
|
|
|
|
|
|
test_b64_decode("");
|
|
|
|
test_b64_decode("Zg==");
|
|
|
|
test_b64_decode("Zm8=");
|
|
|
|
test_b64_decode("Zm9v");
|
|
|
|
test_b64_decode("Zm9vYg==");
|
|
|
|
test_b64_decode("Zm9vYmE=");
|
|
|
|
test_b64_decode("Zm9vYmFy");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|