IBR-DTNSuite
0.8
|
00001 /* 00002 * HashStream.h 00003 * 00004 * Created on: 12.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef HASHSTREAM_H_ 00009 #define HASHSTREAM_H_ 00010 00011 #include "ibrcommon/Exceptions.h" 00012 #include <streambuf> 00013 #include <iostream> 00014 00015 namespace ibrcommon 00016 { 00017 class HashStream : public std::basic_streambuf<char, std::char_traits<char> >, public std::iostream 00018 { 00019 public: 00020 HashStream(const size_t hash, const size_t buffer = 2048); 00021 virtual ~HashStream(); 00022 00023 static std::string extract(std::istream &stream); 00024 00025 protected: 00026 virtual void update(char *buf, const size_t size) = 0; 00027 virtual void finalize(char * hash, unsigned int &size) = 0; 00028 00029 virtual int sync(); 00030 virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof()); 00031 virtual std::char_traits<char>::int_type underflow(); 00032 00033 private: 00034 // Output buffer 00035 char *data_buf_; 00036 00037 // length of the data buffer 00038 size_t data_size_; 00039 00040 // Input buffer (contains the hash after finalize) 00041 char *hash_buf_; 00042 00043 // length of the hash 00044 unsigned int hash_size_; 00045 00046 bool final_; 00047 }; 00048 } 00049 00050 #endif /* HASHSTREAM_H_ */