Updates from BitShares FC #22
1 changed files with 12 additions and 9 deletions
|
|
@ -28,6 +28,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
|
|
||||||
|
namespace fc { namespace detail {
|
||||||
|
|
||||||
/** Errors thrown by the bignum class */
|
/** Errors thrown by the bignum class */
|
||||||
class bignum_error : public std::runtime_error
|
class bignum_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
|
|
@ -605,11 +607,10 @@ inline bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vch
|
||||||
return DecodeBase58(str.c_str(), vchRet);
|
return DecodeBase58(str.c_str(), vchRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // detail
|
||||||
namespace fc {
|
|
||||||
|
|
||||||
std::string to_base58( const char* d, size_t s ) {
|
std::string to_base58( const char* d, size_t s ) {
|
||||||
return EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str();
|
return fc::detail::EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_base58( const std::vector<char>& d )
|
std::string to_base58( const std::vector<char>& d )
|
||||||
|
|
@ -620,8 +621,9 @@ std::string to_base58( const std::vector<char>& d )
|
||||||
}
|
}
|
||||||
std::vector<char> from_base58( const std::string& base58_str ) {
|
std::vector<char> from_base58( const std::string& base58_str ) {
|
||||||
std::vector<unsigned char> out;
|
std::vector<unsigned char> out;
|
||||||
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
if( !fc::detail::DecodeBase58( base58_str.c_str(), out ) ) {
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
|
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}",
|
||||||
|
("base58_str",base58_str) );
|
||||||
}
|
}
|
||||||
return std::vector<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
|
return std::vector<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
|
||||||
}
|
}
|
||||||
|
|
@ -629,10 +631,10 @@ std::vector<char> from_base58( const std::string& base58_str ) {
|
||||||
* @return the number of bytes decoded
|
* @return the number of bytes decoded
|
||||||
*/
|
*/
|
||||||
size_t from_base58( const std::string& base58_str, char* out_data, size_t out_data_len ) {
|
size_t from_base58( const std::string& base58_str, char* out_data, size_t out_data_len ) {
|
||||||
//slog( "%s", base58_str.c_str() );
|
|
||||||
std::vector<unsigned char> out;
|
std::vector<unsigned char> out;
|
||||||
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
if( !fc::detail::DecodeBase58( base58_str.c_str(), out ) ) {
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
|
FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}",
|
||||||
|
("base58_str",base58_str) );
|
||||||
}
|
}
|
||||||
FC_ASSERT( out.size() <= out_data_len );
|
FC_ASSERT( out.size() <= out_data_len );
|
||||||
if (!out.empty()) {
|
if (!out.empty()) {
|
||||||
|
|
@ -640,6 +642,7 @@ size_t from_base58( const std::string& base58_str, char* out_data, size_t out_da
|
||||||
}
|
}
|
||||||
return out.size();
|
return out.size();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} // fc
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue