| 672 | |
| 673 | |
| 674 | static int decode_sequence(const unsigned char *coded, unsigned char *plain) { |
| 675 | ENCODING_LOG("[decode_sequence] Starting sequence decoding"); |
| 676 | |
| 677 | assert(CHAR_BIT == 8); |
| 678 | assert(coded && plain); |
| 679 | |
| 680 | plain[0] = 0; |
| 681 | for (int block = 0; block < 8; block++) { |
| 682 | int offset = get_offset(block); |
| 683 | int octet = get_octet(block); |
| 684 | |
| 685 | ENCODING_LOG("[decode_sequence] Decoding block %d, offset: %d, octet: %d", block, offset, octet); |
| 686 | |
| 687 | int c = decode_char(coded[block]); |
| 688 | if (c < 0) { |
| 689 | ENCODING_LOG("[decode_sequence] Invalid character at block %d", block); |
| 690 | return octet; |
| 691 | } |
| 692 | |
| 693 | plain[octet] |= shift_left(c, offset); |
| 694 | if (offset < 0) { |
| 695 | assert(octet < 4); |
| 696 | plain[octet + 1] = shift_left(c, 8 + offset); |
| 697 | ENCODING_LOG("[decode_sequence] Block overflows to next octet."); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | ENCODING_LOG("[decode_sequence] Decoding completed successfully"); |
| 702 | return 5; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /** |
no test coverage detected