IBR-DTNSuite 0.6

ibrcommon/ibrcommon/ssl/RSASHA256Stream.h

Go to the documentation of this file.
00001 #ifndef RSASHA256STREAM_H_
00002 #define RSASHA256STREAM_H_
00003 
00004 #include "ibrcommon/Exceptions.h"
00005 #include <openssl/evp.h>
00006 #include <streambuf>
00007 #include <iostream>
00008 
00009 namespace ibrcommon
00010 {
00017         class RSASHA256Stream : public std::basic_streambuf<char, std::char_traits<char> >, public std::ostream
00018         {
00019         public:
00021                 static const size_t BUFF_SIZE = 2048;
00022 
00030                 RSASHA256Stream(EVP_PKEY * const pkey, bool verfiy = false);
00031 
00033                 virtual ~RSASHA256Stream();
00034 
00039                 void reset();
00040 
00048                 const std::pair<const int, const std::string> getSign();
00049 
00055                 int getVerification(const std::string& their_sign);
00056 
00057         protected:
00063                 virtual int sync();
00064 
00071                 virtual int overflow(int = std::char_traits<char>::eof());
00072 
00073         private:
00075                 char *out_buf_;
00076 
00078                 EVP_PKEY * const _pkey;
00079 
00081                 const bool _verify;
00082 
00085                 EVP_MD_CTX _ctx;
00086 
00089                 bool _sign_valid;
00092                 int _return_code;
00095                 std::string _sign;
00096         };
00097 }
00098 #endif /* RSASHA256STREAM_H_ */