38 lines
887 B
C
38 lines
887 B
C
|
#include "../include/base64c.h"
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
unsigned char in[11] = "Hello Worl";
|
||
|
size_t in_len = 10;
|
||
|
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;
|
||
|
}
|
||
|
}
|