aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--lib/libbindle/lencoding.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/libbindle/lencoding.c b/lib/libbindle/lencoding.c
index c24623b..62c5a77 100644
--- a/lib/libbindle/lencoding.c
+++ b/lib/libbindle/lencoding.c
@@ -393,7 +393,13 @@ bindle_base32_decode(
393 datlen++; 393 datlen++;
394 break; 394 break;
395 395
396 // byte 1 396 // byte 2
397 case 2:
398 if (src[pos] == '=')
399 return((ssize_t)datlen);
400 break;
401
402 // byte 3
397 case 3: 403 case 3:
398 dst[datlen] = (map[(unsigned char)src[pos-2]] << 6) & 0xC0; // 2 MSB 404 dst[datlen] = (map[(unsigned char)src[pos-2]] << 6) & 0xC0; // 2 MSB
399 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 1) & 0x3E; // 5 MB 405 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 1) & 0x3E; // 5 MB
@@ -401,14 +407,22 @@ bindle_base32_decode(
401 datlen++; 407 datlen++;
402 break; 408 break;
403 409
404 // byte 2 410 // byte 4
405 case 4: 411 case 4:
412 if (src[pos] == '=')
413 return((ssize_t)datlen);
406 dst[datlen] = (map[(unsigned char)src[pos-1]] << 4) & 0xF0; // 4 MSB 414 dst[datlen] = (map[(unsigned char)src[pos-1]] << 4) & 0xF0; // 4 MSB
407 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 1) & 0x0F; // 4 LSB 415 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 1) & 0x0F; // 4 LSB
408 datlen++; 416 datlen++;
409 break; 417 break;
410 418
411 // byte 3 419 // byte 5;
420 case 5:
421 if (src[pos] == '=')
422 return((ssize_t)datlen);
423 break;
424
425 // byte 6
412 case 6: 426 case 6:
413 dst[datlen] = (map[(unsigned char)src[pos-2]] << 7) & 0x80; // 1 MSB 427 dst[datlen] = (map[(unsigned char)src[pos-2]] << 7) & 0x80; // 1 MSB
414 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 2) & 0x7C; // 5 MB 428 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 2) & 0x7C; // 5 MB
@@ -416,8 +430,10 @@ bindle_base32_decode(
416 datlen++; 430 datlen++;
417 break; 431 break;
418 432
419 // byte 4 433 // byte 7
420 case 7: 434 case 7:
435 if (src[pos] == '=')
436 return((ssize_t)datlen);
421 dst[datlen] = (map[(unsigned char)src[pos-1]] << 5) & 0xE0; // 3 MSB 437 dst[datlen] = (map[(unsigned char)src[pos-1]] << 5) & 0xE0; // 3 MSB
422 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 0) & 0x1F; // 5 LSB 438 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 0) & 0x1F; // 5 LSB
423 datlen++; 439 datlen++;