Changeset 91 in libcf
- Timestamp:
- 05/19/13 13:24:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_codec.c
r90 r91 77 77 * 78 78 * @remark 79 * hex는 할당된 메모리이며, 크기는 '\0'를 포함하여 len * 2 + 179 * hex는 할당된 메모리이며, 크기는 '\0'를 제외하고 len * 2 80 80 */ 81 81 int … … 172 172 * 173 173 * @remark 174 * base64는 할당된 메모리이며, 크기는 ((len + 2) / 3) * 4 175 * (null-character 제외) 174 * base64는 할당된 메모리이며, 크기는 '\0'를 제외하고 ((len + 2) / 3) * 4 176 175 */ 177 176 int … … 209 208 if (src - bin == len - 1) 210 209 { 211 *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 ( bin)];210 *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (src)]; 212 211 *dst++ = g_table_Base64Encode[BASE64_PADDING_CHAR_INDEX]; 213 212 } 214 213 else 215 214 { 216 *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 ( bin)|217 SEXTUPLE_E_3 ( bin)];218 *dst++ = g_table_Base64Encode[SEXTUPLE_E_4 ( bin)];215 *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (src)| 216 SEXTUPLE_E_3 (src)]; 217 *dst++ = g_table_Base64Encode[SEXTUPLE_E_4 (src)]; 219 218 } 220 219 … … 235 234 * 236 235 * @remark 237 * base64는 할당된 메모리이며, 크기는 (strlen (base64) - <패딩 길이>) / 4 * 3236 * base64는 할당된 메모리이며, 크기는 (strlen (base64)) / 4 * 3 238 237 */ 239 238 int … … 241 240 unsigned char * bin) 242 241 { 243 int remain = 0;244 242 const char * src = base64; 245 243 unsigned char * dst = bin; 244 int remain = 0; 246 245 int binlen = 0; 247 246 … … 251 250 while (g_ascii_Base64Decode[(int)*src] < BASE64_PADDING_CHAR_INDEX) src++; 252 251 253 if (*src )252 if (*src == 0xff) 254 253 return CF_ERROR_CODEC_NOT_BASE64; 255 254 256 255 remain = (int)(src - base64); 257 binlen = ((remain + 3) / 4) * 3;256 binlen = ((remain + 2/* max padding length */) / 4) * 3; 258 257 259 258 #define SEXTUPLE_D_1(src) (g_ascii_Base64Decode[(int)src[0]] << 2) … … 264 263 #define SEXTUPLE_D_6(src) (g_ascii_Base64Decode[(int)src[3]] ) 265 264 266 for (src = base64 , dst = bin; remain > 4 ; remain -= 4, src += 4)265 for (src = base64 ; remain > 4 ; remain -= 4, src += 4) 267 266 { 268 267 *dst++ = (unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src)); … … 278 277 *dst++ = (unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src)); 279 278 280 return binlen ;281 } 279 return binlen - (4 % remain); 280 }
Note:
See TracChangeset
for help on using the changeset viewer.