Panda3D

encryptStreamBuf.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file encryptStreamBuf.h
10 * @author drose
11 * @date 2004-09-01
12 */
13
14 #ifndef ENCRYPTSTREAMBUF_H
15 #define ENCRYPTSTREAMBUF_H
16
17 #include "dtoolbase.h"
18
19 // This module is not compiled if OpenSSL is not available.
20 #ifdef HAVE_OPENSSL
21
22 typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
23
24 /**
25 * The streambuf object that implements IDecompressStream and OCompressStream.
26 */
27 class EXPCL_DTOOL_PRC EncryptStreamBuf : public std::streambuf {
28 public:
29 EncryptStreamBuf();
30 virtual ~EncryptStreamBuf();
31
32 void open_read(std::istream *source, bool owns_source, const std::string &password);
33 void close_read();
34
35 void open_write(std::ostream *dest, bool owns_dest, const std::string &password);
36 void close_write();
37
38 INLINE void set_algorithm(const std::string &algorithm);
39 INLINE const std::string &get_algorithm() const;
40
41 INLINE void set_key_length(int key_length);
42 INLINE int get_key_length() const;
43
44 INLINE void set_iteration_count(int iteration_count);
45 INLINE int get_iteration_count() const;
46
47 protected:
48 virtual int overflow(int c);
49 virtual int sync();
50 virtual int underflow();
51
52 private:
53 size_t read_chars(char *start, size_t length);
54 void write_chars(const char *start, size_t length);
55
56 private:
57 std::istream *_source;
58 bool _owns_source;
59
60 std::ostream *_dest;
61 bool _owns_dest;
62
63 std::string _algorithm;
64 int _key_length;
65 int _iteration_count;
66
67 EVP_CIPHER_CTX *_read_ctx;
68 size_t _read_block_size;
69 unsigned char *_read_overflow_buffer;
70 size_t _in_read_overflow_buffer;
71
72 EVP_CIPHER_CTX *_write_ctx;
73 size_t _write_block_size;
74 };
75
76 #include "encryptStreamBuf.I"
77
78 #endif // HAVE_OPENSSL
79
80 #endif
dtoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
encryptStreamBuf.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.