Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
hex.cpp
Go to the documentation of this file.
1#include <fc/crypto/hex.hpp>
3
4namespace fc {
5
6 uint8_t from_hex( char c ) {
7 if( c >= '0' && c <= '9' )
8 return c - '0';
9 if( c >= 'a' && c <= 'f' )
10 return c - 'a' + 10;
11 if( c >= 'A' && c <= 'F' )
12 return c - 'A' + 10;
13 FC_THROW_EXCEPTION( exception, "Invalid hex character '${c}'", ("c", fc::string(&c,1) ) );
14 return 0;
15 }
16
17 std::string to_hex( const char* d, uint32_t s )
18 {
19 std::string r;
20 const char* to_hex="0123456789abcdef";
21 uint8_t* c = (uint8_t*)d;
22 for( uint32_t i = 0; i < s; ++i )
23 (r += to_hex[(c[i]>>4)]) += to_hex[(c[i] &0x0f)];
24 return r;
25 }
26
27 size_t from_hex( const fc::string& hex_str, char* out_data, size_t out_data_len ) {
28 fc::string::const_iterator i = hex_str.begin();
29 uint8_t* out_pos = (uint8_t*)out_data;
30 uint8_t* out_end = out_pos + out_data_len;
31 while( i != hex_str.end() && out_end != out_pos ) {
32 *out_pos = from_hex( *i ) << 4;
33 ++i;
34 if( i != hex_str.end() ) {
35 *out_pos |= from_hex( *i );
36 ++i;
37 }
38 ++out_pos;
39 }
40 return out_pos - (uint8_t*)out_data;
41 }
42 std::string to_hex( const std::vector<char>& data )
43 {
44 if( data.size() )
45 return to_hex( data.data(), data.size() );
46 return "";
47 }
48
49}
const mie::Vuint & r
Definition bn.cpp:28
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
Defines exception's used by fc.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
uint8_t from_hex(char c)
Definition hex.cpp:6
fc::string to_hex(const char *d, uint32_t s)
Definition hex.cpp:17
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
CK_ULONG d
char * s