BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
ripemd160.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <boost/endian/buffers.hpp>
3 #include <fc/fwd.hpp>
4 #include <fc/io/raw_fwd.hpp>
6 
7 namespace fc{
8 class sha512;
9 class sha256;
10 
11 class ripemd160
12 {
13  public:
14  ripemd160();
15  explicit ripemd160( const string& hex_str );
16 
17  string str()const;
18  explicit operator string()const;
19 
20  char* data()const;
21  static constexpr size_t data_size() { return 160/8; }
22 
23  static ripemd160 hash( const fc::sha512& h );
24  static ripemd160 hash( const fc::sha256& h );
25  static ripemd160 hash( const char* d, uint32_t dlen );
26  static ripemd160 hash( const string& );
27 
28  template<typename T>
29  static ripemd160 hash( const T& t )
30  {
32  fc::raw::pack(e,t);
33  return e.result();
34  }
35 
36  class encoder
37  {
38  public:
39  encoder();
40  ~encoder();
41 
42  void write( const char* d, uint32_t dlen );
43  void put( char c ) { write( &c, 1 ); }
44  void reset();
45  ripemd160 result();
46 
47  private:
48  class impl;
50  };
51 
52  template<typename T>
53  inline friend T& operator<<( T& ds, const ripemd160& ep ) {
54  ds.write( ep.data(), sizeof(ep) );
55  return ds;
56  }
57 
58  template<typename T>
59  inline friend T& operator>>( T& ds, ripemd160& ep ) {
60  ds.read( ep.data(), sizeof(ep) );
61  return ds;
62  }
63  friend ripemd160 operator << ( const ripemd160& h1, uint32_t i );
64  friend bool operator == ( const ripemd160& h1, const ripemd160& h2 );
65  friend bool operator != ( const ripemd160& h1, const ripemd160& h2 );
66  friend ripemd160 operator ^ ( const ripemd160& h1, const ripemd160& h2 );
67  friend bool operator >= ( const ripemd160& h1, const ripemd160& h2 );
68  friend bool operator > ( const ripemd160& h1, const ripemd160& h2 );
69  friend bool operator < ( const ripemd160& h1, const ripemd160& h2 );
70 
71  boost::endian::little_uint32_buf_t _hash[5];
72 };
73 
74 namespace raw {
75 
76  template<typename T>
77  inline void pack( T& ds, const ripemd160& ep, uint32_t _max_depth ) {
78  ds << ep;
79  }
80 
81  template<typename T>
82  inline void unpack( T& ds, ripemd160& ep, uint32_t _max_depth ) {
83  ds >> ep;
84  }
85 
86 }
87 
88  class variant;
89  void to_variant( const ripemd160& bi, variant& v, uint32_t max_depth );
90  void from_variant( const variant& v, ripemd160& bi, uint32_t max_depth );
91 
93  typedef ripemd160 uint160;
94 
95  template<> struct get_typename<uint160_t> { static const char* name() { return "uint160_t"; } };
96 
97 } // namespace fc
98 
99 namespace std
100 {
101  template<>
102  struct hash<fc::ripemd160>
103  {
104  size_t operator()( const fc::ripemd160& s )const
105  {
106  return *((size_t*)&s);
107  }
108  };
109 }
fc::ripemd160::operator>>
friend T & operator>>(T &ds, ripemd160 &ep)
Definition: ripemd160.hpp:59
fc::ripemd160::encoder::write
void write(const char *d, uint32_t dlen)
Definition: ripemd160.cpp:60
fc::ripemd160::operator<<
friend T & operator<<(T &ds, const ripemd160 &ep)
Definition: ripemd160.hpp:53
fc::raw::unpack
void unpack(Stream &s, flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:23
fwd.hpp
fc
Definition: api.hpp:15
fc::ripemd160::encoder::reset
void reset()
Definition: ripemd160.cpp:68
fc::sha256
Definition: sha256.hpp:10
fc::get_typename< uint160_t >::name
static const char * name()
Definition: ripemd160.hpp:95
fc::ripemd160::data
char * data() const
Definition: ripemd160.cpp:26
fc::uint160_t
ripemd160 uint160_t
Definition: ripemd160.hpp:92
fc::ripemd160::ripemd160
ripemd160()
Definition: ripemd160.cpp:16
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::ripemd160::_hash
boost::endian::little_uint32_buf_t _hash[5]
Definition: ripemd160.hpp:71
fc::ripemd160::operator<
friend bool operator<(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:92
fc::sha512
Definition: sha512.hpp:9
fc::ripemd160::encoder::result
ripemd160 result()
Definition: ripemd160.cpp:63
fc::get_typename
Definition: typename.hpp:20
fc::ripemd160
Definition: ripemd160.hpp:11
fc::ripemd160::encoder
Definition: ripemd160.hpp:36
fc::ripemd160::str
string str() const
Definition: ripemd160.cpp:21
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::ripemd160::hash
static ripemd160 hash(const T &t)
Definition: ripemd160.hpp:29
fc::ripemd160::operator==
friend bool operator==(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:98
fc::ripemd160::operator>
friend bool operator>(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:89
fc::ripemd160::encoder::encoder
encoder()
Definition: ripemd160.cpp:39
fc::ripemd160::operator>=
friend bool operator>=(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:86
std
Definition: zeroed_array.hpp:76
fc::ripemd160::hash
static ripemd160 hash(const fc::sha512 &h)
Definition: ripemd160.cpp:43
fc::ripemd160::encoder::put
void put(char c)
Definition: ripemd160.hpp:43
fc::ripemd160::encoder::~encoder
~encoder()
Definition: ripemd160.cpp:38
raw_fwd.hpp
fc::uint160
ripemd160 uint160
Definition: ripemd160.hpp:93
std::hash< fc::ripemd160 >::operator()
size_t operator()(const fc::ripemd160 &s) const
Definition: ripemd160.hpp:104
fc::ripemd160::data_size
static constexpr size_t data_size()
Definition: ripemd160.hpp:21
fc::ripemd160::operator^
friend ripemd160 operator^(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:77
typename.hpp
fc::ripemd160::operator!=
friend bool operator!=(const ripemd160 &h1, const ripemd160 &h2)
Definition: ripemd160.cpp:95
fc::fwd
Used to forward declare value types.
Definition: fwd.hpp:10
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11