libxputty 0.1
Loading...
Searching...
No Matches
Functions | Variables
b64_encode.c File Reference

Go to the source code of this file.

Functions

void decodeblock (unsigned char in[], unsigned char **clrstr)
 
void b64_decode (char *b64src, char *clrdst)
 b64_decode - decode to a b64 based char
 
void encodeblock (unsigned char in[], char b64str[], int len)
 
void b64_encode (char *clrstr, char *b64dst)
 b64_encode - encode a b64 based char
 

Variables

char b64 [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 

Function Documentation

◆ b64_decode()

void b64_decode ( char *  b64src,
char *  clrdst 
)

b64_decode - decode to a b64 based char

Parameters
*b64src- the char to decode
*clrdst- the decoded char

Definition at line 26 of file b64_encode.c.

26 {
27 int c, phase, i;
28 unsigned char in[4];
29 char *p;
30
31 clrdst[0] = '\0';
32 phase = 0;
33 i=0;
34 while(b64src[i]) {
35 c = (int) b64src[i];
36 if(c == '=') {
37 decodeblock(in, (unsigned char **) &clrdst);
38 break;
39 }
40 p = strchr(b64, c);
41 if(p) {
42 in[phase] = p - b64;
43 phase = (phase + 1) % 4;
44 if(phase == 0) {
45 decodeblock(in, (unsigned char **) &clrdst);
46 in[0]=in[1]=in[2]=in[3]=0;
47 }
48 }
49 i++;
50 }
51}
void decodeblock(unsigned char in[], unsigned char **clrstr)
Definition b64_encode.c:20
char b64[]
Definition b64_encode.c:17

References b64, and decodeblock().

Referenced by widget_get_scaled_svg(), and widget_get_svg().

◆ b64_encode()

void b64_encode ( char *  clrstr,
char *  b64dst 
)

b64_encode - encode a b64 based char

Parameters
*clrstr- the char to encode
*b64dst- the encoded char

Definition at line 66 of file b64_encode.c.

66 {
67 unsigned char in[3];
68 int i, len = 0;
69 int j = 0;
70
71 b64dst[0] = '\0';
72 while(clrstr[j]) {
73 len = 0;
74 for(i=0; i<3; i++) {
75 in[i] = (unsigned char) clrstr[j];
76 if(clrstr[j]) {
77 len++;
78 j++;
79 }
80 else in[i] = 0;
81 }
82 if( len ) {
83 encodeblock( in, b64dst, len );
84 }
85 }
86}
void encodeblock(unsigned char in[], char b64str[], int len)
Definition b64_encode.c:54

References encodeblock().

◆ decodeblock()

void decodeblock ( unsigned char  in[],
unsigned char **  clrstr 
)

Definition at line 20 of file b64_encode.c.

20 {
21 *((*clrstr) ++) = in[0] << 2 | in[1] >> 4;
22 *((*clrstr) ++) = in[1] << 4 | in[2] >> 2;
23 *((*clrstr) ++) = in[2] << 6 | in[3] >> 0;
24}

Referenced by b64_decode().

◆ encodeblock()

void encodeblock ( unsigned char  in[],
char  b64str[],
int  len 
)

Definition at line 54 of file b64_encode.c.

54 {
55 unsigned char out[5];
56 out[0] = b64[ in[0] >> 2 ];
57 out[1] = b64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
58 out[2] = (unsigned char) (len > 1 ? b64[ ((in[1] & 0x0f) << 2) |
59 ((in[2] & 0xc0) >> 6) ] : '=');
60 out[3] = (unsigned char) (len > 2 ? b64[ in[2] & 0x3f ] : '=');
61 out[4] = '\0';
62 strncat(b64str, (char*)out, sizeof(char)*5);
63}

References b64.

Referenced by b64_encode().

Variable Documentation

◆ b64

char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 17 of file b64_encode.c.

Referenced by b64_decode(), and encodeblock().