|
@@ -54,11 +54,16 @@ void base64_encode ( const uint8_t *raw, size_t len, char *encoded ) {
|
54
|
54
|
uint8_t *encoded_bytes = ( ( uint8_t * ) encoded );
|
55
|
55
|
size_t raw_bit_len = ( 8 * len );
|
56
|
56
|
unsigned int bit;
|
|
57
|
+ unsigned int byte;
|
|
58
|
+ unsigned int shift;
|
57
|
59
|
unsigned int tmp;
|
58
|
60
|
|
59
|
61
|
for ( bit = 0 ; bit < raw_bit_len ; bit += 6 ) {
|
60
|
|
- tmp = ( ( raw_bytes[ bit / 8 ] << ( bit % 8 ) ) |
|
61
|
|
- ( raw_bytes[ bit / 8 + 1 ] >> ( 8 - ( bit % 8 ) ) ) );
|
|
62
|
+ byte = ( bit / 8 );
|
|
63
|
+ shift = ( bit % 8 );
|
|
64
|
+ tmp = ( raw_bytes[byte] << shift );
|
|
65
|
+ if ( ( byte + 1 ) < len )
|
|
66
|
+ tmp |= ( raw_bytes[ byte + 1 ] >> ( 8 - shift ) );
|
62
|
67
|
tmp = ( ( tmp >> 2 ) & 0x3f );
|
63
|
68
|
*(encoded_bytes++) = base64[tmp];
|
64
|
69
|
}
|