Panda3D
encryptStream.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 encryptStream.h
10  * @author drose
11  * @date 2004-09-01
12  */
13 
14 #ifndef ENCRYPTSTREAM_H
15 #define ENCRYPTSTREAM_H
16 
17 #include "dtoolbase.h"
18 
19 // This module is not compiled if OpenSSL is not available.
20 #ifdef HAVE_OPENSSL
21 
22 #include "encryptStreamBuf.h"
23 
24 /**
25  * An input stream object that uses OpenSSL to decrypt the input from another
26  * source stream on-the-fly.
27  *
28  * Attach an IDecryptStream to an existing istream that provides encrypted
29  * data, as generated by an OEncryptStream, and read the corresponding
30  * unencrypted data from the IDecryptStream.
31  *
32  * Seeking is not supported.
33  */
34 class EXPCL_DTOOL_PRC IDecryptStream : public std::istream {
35 PUBLISHED:
36  INLINE IDecryptStream();
37  INLINE explicit IDecryptStream(std::istream *source, bool owns_source,
38  const std::string &password);
39 
40 #if _MSC_VER >= 1800
41  INLINE IDecryptStream(const IDecryptStream &copy) = delete;
42 #endif
43 
44  INLINE IDecryptStream &open(std::istream *source, bool owns_source,
45  const std::string &password);
46  INLINE IDecryptStream &close();
47 
48  INLINE const std::string &get_algorithm() const;
49  INLINE int get_key_length() const;
50  INLINE int get_iteration_count() const;
51 
52  MAKE_PROPERTY(algorithm, get_algorithm);
53  MAKE_PROPERTY(key_length, get_key_length);
54  MAKE_PROPERTY(iteration_count, get_iteration_count);
55 
56 private:
57  EncryptStreamBuf _buf;
58 };
59 
60 /**
61  * An input stream object that uses OpenSSL to encrypt data to another
62  * destination stream on-the-fly.
63  *
64  * Attach an OEncryptStream to an existing ostream that will accept encrypted
65  * data, and write your unencrypted source data to the OEncryptStream.
66  *
67  * Seeking is not supported.
68  */
69 class EXPCL_DTOOL_PRC OEncryptStream : public std::ostream {
70 PUBLISHED:
71  INLINE OEncryptStream();
72  INLINE explicit OEncryptStream(std::ostream *dest, bool owns_dest,
73  const std::string &password);
74 
75 #if _MSC_VER >= 1800
76  INLINE OEncryptStream(const OEncryptStream &copy) = delete;
77 #endif
78 
79  INLINE OEncryptStream &open(std::ostream *dest, bool owns_dest,
80  const std::string &password);
81  INLINE OEncryptStream &close();
82 
83 public:
84  INLINE const std::string &get_algorithm() const;
85  INLINE int get_key_length() const;
86  INLINE int get_iteration_count() const;
87 
88 PUBLISHED:
89  INLINE void set_algorithm(const std::string &algorithm);
90  INLINE void set_key_length(int key_length);
91  INLINE void set_iteration_count(int iteration_count);
92 
93  MAKE_PROPERTY(algorithm, get_algorithm, set_algorithm);
94  MAKE_PROPERTY(key_length, get_key_length, set_key_length);
95  MAKE_PROPERTY(iteration_count, get_iteration_count, set_iteration_count);
96 
97 private:
98  EncryptStreamBuf _buf;
99 };
100 
101 #include "encryptStream.I"
102 
103 #endif // HAVE_OPENSSL
104 
105 
106 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.