@@ -5,6 +5,7 @@ from .key cimport *
55from .utils cimport _b, _u
66from .error import *
77from copy import copy
8+ from .ssl cimport ERR_clear_error
89
910__all__ = [
1011 ' KeyData' ,
@@ -117,6 +118,9 @@ cdef class Key(object):
117118 c_data, c_size, format, c_password, NULL , NULL )
118119
119120 if handle == NULL :
121+ # Clear the error stack generated from openssl
122+ ERR_clear_error()
123+
120124 raise ValueError (" failed to load key" )
121125
122126 # Construct and return a new instance.
@@ -139,6 +143,9 @@ cdef class Key(object):
139143 c_filename, format, c_password, NULL , NULL )
140144
141145 if handle == NULL :
146+ # Clear the error stack generated from openssl
147+ ERR_clear_error()
148+
142149 raise ValueError (" failed to load key from '%s '" % filename)
143150
144151 # Construct and return a new instance.
@@ -159,7 +166,10 @@ cdef class Key(object):
159166 handle = xmlSecKeyGenerate(data_id, size, type )
160167
161168 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" )
163173
164174 # Construct and return a new instance.
165175 instance = cls ()
@@ -180,7 +190,10 @@ cdef class Key(object):
180190 handle = xmlSecKeyReadBinaryFile(data_id, c_filename)
181191
182192 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)
184197
185198 # Construct and return a new instance.
186199 instance = cls ()
@@ -203,6 +216,9 @@ cdef class Key(object):
203216 self ._handle, c_data, c_size, format)
204217
205218 if rv != 0 :
219+ # Clear the error stack generated from openssl
220+ ERR_clear_error()
221+
206222 raise ValueError (' Failed to load the certificate from the I/O stream.' )
207223
208224 def load_cert_from_file (self , filename , xmlSecKeyDataFormat format ):
@@ -214,6 +230,9 @@ cdef class Key(object):
214230 rv = xmlSecOpenSSLAppKeyCertLoad(self ._handle, c_filename, format)
215231
216232 if rv != 0 :
233+ # Clear the error stack generated from openssl
234+ ERR_clear_error()
235+
217236 raise ValueError (' Failed to load the certificate from the file.' )
218237
219238 property name :
0 commit comments