IBR-DTNSuite  0.10
InputCipherStream.h
Go to the documentation of this file.
1 /*
2  * InputCipherStream.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 INPUTCIPHERSTREAM_H_
23 #define INPUTCIPHERSTREAM_H_
24 
25 #include "ibrcommon/Exceptions.h"
26 #include <streambuf>
27 #include <iostream>
28 #include <vector>
29 
30 namespace ibrcommon
31 {
32  class InputCipherStream : public std::basic_streambuf<char, std::char_traits<char> >, public std::istream
33  {
34  public:
36  {
39  };
40 
41  InputCipherStream(std::istream &stream, const CipherMode mode = CIPHER_DECRYPT, const size_t buffer = 2048);
42  virtual ~InputCipherStream();
43 
44  protected:
45  virtual void encrypt(char *buf, const size_t size) = 0;
46  virtual void decrypt(char *buf, const size_t size) = 0;
47 
48  virtual int sync();
49  virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof());
50  virtual std::char_traits<char>::int_type underflow();
51 
52  private:
53  std::istream &_stream;
54 
55  CipherMode _mode;
56 
57  // Output buffer
58  std::vector<char> data_buf_;
59 
60  // length of the data buffer
61  size_t data_size_;
62  };
63 }
64 
65 #endif /* INPUTCIPHERSTREAM_H_ */