update pub/priv key to/from value conversion
This commit is contained in:
parent
efca814f0b
commit
12b637970e
6 changed files with 74 additions and 13 deletions
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef _FC_BASE58_HPP_
|
||||
#define _FC_BASE58_HPP_
|
||||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
fc::string to_base58( const char* d, uint32_t s );
|
||||
fc::vector<char> 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_
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef FC_PKE_HPP_
|
||||
#define FC_PKE_HPP_
|
||||
#pragma once
|
||||
#include <fc/sha1.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/reflect.hpp>
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef _TORNET_RPC_RAW_HPP_
|
||||
#define _TORNET_RPC_RAW_HPP_
|
||||
#pragma once
|
||||
#include <fc/reflect.hpp>
|
||||
#include <fc/datastream.hpp>
|
||||
#include <fc/varint.hpp>
|
||||
|
|
@ -7,7 +6,6 @@
|
|||
#include <fc/vector.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/array.hpp>
|
||||
//#include <fc/value.hpp>
|
||||
|
||||
namespace fc {
|
||||
class value;
|
||||
|
|
@ -280,4 +278,3 @@ namespace fc {
|
|||
|
||||
} } // namespace fc::raw
|
||||
|
||||
#endif // BOOST_RPC_RAW_HPP
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _FC_TIME_HPP_
|
||||
#define _FC_TIME_HPP_
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/raw.hpp>
|
||||
|
||||
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<typename Stream, typename T>
|
||||
void unpack( Stream& s, fc::time_point& v );
|
||||
template<typename Stream, typename T>
|
||||
void pack( Stream& s, const fc::time_point& v );
|
||||
}
|
||||
}
|
||||
#endif // _FC_TIME_HPP_
|
||||
|
|
|
|||
|
|
@ -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<char> from_base58( const fc::string& base58_str ) {
|
||||
std::vector<unsigned char> 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<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
|
||||
}
|
||||
/**
|
||||
* @return the number of bytes decoded
|
||||
*/
|
||||
|
|
|
|||
41
src/pke.cpp
41
src/pke.cpp
|
|
@ -1,6 +1,9 @@
|
|||
#include <fc/pke.hpp>
|
||||
#include <fc/error.hpp>
|
||||
#include <fc/exception.hpp>
|
||||
#include <fc/raw.hpp>
|
||||
#include <fc/value.hpp>
|
||||
#include <fc/base58.hpp>
|
||||
#include <iostream>
|
||||
#include <fc/sha1.hpp>
|
||||
#include <openssl/rsa.h>
|
||||
|
|
@ -10,6 +13,44 @@
|
|||
#include <openssl/err.h>
|
||||
|
||||
namespace fc {
|
||||
void pack( fc::value& v, const fc::public_key_t& s ) {
|
||||
fc::vector<char> 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<fc::string>(v));
|
||||
s = fc::raw::unpack<public_key_t>(ve);
|
||||
} catch ( ... ) {
|
||||
wlog( "error unpacking signature" );
|
||||
}
|
||||
}
|
||||
|
||||
void pack( fc::value& v, const fc::private_key_t& s ) {
|
||||
fc::vector<char> 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<fc::string>(v));
|
||||
s = fc::raw::unpack<private_key_t>(ve);
|
||||
} catch ( ... ) {
|
||||
wlog( "error unpacking private_key" );
|
||||
}
|
||||
}
|
||||
void pack( fc::value& v, const fc::signature_t& s ) {
|
||||
fc::vector<char> 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<fc::string>(v));
|
||||
s = fc::raw::unpack<signature_t>(ve);
|
||||
} catch ( ... ) {
|
||||
wlog( "error unpacking signature" );
|
||||
}
|
||||
}
|
||||
|
||||
RSA* get_pub( const char* key, uint32_t key_size, uint32_t pe )
|
||||
{
|
||||
RSA* rsa = RSA_new();
|
||||
|
|
|
|||
Loading…
Reference in a new issue