Skip to content
This repository was archived by the owner on May 4, 2021. It is now read-only.

Commit 539af75

Browse files
committed
Indent code.
1 parent a9a9cf4 commit 539af75

File tree

14 files changed

+1225
-1102
lines changed

14 files changed

+1225
-1102
lines changed

cdecode.c

Lines changed: 86 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,101 @@ For details, see http://sourceforge.net/projects/libb64
77

88
#include <cdecode.h>
99

10-
int base64_decode_value(char value_in)
10+
int
11+
base64_decode_value (char value_in)
1112
{
12-
static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
13-
static const char decoding_size = sizeof(decoding);
14-
value_in -= 43;
15-
if (value_in < 0 || value_in > decoding_size) return -1;
16-
return decoding[(int)value_in];
13+
static const char decoding[] =
14+
{ 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1,
15+
-2, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
16+
17, 18, 19, 20, 21, 22, 23,
17+
24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
18+
36, 37, 38, 39, 40, 41, 42,
19+
43, 44, 45, 46, 47, 48, 49, 50, 51
20+
};
21+
static const char decoding_size = sizeof (decoding);
22+
value_in -= 43;
23+
if (value_in < 0 || value_in > decoding_size)
24+
return -1;
25+
return decoding[(int) value_in];
1726
}
1827

19-
void base64_init_decodestate(base64_decodestate* state_in)
28+
void
29+
base64_init_decodestate (base64_decodestate * state_in)
2030
{
21-
state_in->step = step_a;
22-
state_in->plainchar = 0;
31+
state_in->step = step_a;
32+
state_in->plainchar = 0;
2333
}
2434

25-
int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in)
35+
int
36+
base64_decode_block (const char *code_in, const int length_in,
37+
char *plaintext_out, base64_decodestate * state_in)
2638
{
27-
const char* codechar = code_in;
28-
char* plainchar = plaintext_out;
29-
signed char fragment;
30-
31-
*plainchar = state_in->plainchar;
32-
33-
switch (state_in->step)
39+
const char *codechar = code_in;
40+
char *plainchar = plaintext_out;
41+
signed char fragment;
42+
43+
*plainchar = state_in->plainchar;
44+
45+
switch (state_in->step)
46+
{
47+
while (1)
3448
{
35-
while (1)
49+
case step_a:
50+
do
51+
{
52+
if (codechar == code_in + length_in)
53+
{
54+
state_in->step = step_a;
55+
state_in->plainchar = *plainchar;
56+
return plainchar - plaintext_out;
57+
}
58+
fragment = (char) base64_decode_value (*codechar++);
59+
}
60+
while (fragment < 0);
61+
*plainchar = (fragment & 0x03f) << 2;
62+
case step_b:
63+
do
64+
{
65+
if (codechar == code_in + length_in)
66+
{
67+
state_in->step = step_b;
68+
state_in->plainchar = *plainchar;
69+
return plainchar - plaintext_out;
70+
}
71+
fragment = (char) base64_decode_value (*codechar++);
72+
}
73+
while (fragment < 0);
74+
*plainchar++ |= (fragment & 0x030) >> 4;
75+
*plainchar = (fragment & 0x00f) << 4;
76+
case step_c:
77+
do
78+
{
79+
if (codechar == code_in + length_in)
80+
{
81+
state_in->step = step_c;
82+
state_in->plainchar = *plainchar;
83+
return plainchar - plaintext_out;
84+
}
85+
fragment = (char) base64_decode_value (*codechar++);
86+
}
87+
while (fragment < 0);
88+
*plainchar++ |= (fragment & 0x03c) >> 2;
89+
*plainchar = (fragment & 0x003) << 6;
90+
case step_d:
91+
do
92+
{
93+
if (codechar == code_in + length_in)
3694
{
37-
case step_a:
38-
do {
39-
if (codechar == code_in+length_in)
40-
{
41-
state_in->step = step_a;
42-
state_in->plainchar = *plainchar;
43-
return plainchar - plaintext_out;
44-
}
45-
fragment = (char)base64_decode_value(*codechar++);
46-
} while (fragment < 0);
47-
*plainchar = (fragment & 0x03f) << 2;
48-
case step_b:
49-
do {
50-
if (codechar == code_in+length_in)
51-
{
52-
state_in->step = step_b;
53-
state_in->plainchar = *plainchar;
54-
return plainchar - plaintext_out;
55-
}
56-
fragment = (char)base64_decode_value(*codechar++);
57-
} while (fragment < 0);
58-
*plainchar++ |= (fragment & 0x030) >> 4;
59-
*plainchar = (fragment & 0x00f) << 4;
60-
case step_c:
61-
do {
62-
if (codechar == code_in+length_in)
63-
{
64-
state_in->step = step_c;
65-
state_in->plainchar = *plainchar;
66-
return plainchar - plaintext_out;
67-
}
68-
fragment = (char)base64_decode_value(*codechar++);
69-
} while (fragment < 0);
70-
*plainchar++ |= (fragment & 0x03c) >> 2;
71-
*plainchar = (fragment & 0x003) << 6;
72-
case step_d:
73-
do {
74-
if (codechar == code_in+length_in)
75-
{
76-
state_in->step = step_d;
77-
state_in->plainchar = *plainchar;
78-
return plainchar - plaintext_out;
79-
}
80-
fragment = (char)base64_decode_value(*codechar++);
81-
} while (fragment < 0);
82-
*plainchar++ |= (fragment & 0x03f);
95+
state_in->step = step_d;
96+
state_in->plainchar = *plainchar;
97+
return plainchar - plaintext_out;
8398
}
99+
fragment = (char) base64_decode_value (*codechar++);
100+
}
101+
while (fragment < 0);
102+
*plainchar++ |= (fragment & 0x03f);
84103
}
85-
/* control should not reach here */
86-
return plainchar - plaintext_out;
104+
}
105+
/* control should not reach here */
106+
return plainchar - plaintext_out;
87107
}

cdecode.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@ cdecode.h - c header for a base64 decoding algorithm
33
44
This is part of the libb64 project, and has been placed in the public domain.
55
For details, see http://sourceforge.net/projects/libb64
6-
*/
7-
6+
*/
7+
88
#ifndef BASE64_CDECODE_H
99
#define BASE64_CDECODE_H
10-
11-
typedef enum
12-
{
13-
step_a, step_b, step_c, step_d
14-
} base64_decodestep;
15-
16-
typedef struct
17-
{
18-
base64_decodestep step;
19-
char plainchar;
20-
} base64_decodestate;
21-
22-
void base64_init_decodestate(base64_decodestate* state_in);
23-
24-
int base64_decode_value(char value_in);
25-
26-
int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in);
27-
28-
#endif /* BASE64_CDECODE_H */
10+
typedef enum
11+
{ step_a, step_b, step_c, step_d
12+
} base64_decodestep;
13+
typedef struct
14+
{
15+
base64_decodestep step;
16+
char plainchar;
17+
} base64_decodestate;
18+
void base64_init_decodestate (base64_decodestate * state_in);
19+
int base64_decode_value (char value_in);
20+
int base64_decode_block (const char *code_in, const int length_in,
21+
char *plaintext_out,
22+
base64_decodestate * state_in);
23+
24+
#endif /* BASE64_CDECODE_H */

0 commit comments

Comments
 (0)