libubox
C utility functions for OpenWrt.
test-b64.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include "utils.h"
6 
7 #define BUF_LEN 255
8 
9 static void test_b64_encode(const char *src)
10 {
11  char *dst = malloc(BUF_LEN+1);
12  int r = b64_encode(src, strlen(src), dst, BUF_LEN);
13  fprintf(stdout, "%d %s\n", r, dst);
14  free(dst);
15 }
16 
17 static void test_b64_decode(const char *src)
18 {
19  char *dst = malloc(BUF_LEN+1);
20  int r = b64_decode(src, dst, BUF_LEN);
21  fprintf(stdout, "%d %s\n", r, dst);
22  free(dst);
23 }
24 
25 int main()
26 {
27  test_b64_encode("");
28  test_b64_encode("f");
29  test_b64_encode("fo");
30  test_b64_encode("foo");
31  test_b64_encode("foob");
32  test_b64_encode("fooba");
33  test_b64_encode("foobar");
34 
35  test_b64_decode("");
36  test_b64_decode("Zg==");
37  test_b64_decode("Zm8=");
38  test_b64_decode("Zm9v");
39  test_b64_decode("Zm9vYg==");
40  test_b64_decode("Zm9vYmE=");
41  test_b64_decode("Zm9vYmFy");
42 
43  return 0;
44 }
int b64_encode(const void *_src, size_t srclength, void *dest, size_t targsize)
Definition: base64.c:139
int b64_decode(const void *_src, void *dest, size_t targsize)
Definition: base64.c:203
#define BUF_LEN
Definition: test-b64.c:7
static void test_b64_decode(const char *src)
Definition: test-b64.c:17
static void test_b64_encode(const char *src)
Definition: test-b64.c:9
int main()
Definition: test-b64.c:25