@@ -5,6 +5,7 @@ from .key cimport *
5
5
from .utils cimport _b, _u
6
6
from .error import *
7
7
from copy import copy
8
+ from .ssl cimport ERR_clear_error
8
9
9
10
__all__ = [
10
11
' KeyData' ,
@@ -117,6 +118,9 @@ cdef class Key(object):
117
118
c_data, c_size, format, c_password, NULL , NULL )
118
119
119
120
if handle == NULL :
121
+ # Clear the error stack generated from openssl
122
+ ERR_clear_error()
123
+
120
124
raise ValueError (" failed to load key" )
121
125
122
126
# Construct and return a new instance.
@@ -139,6 +143,9 @@ cdef class Key(object):
139
143
c_filename, format, c_password, NULL , NULL )
140
144
141
145
if handle == NULL :
146
+ # Clear the error stack generated from openssl
147
+ ERR_clear_error()
148
+
142
149
raise ValueError (" failed to load key from '%s '" % filename)
143
150
144
151
# Construct and return a new instance.
@@ -159,7 +166,10 @@ cdef class Key(object):
159
166
handle = xmlSecKeyGenerate(data_id, size, type )
160
167
161
168
if handle == NULL :
162
- raise ValueError (" failed to generate key" )
169
+ # Clear the error stack generated from openssl
170
+ ERR_clear_error()
171
+
172
+ raise ValueError (" failed to generate key" )
163
173
164
174
# Construct and return a new instance.
165
175
instance = cls ()
@@ -180,7 +190,10 @@ cdef class Key(object):
180
190
handle = xmlSecKeyReadBinaryFile(data_id, c_filename)
181
191
182
192
if handle == NULL :
183
- raise ValueError (" failed to load from '%s '" % filename)
193
+ # Clear the error stack generated from openssl
194
+ ERR_clear_error()
195
+
196
+ raise ValueError (" failed to load from '%s '" % filename)
184
197
185
198
# Construct and return a new instance.
186
199
instance = cls ()
@@ -203,6 +216,9 @@ cdef class Key(object):
203
216
self ._handle, c_data, c_size, format)
204
217
205
218
if rv != 0 :
219
+ # Clear the error stack generated from openssl
220
+ ERR_clear_error()
221
+
206
222
raise ValueError (' Failed to load the certificate from the I/O stream.' )
207
223
208
224
def load_cert_from_file (self , filename , xmlSecKeyDataFormat format ):
@@ -214,6 +230,9 @@ cdef class Key(object):
214
230
rv = xmlSecOpenSSLAppKeyCertLoad(self ._handle, c_filename, format)
215
231
216
232
if rv != 0 :
233
+ # Clear the error stack generated from openssl
234
+ ERR_clear_error()
235
+
217
236
raise ValueError (' Failed to load the certificate from the file.' )
218
237
219
238
property name :
0 commit comments