forked from cory/tildefriends
Cory McWilliams
79022e1e1f
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3621 ed5197a5-7fde-0310-b194-c3ffbd925b24
38 lines
891 B
C
38 lines
891 B
C
#include "../include/base64c.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
unsigned char in[10] = "Hello Wo";
|
|
size_t in_len = 8;
|
|
unsigned char enc[32];
|
|
size_t enc_len = 32;
|
|
unsigned char out[12];
|
|
size_t out_len = 12;
|
|
|
|
printf("Encoding %lu - %s\n", in_len, in);
|
|
|
|
size_t enc_result = base64c_encode(in, in_len, enc, enc_len);
|
|
|
|
printf("Encoded %lu - %s\n", enc_result, enc);
|
|
|
|
size_t dec_result = base64c_decode(enc, enc_result, out, out_len);
|
|
|
|
if ((long)dec_result < 0) {
|
|
printf("Decode failed with code %ld\n", (long)dec_result);
|
|
return 1;
|
|
}
|
|
|
|
printf("Decoded %lu - %s\n", dec_result, out);
|
|
|
|
if (dec_result != in_len) {
|
|
printf("in length %ld not equal to out length %ld", in_len, dec_result);
|
|
return 3;
|
|
}
|
|
|
|
if (strncmp((char*)in, (char*)out, in_len)) {
|
|
printf("roundtrip encoding failed\n");
|
|
return 2;
|
|
}
|
|
}
|