source: libcf/trunk/test/codec.c@ 151

Last change on this file since 151 was 151, checked in by cheese, 11 years ago

#1 fix interface and add util module

File size: 1.5 KB
Line 
1/**
2 * @file codec.c
3 * @author myusgun <myusgun@gmail.com>
4 */
5#include "cf_codec.h"
6#include "cf_debug.h"
7#include <stdio.h>
8#include <string.h>
9
10int main (void)
11{
12 char data[] = "ONE OK ROCK - Nothing Helps";
13
14 char encode[512] = {0x00,};
15 unsigned char bin[512] = {0x00,};
16 size_t length = 0;
17
18 /* hex */
19 CF_DEBUG_PRINT (stderr, "------------------- codec/hex ----------------\n");
20 CF_DEBUG_PRINT (stderr, "data : %s\n", data);
21 CF_DEBUG_PRINT (stderr, "= Convert binary to hex =\n");
22 CF_Codec_Hex_Encode ((unsigned char *)data, strlen (data), encode);
23 CF_DEBUG_PRINT (stderr, "hex : %s\n", encode);
24 CF_DEBUG_PRINT_BIN (stderr, (unsigned char *) data, strlen (data), "data : %s\n", data);
25
26 CF_DEBUG_PRINT (stderr, "= Convert hex to binary =\n");
27 if (CF_Codec_Hex_Decode (encode, bin, &length) < 0)
28 CF_DEBUG_PRINT (stderr, "error\n");
29 else
30 CF_DEBUG_PRINT_BIN (stderr, bin, length, "bin : %s\n", bin);
31
32 memset (bin , 0x00, sizeof (bin));
33 memset (encode, 0x00, sizeof (encode));
34 length = 0;
35
36 /* base64 */
37 CF_DEBUG_PRINT (stderr, "----------------- codec/base64 ---------------\n");
38 CF_DEBUG_PRINT (stderr, "data : %s\n", data);
39 CF_DEBUG_PRINT (stderr, "= Convert binary to base64 =\n");
40 CF_Codec_Base64_Encode ((unsigned char *)data, strlen (data), encode);
41 CF_DEBUG_PRINT (stderr, "base64 : %s\n", encode);
42
43 CF_DEBUG_PRINT (stderr, "= Convert base64 to binary =\n");
44 if (CF_Codec_Base64_Decode (encode, bin, &length) < 0) {
45 // error
46 }
47 else
48 CF_DEBUG_PRINT_BIN (stderr, bin, length, "bin : %s\n", bin);
49
50 return 0;
51}
Note: See TracBrowser for help on using the repository browser.