Panda3D

encryptStream.I
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.I
10 * @author drose
11 * @date 2004-09-01
12 */
13
14 /**
15 *
16 */
17 INLINE IDecryptStream::
18 IDecryptStream() : std::istream(&_buf) {
19 }
20
21 /**
22 *
23 */
24 INLINE IDecryptStream::
25 IDecryptStream(std::istream *source, bool owns_source,
26 const std::string &password) : std::istream(&_buf) {
27 open(source, owns_source, password);
28 }
29
30 /**
31 *
32 */
33 INLINE IDecryptStream &IDecryptStream::
34 open(std::istream *source, bool owns_source, const std::string &password) {
35 clear((ios_iostate)0);
36 _buf.open_read(source, owns_source, password);
37 return *this;
38 }
39
40 /**
41 * Resets the EncryptStream to empty, but does not actually close the source
42 * istream unless owns_source was true.
43 */
44 INLINE IDecryptStream &IDecryptStream::
45 close() {
46 _buf.close_read();
47 return *this;
48 }
49
50 /**
51 * Returns the encryption algorithm that was read from the stream.
52 */
53 INLINE const std::string &IDecryptStream::
54 get_algorithm() const {
55 return _buf.get_algorithm();
56 }
57
58 /**
59 * Returns the encryption key length, in bits, that was read from the stream.
60 */
61 INLINE int IDecryptStream::
62 get_key_length() const {
63 return _buf.get_key_length();
64 }
65
66 /**
67 * Returns the value that was was read from the stream.
68 */
69 INLINE int IDecryptStream::
70 get_iteration_count() const {
71 return _buf.get_iteration_count();
72 }
73
74
75 /**
76 *
77 */
78 INLINE OEncryptStream::
79 OEncryptStream() : std::ostream(&_buf) {
80 }
81
82 /**
83 *
84 */
85 INLINE OEncryptStream::
86 OEncryptStream(std::ostream *dest, bool owns_dest, const std::string &password) :
87 std::ostream(&_buf)
88 {
89 open(dest, owns_dest, password);
90 }
91
92 /**
93 *
94 */
95 INLINE OEncryptStream &OEncryptStream::
96 open(std::ostream *dest, bool owns_dest, const std::string &password) {
97 clear((ios_iostate)0);
98 _buf.open_write(dest, owns_dest, password);
99 return *this;
100 }
101
102 /**
103 * Resets the EncryptStream to empty, but does not actually close the dest
104 * ostream unless owns_dest was true.
105 */
106 INLINE OEncryptStream &OEncryptStream::
107 close() {
108 _buf.close_write();
109 return *this;
110 }
111
112 /**
113 * Returns the encryption algorithm that was read from the stream.
114 */
115 INLINE const std::string &OEncryptStream::
116 get_algorithm() const {
117 return _buf.get_algorithm();
118 }
119
120 /**
121 * Returns the encryption key length, in bits, that was read from the stream.
122 */
123 INLINE int OEncryptStream::
124 get_key_length() const {
125 return _buf.get_key_length();
126 }
127
128 /**
129 * Returns the value that was was read from the stream.
130 */
131 INLINE int OEncryptStream::
132 get_iteration_count() const {
133 return _buf.get_iteration_count();
134 }
135
136 /**
137 * Specifies the encryption algorithm that should be used for future calls to
138 * open(). The default is whatever is specified by the encryption-algorithm
139 * config variable. The complete set of available algorithms is defined by
140 * the current version of OpenSSL.
141 *
142 * If an invalid algorithm is specified, there is no immediate error return
143 * code, but open() will fail.
144 */
145 INLINE void OEncryptStream::
146 set_algorithm(const std::string &algorithm) {
147 _buf.set_algorithm(algorithm);
148 }
149
150 /**
151 * Specifies the length of the key, in bits, that should be used to encrypt
152 * the stream in future calls to open(). The default is whatever is specified
153 * by the encryption-key-length config variable.
154 *
155 * If an invalid key_length for the chosen algorithm is specified, there is no
156 * immediate error return code, but open() will fail.
157 */
158 INLINE void OEncryptStream::
159 set_key_length(int key_length) {
160 _buf.set_key_length(key_length);
161 }
162
163 /**
164 * Specifies the number of times to repeatedly hash the key before writing it
165 * to the stream in future calls to open(). Its purpose is to make it
166 * computationally more expensive for an attacker to search the key space
167 * exhaustively. This should be a multiple of 1,000 and should not exceed
168 * about 65 million; the value 0 indicates just one application of the hashing
169 * algorithm.
170 *
171 * The default is whatever is specified by the encryption-iteration-count
172 * config variable.
173 */
174 INLINE void OEncryptStream::
175 set_iteration_count(int iteration_count) {
176 _buf.set_iteration_count(iteration_count);
177 }