BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
sha512.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <boost/endian/buffers.hpp>
3 #include <fc/io/raw_fwd.hpp>
4 #include <fc/fwd.hpp>
5 
6 namespace fc
7 {
8 
9 class sha512
10 {
11  public:
12  sha512();
13  explicit sha512( const std::string& hex_str );
14 
15  std::string str()const;
16  operator std::string()const;
17 
18  char* data()const;
19  static constexpr size_t data_size() { return 512 / 8; }
20 
21  static sha512 hash( const char* d, uint32_t dlen );
22  static sha512 hash( const std::string& );
23 
24  template<typename T>
25  static sha512 hash( const T& t )
26  {
27  sha512::encoder e;
28  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  sha512 result();
42 
43  private:
44  struct impl;
46  };
47 
48  template<typename T>
49  inline friend T& operator<<( T& ds, const sha512& ep ) {
50  ds.write( ep.data(), sizeof(ep) );
51  return ds;
52  }
53 
54  template<typename T>
55  inline friend T& operator>>( T& ds, sha512& ep ) {
56  ds.read( ep.data(), sizeof(ep) );
57  return ds;
58  }
59  friend sha512 operator << ( const sha512& h1, uint32_t i );
60  friend bool operator == ( const sha512& h1, const sha512& h2 );
61  friend bool operator != ( const sha512& h1, const sha512& h2 );
62  friend sha512 operator ^ ( const sha512& h1, const sha512& h2 );
63  friend bool operator >= ( const sha512& h1, const sha512& h2 );
64  friend bool operator > ( const sha512& h1, const sha512& h2 );
65  friend bool operator < ( const sha512& h1, const sha512& h2 );
66 
67  boost::endian::little_uint64_buf_t _hash[8];
68 };
69 
70 namespace raw {
71 
72  template<typename T>
73  inline void pack( T& ds, const sha512& ep, uint32_t _max_depth ) {
74  ds << ep;
75  }
76 
77  template<typename T>
78  inline void unpack( T& ds, sha512& ep, uint32_t _max_depth ) {
79  ds >> ep;
80  }
81 
82 }
83 
85 
86  class variant;
87  void to_variant( const sha512& bi, variant& v, uint32_t max_depth );
88  void from_variant( const variant& v, sha512& bi, uint32_t max_depth );
89 
90 } // fc
91 
92 #include <fc/reflect/reflect.hpp>
fc::sha512::str
std::string str() const
Definition: sha512.cpp:17
fc::sha512::operator==
friend bool operator==(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:84
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
fc::sha512::sha512
sha512()
Definition: sha512.cpp:12
fwd.hpp
fc
Definition: api.hpp:15
fc::sha512::operator<
friend bool operator<(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:78
fc::sha512::encoder
Definition: sha512.hpp:32
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::sha512
Definition: sha512.hpp:9
fc::sha512::encoder::reset
void reset()
Definition: sha512.cpp:51
fc::sha512::encoder::put
void put(char c)
Definition: sha512.hpp:39
fc::sha512::hash
static sha512 hash(const char *d, uint32_t dlen)
Definition: sha512.cpp:34
fc::sha512::operator!=
friend bool operator!=(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:81
fc::sha512::data
char * data() const
Definition: sha512.cpp:22
fc::sha512::operator>>
friend T & operator>>(T &ds, sha512 &ep)
Definition: sha512.hpp:55
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::sha512::hash
static sha512 hash(const T &t)
Definition: sha512.hpp:25
fc::sha512::operator>
friend bool operator>(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:75
fc::sha512::operator<<
friend T & operator<<(T &ds, const sha512 &ep)
Definition: sha512.hpp:49
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
fc::sha512::encoder::~encoder
~encoder()
Definition: sha512.cpp:29
fc::sha512::encoder::encoder
encoder()
Definition: sha512.cpp:30
raw_fwd.hpp
fc::sha512::encoder::result
sha512 result()
Definition: sha512.cpp:46
fc::sha512::_hash
boost::endian::little_uint64_buf_t _hash[8]
Definition: sha512.hpp:67
fc::uint512
fc::sha512 uint512
Definition: sha512.hpp:84
fc::sha512::operator>=
friend bool operator>=(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:72
fc::sha512::operator^
friend sha512 operator^(const sha512 &h1, const sha512 &h2)
Definition: sha512.cpp:60
fc::fwd
Used to forward declare value types.
Definition: fwd.hpp:10
fc::sha512::data_size
static constexpr size_t data_size()
Definition: sha512.hpp:19
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
fc::sha512::encoder::write
void write(const char *d, uint32_t dlen)
Definition: sha512.cpp:43