@@ -24,7 +24,7 @@ typedef struct {
2424
2525static PyObject * PyXmlSec_EncryptionContext__new__ (PyTypeObject * type , PyObject * args , PyObject * kwargs ) {
2626 PyXmlSec_EncryptionContext * ctx = (PyXmlSec_EncryptionContext * )PyType_GenericNew (type , args , kwargs );
27- PYXMLSEC_DEBUGF ("%p: new sign context" , ctx );
27+ PYXMLSEC_DEBUGF ("%p: new enc context" , ctx );
2828 if (ctx != NULL ) {
2929 ctx -> handle = NULL ;
3030 ctx -> manager = NULL ;
@@ -37,24 +37,26 @@ static int PyXmlSec_EncryptionContext__init__(PyObject* self, PyObject* args, Py
3737
3838 PyXmlSec_KeysManager * manager = NULL ;
3939 PyXmlSec_EncryptionContext * ctx = (PyXmlSec_EncryptionContext * )self ;
40- PYXMLSEC_DEBUGF ("%p: init sign context" , self );
40+ PYXMLSEC_DEBUGF ("%p: init enc context" , self );
4141 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|O&:__init__" , kwlist , PyXmlSec_KeysManagerConvert , & manager )) {
42- return -1 ;
42+ goto ON_FAIL ;
4343 }
44-
45- PYXMLSEC_DEBUGF ("%p" , manager );
4644 ctx -> handle = xmlSecEncCtxCreate (manager != NULL ? manager -> handle : NULL );
4745 if (ctx -> handle == NULL ) {
48- PyXmlSec_SetLastError ("failed to create the digital signature context" );
49- return -1 ;
46+ PyXmlSec_SetLastError ("failed to create the encryption context" );
47+ goto ON_FAIL ;
5048 }
51- Py_XINCREF (manager );
5249 ctx -> manager = manager ;
50+ PYXMLSEC_DEBUGF ("%p: init enc context - ok, manager - %p" , self , manager );
5351 return 0 ;
52+ ON_FAIL :
53+ PYXMLSEC_DEBUGF ("%p: init enc context - failed" , self );
54+ Py_XDECREF (manager );
55+ return -1 ;
5456}
5557
5658static void PyXmlSec_EncryptionContext__del__ (PyObject * self ) {
57- PYXMLSEC_DEBUGF ("%p: delete sign context" , self );
59+ PYXMLSEC_DEBUGF ("%p: delete enc context" , self );
5860 PyXmlSec_EncryptionContext * ctx = (PyXmlSec_EncryptionContext * )self ;
5961 if (ctx -> handle != NULL ) {
6062 xmlSecEncCtxDestroy (ctx -> handle );
@@ -66,8 +68,13 @@ static void PyXmlSec_EncryptionContext__del__(PyObject* self) {
6668
6769static const char PyXmlSec_EncryptionContextKey__doc__ [] = "Encryption key.\n" ;
6870static PyObject * PyXmlSec_EncryptionContextKeyGet (PyObject * self , void * closure ) {
71+ PyXmlSec_EncryptionContext * ctx = ((PyXmlSec_EncryptionContext * )self );
72+ if (ctx -> handle -> encKey == NULL ) {
73+ Py_RETURN_NONE ;
74+ }
75+
6976 PyXmlSec_Key * key = PyXmlSec_NewKey ();
70- key -> handle = (( PyXmlSec_EncryptionContext * ) self ) -> handle -> encKey ;
77+ key -> handle = ctx -> handle -> encKey ;
7178 key -> is_own = 0 ;
7279 return (PyObject * )key ;
7380}
@@ -142,9 +149,10 @@ static void PyXmlSec_ClearReplacedNodes(xmlSecEncCtxPtr ctx, PyXmlSec_LxmlDocume
142149 xmlNodePtr n = ctx -> replacedNodeList ;
143150 xmlNodePtr nn ;
144151 while (n != NULL ) {
152+ PYXMLSEC_DEBUGF ("clear replaced node %p" , n );
145153 nn = n -> next ;
146154 // if n has references, it will not be deleted
147- Py_XDECREF (PyXmlSec_elementFactory (doc , n ));
155+ Py_DECREF (PyXmlSec_elementFactory (doc , n ));
148156 n = nn ;
149157 }
150158 ctx -> replacedNodeList = NULL ;
@@ -290,7 +298,7 @@ static PyObject* PyXmlSec_EncryptionContextDecrypt(PyObject* self, PyObject* arg
290298 }
291299
292300 xmlNodePtr xparent = node -> _c_node -> parent ;
293- if (xparent != NULL && !_isElement (xparent )) {
301+ if (xparent != NULL && !PyXmlSec_IsElement (xparent )) {
294302 xparent = NULL ;
295303 }
296304
@@ -323,7 +331,7 @@ static PyObject* PyXmlSec_EncryptionContextDecrypt(PyObject* self, PyObject* arg
323331 if (!ctx -> resultReplaced ) {
324332 Py_XDECREF (node_num );
325333 Py_XDECREF (parent );
326- PYXMLSEC_DEBUGF ("%p: decrypt - ok" , self );
334+ PYXMLSEC_DEBUGF ("%p: binary. decrypt - ok" , self );
327335 return PyBytes_FromStringAndSize (
328336 (const char * )xmlSecBufferGetData (ctx -> result ), (Py_ssize_t )xmlSecBufferGetSize (ctx -> result )
329337 );
@@ -341,7 +349,7 @@ static PyObject* PyXmlSec_EncryptionContextDecrypt(PyObject* self, PyObject* arg
341349 parent = tmp ;
342350 }
343351 Py_DECREF (node_num );
344- PYXMLSEC_DEBUGF ("%p: decrypt - ok" , self );
352+ PYXMLSEC_DEBUGF ("%p: parent. decrypt - ok" , self );
345353 return parent ;
346354 }
347355
0 commit comments