IBR-DTNSuite  0.8
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:
00020                 typedef std::char_traits<char> traits;
00021 
00023                 static const size_t BUFF_SIZE = 2048;
00024 
00032                 RSASHA256Stream(EVP_PKEY * const pkey, bool verfiy = false);
00033 
00035                 virtual ~RSASHA256Stream();
00036 
00041                 void reset();
00042 
00050                 const std::pair<const int, const std::string> getSign();
00051 
00057                 int getVerification(const std::string& their_sign);
00058 
00059         protected:
00065                 virtual int sync();
00066 
00073                 virtual traits::int_type overflow(traits::int_type = traits::eof());
00074 
00075         private:
00077                 char *out_buf_;
00078 
00080                 EVP_PKEY * const _pkey;
00081 
00083                 const bool _verify;
00084 
00087                 EVP_MD_CTX _ctx;
00088 
00091                 bool _sign_valid;
00094                 int _return_code;
00097                 std::string _sign;
00098         };
00099 }
00100 #endif /* RSASHA256STREAM_H_ */