@@ -51,28 +51,27 @@ size_t base64_encode(char *dst, const char *src, size_t src_len)
51
51
const unsigned char * basis64 = base64_default_tables .encode ;
52
52
53
53
while (src_len > 2 ) {
54
- * d ++ = basis64 [(s [0 ] >> 2 ) & 0x3f ];
55
- * d ++ = basis64 [((s [0 ] & 3 ) << 4 ) | (s [1 ] >> 4 )];
56
- * d ++ = basis64 [((s [1 ] & 0x0f ) << 2 ) | (s [2 ] >> 6 )];
57
- * d ++ = basis64 [s [2 ] & 0x3f ];
54
+ * d ++ = basis64 [(s [0 ] >> 2 ) & 0x3f ];
55
+ * d ++ = basis64 [((s [0 ] & 3 ) << 4 ) | (s [1 ] >> 4 )];
56
+ * d ++ = basis64 [((s [1 ] & 0x0f ) << 2 ) | (s [2 ] >> 6 )];
57
+ * d ++ = basis64 [s [2 ] & 0x3f ];
58
58
59
- s += 3 ;
60
- src_len -= 3 ;
59
+ s += 3 ;
60
+ src_len -= 3 ;
61
61
}
62
62
63
63
if (src_len ) {
64
- * d ++ = basis64 [(s [0 ] >> 2 ) & 0x3f ];
65
-
66
- if (src_len == 1 ) {
67
- * d ++ = basis64 [(s [0 ] & 3 ) << 4 ];
68
- * d ++ = base64_default_tables .padding ;
69
-
70
- } else {
71
- * d ++ = basis64 [((s [0 ] & 3 ) << 4 ) | (s [1 ] >> 4 )];
72
- * d ++ = basis64 [(s [1 ] & 0x0f ) << 2 ];
73
- }
64
+ * d ++ = basis64 [(s [0 ] >> 2 ) & 0x3f ];
74
65
66
+ if (src_len == 1 ) {
67
+ * d ++ = basis64 [(s [0 ] & 3 ) << 4 ];
75
68
* d ++ = base64_default_tables .padding ;
69
+ } else {
70
+ * d ++ = basis64 [((s [0 ] & 3 ) << 4 ) | (s [1 ] >> 4 )];
71
+ * d ++ = basis64 [(s [1 ] & 0x0f ) << 2 ];
72
+ }
73
+
74
+ * d ++ = base64_default_tables .padding ;
76
75
}
77
76
78
77
return (d - dst );
@@ -86,35 +85,34 @@ size_t base64_decode(char *dst, const char *src, size_t src_len)
86
85
const unsigned char * basis = base64_default_tables .decode ;
87
86
88
87
for (len = 0 ; len < src_len ; len ++ ) {
89
-
90
88
if (s [len ] == base64_default_tables .padding ) {
91
- break ;
92
- }
89
+ break ;
90
+ }
93
91
94
- if (basis [s [len ]] == 77 ) {
95
- return 0 ;
96
- }
92
+ if (basis [s [len ]] == 77 ) {
93
+ return 0 ;
94
+ }
97
95
}
98
96
99
97
if (len % 4 == 1 ) {
100
- return 0 ;
98
+ return 0 ;
101
99
}
102
100
103
101
while (len > 3 ) {
104
- * d ++ = (char ) (basis [s [0 ]] << 2 | basis [s [1 ]] >> 4 );
105
- * d ++ = (char ) (basis [s [1 ]] << 4 | basis [s [2 ]] >> 2 );
106
- * d ++ = (char ) (basis [s [2 ]] << 6 | basis [s [3 ]]);
102
+ * d ++ = (char ) (basis [s [0 ]] << 2 | basis [s [1 ]] >> 4 );
103
+ * d ++ = (char ) (basis [s [1 ]] << 4 | basis [s [2 ]] >> 2 );
104
+ * d ++ = (char ) (basis [s [2 ]] << 6 | basis [s [3 ]]);
107
105
108
- s += 4 ;
109
- len -= 4 ;
106
+ s += 4 ;
107
+ len -= 4 ;
110
108
}
111
109
112
110
if (len > 1 ) {
113
- * d ++ = (char ) (basis [s [0 ]] << 2 | basis [s [1 ]] >> 4 );
111
+ * d ++ = (char ) (basis [s [0 ]] << 2 | basis [s [1 ]] >> 4 );
114
112
}
115
113
116
114
if (len > 2 ) {
117
- * d ++ = (char ) (basis [s [1 ]] << 4 | basis [s [2 ]] >> 2 );
115
+ * d ++ = (char ) (basis [s [1 ]] << 4 | basis [s [2 ]] >> 2 );
118
116
}
119
117
120
118
return (d - dst );
0 commit comments