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