peerplays-fc/include/fc/sha1.hpp
Daniel Larimer 3d56a96d4e major updates to stream,reflect,value,and json
- removed polymorphic reflection, made static_reflect default because
  there are cases such as deserializing an array that you need more
  information than the runtime reflection can provide such as the
  ability to resize arrays and know the array content type.

- refactored iostream, sstream, fstream to be much simpler, fewer
  indirections, and fixed getline.

- json parsing works using code from mace.
- value is reimplemented based upon mace::rpc::value and no longer uses
  the runtime reflection that was removed.

- moved the typename utility to its own header
2012-10-21 02:28:59 -04:00

64 lines
1.6 KiB
C++

#pragma once
#include <fc/fwd.hpp>
#include <fc/string.hpp>
#include <fc/reflect.hpp>
namespace fc {
class sha1 {
public:
sha1();
explicit sha1( const fc::string& hex_str );
fc::string str()const;
operator fc::string()const;
char* data()const;
static sha1 hash( const char* d, uint32_t dlen );
static sha1 hash( const fc::string& );
template<typename T>
static sha1 hash( const T& t ) { sha1::encoder e; e << t; return e.result(); }
class encoder {
public:
encoder();
~encoder();
void write( const char* d, uint32_t dlen );
void put( char c ) { write( &c, 1 ); }
void reset();
sha1 result();
private:
struct impl;
fwd<impl,89> my;
};
template<typename T>
inline friend T& operator<<( T& ds, const sha1& ep ) {
ds.write( ep.data(), sizeof(ep) );
return ds;
}
template<typename T>
inline friend T& operator>>( T& ds, sha1& ep ) {
ds.read( ep.data(), sizeof(ep) );
return ds;
}
friend sha1 operator << ( const sha1& h1, uint32_t i );
friend bool operator == ( const sha1& h1, const sha1& h2 );
friend bool operator != ( const sha1& h1, const sha1& h2 );
friend sha1 operator ^ ( const sha1& h1, const sha1& h2 );
friend bool operator >= ( const sha1& h1, const sha1& h2 );
friend bool operator > ( const sha1& h1, const sha1& h2 );
friend bool operator < ( const sha1& h1, const sha1& h2 );
uint32_t _hash[5];
};
}