BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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>
Used to forward declare value types.
Definition: fwd.hpp:10
friend bool operator!=(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:75
void put(char c)
Definition: sha224.hpp:39
friend T & operator>>(T &ds, sha224 &ep)
Definition: sha224.hpp:56
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
friend bool operator==(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:78
char * data() const
Definition: sha224.cpp:22
Defines types and macros used to provide reflection.
friend bool operator<(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:72
static sha224 hash(const char *d, uint32_t dlen)
Definition: sha224.cpp:34
boost::endian::little_uint32_buf_t _hash[7]
Definition: sha224.hpp:68
friend bool operator>(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:69
FC_REFLECT_TYPENAME(fc::log_message)
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
static sha224 hash(const T &t)
Definition: sha224.hpp:25
string str() const
Definition: sha224.cpp:17
friend sha224 operator^(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:60
size_t operator()(const fc::sha224 &s) const
Definition: sha224.hpp:95
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
friend T & operator<<(T &ds, const sha224 &ep)
Definition: sha224.hpp:49
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
void write(const char *d, uint32_t dlen)
Definition: sha224.cpp:43
Definition: api.hpp:15
void unpack(T &ds, sha224 &ep, uint32_t _max_depth)
Definition: sha224.hpp:79
friend bool operator>=(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:66
static constexpr size_t data_size()
Definition: sha224.hpp:19
sha224 result()
Definition: sha224.cpp:46
void pack(T &ds, const sha224 &ep, uint32_t _max_depth)
Definition: sha224.hpp:74