diff --git a/include/fc/base58.hpp b/include/fc/base58.hpp index 3c5a714..e9dc90c 100644 --- a/include/fc/base58.hpp +++ b/include/fc/base58.hpp @@ -1,9 +1,8 @@ -#ifndef _FC_BASE58_HPP_ -#define _FC_BASE58_HPP_ +#pragma once #include namespace fc { fc::string to_base58( const char* d, uint32_t s ); + fc::vector from_base58( const fc::string& base58_str ); size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_data_len ); } -#endif // _FC_BASE58_HPP_ diff --git a/include/fc/pke.hpp b/include/fc/pke.hpp index 912f7fc..b0edba9 100644 --- a/include/fc/pke.hpp +++ b/include/fc/pke.hpp @@ -1,7 +1,7 @@ -#ifndef FC_PKE_HPP_ -#define FC_PKE_HPP_ +#pragma once #include #include +#include /** * Define common crypto methods and data types to abstract underlying implementation. @@ -143,7 +143,13 @@ namespace fc { typedef private_key<> private_key_t; typedef signature<> signature_t; + class value; + void pack( fc::value& , const fc::signature_t& ); + void unpack( const fc::value& , fc::signature_t& ); + void pack( fc::value& , const fc::public_key_t& ); + void unpack( const fc::value& , fc::private_key_t& ); + void pack( fc::value& , const fc::private_key_t& ); + void unpack( const fc::value& , fc::public_key_t& ); } // namespace fc -#endif diff --git a/include/fc/raw.hpp b/include/fc/raw.hpp index 0de79c6..e9428b8 100644 --- a/include/fc/raw.hpp +++ b/include/fc/raw.hpp @@ -1,5 +1,4 @@ -#ifndef _TORNET_RPC_RAW_HPP_ -#define _TORNET_RPC_RAW_HPP_ +#pragma once #include #include #include @@ -7,7 +6,6 @@ #include #include #include -//#include namespace fc { class value; @@ -280,4 +278,3 @@ namespace fc { } } // namespace fc::raw -#endif // BOOST_RPC_RAW_HPP diff --git a/include/fc/time.hpp b/include/fc/time.hpp index 6771a37..7f9678d 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -1,7 +1,7 @@ -#ifndef _FC_TIME_HPP_ -#define _FC_TIME_HPP_ +#pragma once #include #include +#include namespace fc { class microseconds { @@ -41,5 +41,16 @@ namespace fc { private: microseconds elapsed; }; + + // forward declare io + class value; + void pack( fc::value& , const fc::time_point& ); + void unpack( const fc::value& , fc::time_point& ); + + namespace raw { + template + void unpack( Stream& s, fc::time_point& v ); + template + void pack( Stream& s, const fc::time_point& v ); + } } -#endif // _FC_TIME_HPP_ diff --git a/src/base58.cpp b/src/base58.cpp index 9145db6..073a985 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -610,6 +610,13 @@ fc::string to_base58( const char* d, uint32_t s ) { return EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str(); } +fc::vector from_base58( const fc::string& base58_str ) { + std::vector out; + if( !DecodeBase58( base58_str.c_str(), out ) ) { + FC_THROW_REPORT( "Unable to decode base58 string ${base58_str}", fc::value().set("base58_str",base58_str) ); + } + return fc::vector((const char*)out.data(), ((const char*)out.data())+out.size() ); +} /** * @return the number of bytes decoded */ diff --git a/src/pke.cpp b/src/pke.cpp index 9cc4460..97d8a00 100644 --- a/src/pke.cpp +++ b/src/pke.cpp @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -10,6 +13,44 @@ #include namespace fc { + void pack( fc::value& v, const fc::public_key_t& s ) { + fc::vector ve = fc::raw::pack( s ); + v = to_base58( ve.data(), ve.size() ); + } + void unpack( const fc::value& v, fc::public_key_t& s ) { + try { + auto ve = from_base58(fc::value_cast(v)); + s = fc::raw::unpack(ve); + } catch ( ... ) { + wlog( "error unpacking signature" ); + } + } + + void pack( fc::value& v, const fc::private_key_t& s ) { + fc::vector ve = fc::raw::pack( s ); + v = to_base58( ve.data(), ve.size() ); + } + void unpack( const fc::value& v, fc::private_key_t& s ) { + try { + auto ve = from_base58(fc::value_cast(v)); + s = fc::raw::unpack(ve); + } catch ( ... ) { + wlog( "error unpacking private_key" ); + } + } + void pack( fc::value& v, const fc::signature_t& s ) { + fc::vector ve = fc::raw::pack( s ); + v = to_base58( ve.data(), ve.size() ); + } + void unpack( const fc::value& v, fc::signature_t& s ) { + try { + auto ve = from_base58(fc::value_cast(v)); + s = fc::raw::unpack(ve); + } catch ( ... ) { + wlog( "error unpacking signature" ); + } + } + RSA* get_pub( const char* key, uint32_t key_size, uint32_t pe ) { RSA* rsa = RSA_new();