fix bug loading null pubkey from binary

This commit is contained in:
Daniel Larimer 2013-09-11 17:54:45 -04:00
parent 5c38242a7a
commit b644ce2b67
2 changed files with 11 additions and 7 deletions

View file

@ -48,12 +48,12 @@ namespace fc
* and other information that is generally only useful for * and other information that is generally only useful for
* developers. * developers.
*/ */
string to_detail_string( log_level ll = log_level::all )const; std::string to_detail_string( log_level ll = log_level::all )const;
/** /**
* Generates a user-friendly error report. * Generates a user-friendly error report.
*/ */
string to_string( log_level ll = log_level::info )const; std::string to_string( log_level ll = log_level::info )const;
/** /**
* Throw this exception as its most derived type. * Throw this exception as its most derived type.
@ -183,7 +183,7 @@ namespace fc
FC_DECLARE_EXCEPTION( assert_exception, "Assert Exception" ); FC_DECLARE_EXCEPTION( assert_exception, "Assert Exception" );
FC_DECLARE_EXCEPTION( eof_exception, "End Of File" ); FC_DECLARE_EXCEPTION( eof_exception, "End Of File" );
fc::string except_str(); std::string except_str();
} // namespace fc } // namespace fc

View file

@ -389,11 +389,15 @@ namespace fc { namespace ecc {
public_key::public_key( const public_key_data& dat ) public_key::public_key( const public_key_data& dat )
{ {
const char* front = &dat.data[0]; const char* front = &dat.data[0];
my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 ); if( *front == 0 ){}
my->_key = o2i_ECPublicKey( &my->_key, (const unsigned char**)&front, sizeof(public_key_data) ); else
if( !my->_key )
{ {
FC_THROW_EXCEPTION( exception, "error decoding public key", ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); my->_key = EC_KEY_new_by_curve_name( NID_secp256k1 );
my->_key = o2i_ECPublicKey( &my->_key, (const unsigned char**)&front, sizeof(public_key_data) );
if( !my->_key )
{
FC_THROW_EXCEPTION( exception, "error decoding public key", ("s", ERR_error_string( ERR_get_error(), nullptr) ) );
}
} }
} }