IBR-DTNSuite  0.10
RSASHA256Stream.h
Go to the documentation of this file.
1 /*
2  * RSASHA256Stream.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef RSASHA256STREAM_H_
23 #define RSASHA256STREAM_H_
24 
25 #include "ibrcommon/Exceptions.h"
26 #include <openssl/evp.h>
27 #include <streambuf>
28 #include <iostream>
29 #include <vector>
30 
31 namespace ibrcommon
32 {
39  class RSASHA256Stream : public std::basic_streambuf<char, std::char_traits<char> >, public std::ostream
40  {
41  public:
42  typedef std::char_traits<char> traits;
43 
45  static const size_t BUFF_SIZE = 2048;
46 
54  RSASHA256Stream(EVP_PKEY * const pkey, bool verfiy = false);
55 
57  virtual ~RSASHA256Stream();
58 
63  void reset();
64 
72  const std::pair<const int, const std::string> getSign();
73 
79  int getVerification(const std::string& their_sign);
80 
81  protected:
87  virtual int sync();
88 
95  virtual traits::int_type overflow(traits::int_type = traits::eof());
96 
97  private:
99  std::vector<char> out_buf_;
100 
102  EVP_PKEY * const _pkey;
103 
105  const bool _verify;
106 
109  EVP_MD_CTX _ctx;
110 
113  bool _sign_valid;
116  int _return_code;
119  std::string _sign;
120  };
121 }
122 #endif /* RSASHA256STREAM_H_ */