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