@@ -34,10 +34,10 @@ static PyObject* PyXmlSec_SignatureContext__new__(PyTypeObject *type, PyObject *
3434
3535static int PyXmlSec_SignatureContext__init__ (PyObject * self , PyObject * args , PyObject * kwargs ) {
3636 static char * kwlist [] = { "manager" , NULL };
37-
37+ PyXmlSec_SignatureContext * ctx = ( PyXmlSec_SignatureContext * ) self ;
3838 PyXmlSec_KeysManager * manager = NULL ;
39+
3940 PYXMLSEC_DEBUGF ("%p: init sign context" , self );
40- PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
4141 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|O&:__init__" , kwlist , PyXmlSec_KeysManagerConvert , & manager )) {
4242 goto ON_FAIL ;
4343 }
@@ -47,6 +47,7 @@ static int PyXmlSec_SignatureContext__init__(PyObject* self, PyObject* args, PyO
4747 goto ON_FAIL ;
4848 }
4949 ctx -> manager = manager ;
50+ PYXMLSEC_DEBUGF ("%p: signMethod: %p" , self , ctx -> handle -> signMethod );
5051 PYXMLSEC_DEBUGF ("%p: init sign context - ok, manager - %p" , self , manager );
5152 return 0 ;
5253ON_FAIL :
@@ -56,8 +57,8 @@ static int PyXmlSec_SignatureContext__init__(PyObject* self, PyObject* args, PyO
5657}
5758
5859static void PyXmlSec_SignatureContext__del__ (PyObject * self ) {
59- PYXMLSEC_DEBUGF ("%p: delete sign context" , self );
6060 PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
61+ PYXMLSEC_DEBUGF ("%p: delete sign context" , self );
6162 if (ctx -> handle != NULL ) {
6263 xmlSecDSigCtxDestroy (ctx -> handle );
6364 }
@@ -69,29 +70,33 @@ static void PyXmlSec_SignatureContext__del__(PyObject* self) {
6970static const char PyXmlSec_SignatureContextKey__doc__ [] = "Signature key.\n" ;
7071static PyObject * PyXmlSec_SignatureContextKeyGet (PyObject * self , void * closure ) {
7172 PyXmlSec_SignatureContext * ctx = ((PyXmlSec_SignatureContext * )self );
73+ PyXmlSec_Key * key ;
74+
7275 if (ctx -> handle -> signKey == NULL ) {
7376 Py_RETURN_NONE ;
7477 }
7578
76- PyXmlSec_Key * key = PyXmlSec_NewKey ();
79+ key = PyXmlSec_NewKey ();
7780 key -> handle = ctx -> handle -> signKey ;
7881 key -> is_own = 0 ;
7982 return (PyObject * )key ;
8083}
8184
8285static int PyXmlSec_SignatureContextKeySet (PyObject * self , PyObject * value , void * closure ) {
86+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
87+ PyXmlSec_Key * key ;
88+
8389 PYXMLSEC_DEBUGF ("%p, %p" , self , value );
8490 if (!PyObject_IsInstance (value , (PyObject * )PyXmlSec_KeyType )) {
8591 PyErr_SetString (PyExc_TypeError , "instance of *xmlsec.Key* expected." );
8692 return -1 ;
8793 }
88- PyXmlSec_Key * key = (PyXmlSec_Key * )value ;
94+ key = (PyXmlSec_Key * )value ;
8995 if (key -> handle == NULL ) {
9096 PyErr_SetString (PyExc_TypeError , "empty key." );
9197 return -1 ;
9298 }
9399
94- PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
95100 if (ctx -> handle -> signKey != NULL ) {
96101 xmlSecKeyDestroy (ctx -> handle -> signKey );
97102 }
@@ -117,7 +122,8 @@ static PyObject* PyXmlSec_SignatureContextRegisterId(PyObject* self, PyObject* a
117122 const char * id_ns = NULL ;
118123
119124 xmlChar * name = NULL ;
120- xmlAttrPtr attr = NULL ;
125+ xmlAttrPtr attr ;
126+ xmlAttrPtr tmpAttr ;
121127
122128 PYXMLSEC_DEBUGF ("%p: register id - start" , self );
123129 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&|sz:register_id" , kwlist ,
@@ -138,7 +144,7 @@ static PyObject* PyXmlSec_SignatureContextRegisterId(PyObject* self, PyObject* a
138144 }
139145
140146 name = xmlNodeListGetString (node -> _c_node -> doc , attr -> children , 1 );
141- xmlAttrPtr tmpAttr = xmlGetID (node -> _c_node -> doc , name );
147+ tmpAttr = xmlGetID (node -> _c_node -> doc , name );
142148 if (tmpAttr != attr ) {
143149 if (tmpAttr != NULL ) {
144150 PyErr_SetString (PyXmlSec_Error , "duplicated id." );
@@ -165,18 +171,18 @@ static const char PyXmlSec_SignatureContextSign__doc__[] = \
165171static PyObject * PyXmlSec_SignatureContextSign (PyObject * self , PyObject * args , PyObject * kwargs ) {
166172 static char * kwlist [] = { "node" , NULL };
167173
174+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
168175 PyXmlSec_LxmlElementPtr node = NULL ;
176+ int rv ;
169177
170178 PYXMLSEC_DEBUGF ("%p: sign - start" , self );
171179 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&:sign" , kwlist , PyXmlSec_LxmlElementConverter , & node )) {
172180 goto ON_FAIL ;
173181 }
174182
175- xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext * )self )-> handle ;
176- int rv ;
177183 Py_BEGIN_ALLOW_THREADS ;
178- rv = xmlSecDSigCtxSign (ctx , node -> _c_node );
179- PYXMLSEC_DUMP (xmlSecDSigCtxDebugDump , ctx );
184+ rv = xmlSecDSigCtxSign (ctx -> handle , node -> _c_node );
185+ PYXMLSEC_DUMP (xmlSecDSigCtxDebugDump , ctx -> handle );
180186 Py_END_ALLOW_THREADS ;
181187 if (rv < 0 ) {
182188 PyXmlSec_SetLastError ("failed to sign" );
@@ -197,25 +203,25 @@ static const char PyXmlSec_SignatureContextVerify__doc__[] = \
197203static PyObject * PyXmlSec_SignatureContextVerify (PyObject * self , PyObject * args , PyObject * kwargs ) {
198204 static char * kwlist [] = { "node" , NULL };
199205
206+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
200207 PyXmlSec_LxmlElementPtr node = NULL ;
208+ int rv ;
201209
202210 PYXMLSEC_DEBUGF ("%p: verify - start" , self );
203211 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&:verify" , kwlist , PyXmlSec_LxmlElementConverter , & node )) {
204212 goto ON_FAIL ;
205213 }
206214
207- xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext * )self )-> handle ;
208- int rv ;
209215 Py_BEGIN_ALLOW_THREADS ;
210- rv = xmlSecDSigCtxVerify (ctx , node -> _c_node );
211- PYXMLSEC_DUMP (xmlSecDSigCtxDebugDump , ctx );
216+ rv = xmlSecDSigCtxVerify (ctx -> handle , node -> _c_node );
217+ PYXMLSEC_DUMP (xmlSecDSigCtxDebugDump , ctx -> handle );
212218 Py_END_ALLOW_THREADS ;
213219
214220 if (rv < 0 ) {
215221 PyXmlSec_SetLastError ("failed to verify" );
216222 goto ON_FAIL ;
217223 }
218- if (ctx -> status != xmlSecDSigStatusSucceeded ) {
224+ if (ctx -> handle -> status != xmlSecDSigStatusSucceeded ) {
219225 PyErr_SetString (PyXmlSec_VerificationError , "Signature is invalid." );
220226 goto ON_FAIL ;
221227 }
@@ -227,54 +233,55 @@ static PyObject* PyXmlSec_SignatureContextVerify(PyObject* self, PyObject* args,
227233}
228234
229235// common helper for operations binary_verify and binary_sign
230- static int PyXmlSec_ProcessSignBinary (xmlSecDSigCtxPtr ctx , const xmlSecByte * data , xmlSecSize data_size , xmlSecTransformId method ) {
236+ static int PyXmlSec_ProcessSignBinary (PyXmlSec_SignatureContext * ctx , const xmlSecByte * data , xmlSecSize data_size , xmlSecTransformId method ) {
237+ int rv ;
238+
231239 if (!(method -> usage & xmlSecTransformUsageSignatureMethod )) {
232240 PyErr_SetString (PyXmlSec_Error , "incompatible signature method" );
233241 return -1 ;
234242 }
235243
236- if (ctx -> signKey == NULL ) {
244+ if (ctx -> handle -> signKey == NULL ) {
237245 PyErr_SetString (PyXmlSec_Error , "Sign key is not specified." );
238246 }
239247
240- if (ctx -> signMethod != NULL ) {
248+ if (ctx -> handle -> signMethod != NULL ) {
249+ PYXMLSEC_DEBUGF ("%p: signMethod: %p" , ctx , ctx -> handle -> signMethod );
241250 PyErr_SetString (PyXmlSec_Error , "Signature context already used; it is designed for one use only." );
242251 return -1 ;
243252 }
244253
245- ctx -> signMethod = xmlSecTransformCtxCreateAndAppend (& (ctx -> transformCtx ), method );
246- if (ctx -> signMethod == NULL ) {
254+ ctx -> handle -> signMethod = xmlSecTransformCtxCreateAndAppend (& (ctx -> handle -> transformCtx ), method );
255+ if (ctx -> handle -> signMethod == NULL ) {
247256 PyXmlSec_SetLastError ("could not create signature transform." );
248257 return -1 ;
249258 }
250259
251- int rv ;
252-
253- ctx -> signMethod -> operation = ctx -> operation ;
254- xmlSecTransformSetKeyReq (ctx -> signMethod , & (ctx -> keyInfoReadCtx .keyReq ));
255- rv = xmlSecKeyMatch (ctx -> signKey , NULL , & (ctx -> keyInfoReadCtx .keyReq ));
260+ ctx -> handle -> signMethod -> operation = ctx -> handle -> operation ;
261+ xmlSecTransformSetKeyReq (ctx -> handle -> signMethod , & (ctx -> handle -> keyInfoReadCtx .keyReq ));
262+ rv = xmlSecKeyMatch (ctx -> handle -> signKey , NULL , & (ctx -> handle -> keyInfoReadCtx .keyReq ));
256263 if (rv != 1 ) {
257264 PyXmlSec_SetLastError ("inappropriate key type." );
258265 return -1 ;
259266 }
260267
261- rv = xmlSecTransformSetKey (ctx -> signMethod , ctx -> signKey );
268+ rv = xmlSecTransformSetKey (ctx -> handle -> signMethod , ctx -> handle -> signKey );
262269 if (rv < 0 ) {
263270 PyXmlSec_SetLastError ("cannot set key." );
264271 return -1 ;
265272 }
266- ctx -> transformCtx .result = NULL ;
267- ctx -> transformCtx .status = xmlSecTransformStatusNone ;
273+ ctx -> handle -> transformCtx .result = NULL ;
274+ ctx -> handle -> transformCtx .status = xmlSecTransformStatusNone ;
268275
269276 Py_BEGIN_ALLOW_THREADS ;
270- rv = xmlSecTransformCtxBinaryExecute (& (ctx -> transformCtx ), data , data_size );
277+ rv = xmlSecTransformCtxBinaryExecute (& (ctx -> handle -> transformCtx ), data , data_size );
271278 Py_END_ALLOW_THREADS ;
272279
273280 if (rv < 0 ) {
274281 PyXmlSec_SetLastError ("failed to transform." );
275282 return -1 ;
276283 }
277- ctx -> result = ctx -> transformCtx .result ;
284+ ctx -> handle -> result = ctx -> handle -> transformCtx .result ;
278285
279286 return 0 ;
280287}
@@ -286,7 +293,7 @@ static const char PyXmlSec_SignatureContextSignBinary__doc__[] = \
286293 ":return: the signature\n" ;
287294static PyObject * PyXmlSec_SignatureContextSignBinary (PyObject * self , PyObject * args , PyObject * kwargs ) {
288295 static char * kwlist [] = { "bytes" , "transform" , NULL };
289-
296+ PyXmlSec_SignatureContext * ctx = ( PyXmlSec_SignatureContext * ) self ;
290297 PyXmlSec_Transform * transform = NULL ;
291298 const char * data = NULL ;
292299 Py_ssize_t data_size = 0 ;
@@ -298,16 +305,16 @@ static PyObject* PyXmlSec_SignatureContextSignBinary(PyObject* self, PyObject* a
298305 goto ON_FAIL ;
299306 }
300307
301- xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext * )self )-> handle ;
302- ctx -> operation = xmlSecTransformOperationSign ;
308+ ctx -> handle -> operation = xmlSecTransformOperationSign ;
303309
304310 if (PyXmlSec_ProcessSignBinary (ctx , (const xmlSecByte * )data , (xmlSecSize )data_size , transform -> id ) != 0 ) {
305311 goto ON_FAIL ;
306312 }
307313
308314 PYXMLSEC_DEBUGF ("%p: sign_binary - ok" , self );
309315 return PyBytes_FromStringAndSize (
310- (const char * )xmlSecBufferGetData (ctx -> result ), (Py_ssize_t )xmlSecBufferGetSize (ctx -> result )
316+ (const char * )xmlSecBufferGetData (ctx -> handle -> result ),
317+ (Py_ssize_t )xmlSecBufferGetSize (ctx -> handle -> result )
311318 );
312319ON_FAIL :
313320 PYXMLSEC_DEBUGF ("%p: sign_binary - fail" , self );
@@ -323,11 +330,13 @@ static const char PyXmlSec_SignatureContextVerifyBinary__doc__[] = \
323330static PyObject * PyXmlSec_SignatureContextVerifyBinary (PyObject * self , PyObject * args , PyObject * kwargs ) {
324331 static char * kwlist [] = { "bytes" , "transform" , "signature" , NULL };
325332
333+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
326334 PyXmlSec_Transform * transform = NULL ;
327335 const char * data = NULL ;
328336 Py_ssize_t data_size = 0 ;
329337 const char * sign = NULL ;
330338 Py_ssize_t sign_size = 0 ;
339+ int rv ;
331340
332341 PYXMLSEC_DEBUGF ("%p: verify binary - start" , self );
333342 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "s#O!s#:verify_binary" , kwlist ,
@@ -336,23 +345,21 @@ static PyObject* PyXmlSec_SignatureContextVerifyBinary(PyObject* self, PyObject*
336345 goto ON_FAIL ;
337346 }
338347
339- xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext * )self )-> handle ;
340- ctx -> operation = xmlSecTransformOperationVerify ;
348+ ctx -> handle -> operation = xmlSecTransformOperationVerify ;
341349 if (PyXmlSec_ProcessSignBinary (ctx , (const xmlSecByte * )data , (xmlSecSize )data_size , transform -> id ) != 0 ) {
342350 goto ON_FAIL ;
343351 }
344352
345- int rv ;
346353 Py_BEGIN_ALLOW_THREADS ;
347- rv = xmlSecTransformVerify (ctx -> signMethod , (const xmlSecByte * )sign , (xmlSecSize )sign_size , & (ctx -> transformCtx ));
354+ rv = xmlSecTransformVerify (ctx -> handle -> signMethod , (const xmlSecByte * )sign , (xmlSecSize )sign_size , & (ctx -> handle -> transformCtx ));
348355 Py_END_ALLOW_THREADS ;
349356
350357 if (rv < 0 ) {
351358 PyXmlSec_SetLastError2 (PyXmlSec_VerificationError , "Cannot verify signature." );
352359 goto ON_FAIL ;
353360 }
354361
355- if (ctx -> signMethod -> status != xmlSecTransformStatusOk ) {
362+ if (ctx -> handle -> signMethod -> status != xmlSecTransformStatusOk ) {
356363 PyXmlSec_SetLastError2 (PyXmlSec_VerificationError , "Signature is invalid." );
357364 goto ON_FAIL ;
358365 }
@@ -372,17 +379,18 @@ static const char PyXmlSec_SignatureContextEnableReferenceTransform__doc__[] = \
372379static PyObject * PyXmlSec_SignatureContextEnableReferenceTransform (PyObject * self , PyObject * args , PyObject * kwargs ) {
373380 static char * kwlist [] = { "transform" , NULL };
374381
382+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
375383 PyXmlSec_Transform * transform = NULL ;
384+ int rv ;
376385
377386 PYXMLSEC_DEBUGF ("%p: enable_reference_transform - start" , self );
378387 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O!:enable_reference_transform" , kwlist , PyXmlSec_TransformType , & transform ))
379388 {
380389 goto ON_FAIL ;
381390 }
382391
383- int rv ;
384392 Py_BEGIN_ALLOW_THREADS ;
385- rv = xmlSecDSigCtxEnableReferenceTransform ((( PyXmlSec_SignatureContext * ) self ) -> handle , transform -> id );
393+ rv = xmlSecDSigCtxEnableReferenceTransform (ctx -> handle , transform -> id );
386394 Py_END_ALLOW_THREADS ;
387395
388396 if (rv < 0 ) {
@@ -405,16 +413,17 @@ static const char PyXmlSec_SignatureContextEnableSignatureTransform__doc__[] = \
405413static PyObject * PyXmlSec_SignatureContextEnableSignatureTransform (PyObject * self , PyObject * args , PyObject * kwargs ) {
406414 static char * kwlist [] = { "transform" , NULL };
407415
416+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
408417 PyXmlSec_Transform * transform = NULL ;
418+ int rv ;
409419
410420 PYXMLSEC_DEBUGF ("%p: enable_signature_transform - start" , self );
411421 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O!:enable_signature_transform" , kwlist , PyXmlSec_TransformType , & transform )) {
412422 goto ON_FAIL ;
413423 }
414424
415- int rv ;
416425 Py_BEGIN_ALLOW_THREADS ;
417- rv = xmlSecDSigCtxEnableSignatureTransform ((( PyXmlSec_SignatureContext * ) self ) -> handle , transform -> id );
426+ rv = xmlSecDSigCtxEnableSignatureTransform (ctx -> handle , transform -> id );
418427 Py_END_ALLOW_THREADS ;
419428
420429 if (rv < 0 ) {
@@ -435,17 +444,19 @@ static const char PyXmlSec_SignatureContextSetEnabledKeyData__doc__[] = \
435444static PyObject * PyXmlSec_SignatureContextSetEnabledKeyData (PyObject * self , PyObject * args , PyObject * kwargs ) {
436445 static char * kwlist [] = { "keydata_list" , NULL };
437446
447+ PyXmlSec_SignatureContext * ctx = (PyXmlSec_SignatureContext * )self ;
438448 PyObject * keydata_list = NULL ;
439449 PyObject * iter = NULL ;
440450 PyObject * item = NULL ;
451+ xmlSecPtrListPtr enabled_list ;
441452
442453 PYXMLSEC_DEBUGF ("%p: set_enabled_key_data - start" , self );
443454 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O:set_enabled_key_data" , kwlist , & keydata_list )) {
444455 goto ON_FAIL ;
445456 }
446457 if ((iter = PyObject_GetIter (keydata_list )) == NULL ) goto ON_FAIL ;
447458
448- xmlSecPtrListPtr enabled_list = & ((( PyXmlSec_SignatureContext * ) self ) -> handle -> keyInfoReadCtx .enabledKeyData );
459+ enabled_list = & (ctx -> handle -> keyInfoReadCtx .enabledKeyData );
449460 xmlSecPtrListEmpty (enabled_list );
450461
451462 while ((item = PyIter_Next (iter )) != NULL ) {
@@ -571,9 +582,9 @@ static PyTypeObject _PyXmlSec_SignatureContextType = {
571582 0 , /* tp_descr_set */
572583 0 , /* tp_dictoffset */
573584 PyXmlSec_SignatureContext__init__ , /* tp_init */
574- PyType_GenericAlloc , /* tp_alloc */
585+ 0 , /* tp_alloc */
575586 PyXmlSec_SignatureContext__new__ , /* tp_new */
576- PyObject_Del /* tp_free */
587+ 0 , /* tp_free */
577588};
578589
579590PyTypeObject * PyXmlSec_SignatureContextType = & _PyXmlSec_SignatureContextType ;
0 commit comments