@ -27,11 +27,9 @@
/// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood.
# include "Base64.h"
# include <iostream>
using namespace std ;
using namespace dev ;
static const std : : string base64_chars =
static const char base64_chars [ ] =
" ABCDEFGHIJKLMNOPQRSTUVWXYZ "
" abcdefghijklmnopqrstuvwxyz "
" 0123456789+/ " ;
@ -40,6 +38,11 @@ static inline bool is_base64(byte c) {
return ( isalnum ( c ) | | ( c = = ' + ' ) | | ( c = = ' / ' ) ) ;
}
static inline byte find_base64_char_index ( byte c ) {
auto it = std : : find ( base64_chars , base64_chars + sizeof ( base64_chars ) , c ) ;
return static_cast < byte > ( it - base64_chars ) ;
}
std : : string dev : : toBase64 ( bytesConstRef _in ) {
std : : string ret ;
int i = 0 ;
@ -85,7 +88,7 @@ std::string dev::toBase64(bytesConstRef _in) {
}
bytes dev : : fromBase64 ( std : : string const & encoded_string ) {
int in_len = encoded_string . size ( ) ;
auto in_len = encoded_string . size ( ) ;
int i = 0 ;
int j = 0 ;
int in_ = 0 ;
@ -94,9 +97,9 @@ bytes dev::fromBase64(std::string const& encoded_string) {
while ( in_len - - & & ( encoded_string [ in_ ] ! = ' = ' ) & & is_base64 ( encoded_string [ in_ ] ) ) {
char_array_4 [ i + + ] = encoded_string [ in_ ] ; in_ + + ;
if ( i = = 4 ) {
for ( i = 0 ; i < 4 ; i + + )
char_array_4 [ i ] = base64_chars . find ( char_array_4 [ i ] ) ;
if ( i = = 4 ) {
for ( i = 0 ; i < 4 ; i + + )
char_array_4 [ i ] = find_base64_char_index ( char_array_4 [ i ] ) ;
char_array_3 [ 0 ] = ( char_array_4 [ 0 ] < < 2 ) + ( ( char_array_4 [ 1 ] & 0x30 ) > > 4 ) ;
char_array_3 [ 1 ] = ( ( char_array_4 [ 1 ] & 0xf ) < < 4 ) + ( ( char_array_4 [ 2 ] & 0x3c ) > > 2 ) ;
@ -109,11 +112,11 @@ bytes dev::fromBase64(std::string const& encoded_string) {
}
if ( i ) {
for ( j = i ; j < 4 ; j + + )
for ( j = i ; j < 4 ; j + + )
char_array_4 [ j ] = 0 ;
for ( j = 0 ; j < 4 ; j + + )
char_array_4 [ j ] = base64_chars . find ( char_array_4 [ j ] ) ;
for ( j = 0 ; j < 4 ; j + + )
char_array_4 [ j ] = find_base64_char_index ( char_array_4 [ j ] ) ;
char_array_3 [ 0 ] = ( char_array_4 [ 0 ] < < 2 ) + ( ( char_array_4 [ 1 ] & 0x30 ) > > 4 ) ;
char_array_3 [ 1 ] = ( ( char_array_4 [ 1 ] & 0xf ) < < 4 ) + ( ( char_array_4 [ 2 ] & 0x3c ) > > 2 ) ;