Skip to content

Commit 55f670b

Browse files
committed
Add context dump in debug
1 parent 74331b1 commit 55f670b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/debug.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#include <stdio.h>
1616
#define PYXMLSEC_DEBUG(fmt) fprintf(stderr, "[%s:%d %s] " fmt "\n", __FILE__, __LINE__, __FUNCTION__)
1717
#define PYXMLSEC_DEBUGF(fmt, ...) fprintf(stderr, "[%s:%d %s] " fmt "\n", __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
18+
#define PYXMLSEC_DUMP(method, obj) method(obj, stderr)
1819
#else
1920
#define PYXMLSEC_DEBUG(...)
2021
#define PYXMLSEC_DEBUGF(...)
22+
#define PYXMLSEC_DUMP(method, obj)
2123
#endif // PYXMLSEC_ENABLE_DEBUG
2224

2325
#endif // __PYXMLSEC_DEBUG_H__

src/ds.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ static PyObject* PyXmlSec_SignatureContextSign(PyObject* self, PyObject* args, P
172172
goto ON_FAIL;
173173
}
174174

175+
xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext*)self)->handle;
175176
int rv;
176177
Py_BEGIN_ALLOW_THREADS;
177-
rv = xmlSecDSigCtxSign(((PyXmlSec_SignatureContext*)self)->handle, node->_c_node);
178+
rv = xmlSecDSigCtxSign(ctx, node->_c_node);
179+
PYXMLSEC_DUMP(xmlSecDSigCtxDebugDump, ctx);
178180
Py_END_ALLOW_THREADS;
179181
if (rv < 0) {
180182
PyXmlSec_SetLastError("failed to sign");
@@ -202,17 +204,18 @@ static PyObject* PyXmlSec_SignatureContextVerify(PyObject* self, PyObject* args,
202204
goto ON_FAIL;
203205
}
204206

205-
xmlSecDSigCtxPtr handle = ((PyXmlSec_SignatureContext*)self)->handle;
207+
xmlSecDSigCtxPtr ctx = ((PyXmlSec_SignatureContext*)self)->handle;
206208
int rv;
207209
Py_BEGIN_ALLOW_THREADS;
208-
rv = xmlSecDSigCtxVerify(handle, node->_c_node);
210+
rv = xmlSecDSigCtxVerify(ctx, node->_c_node);
211+
PYXMLSEC_DUMP(xmlSecDSigCtxDebugDump, ctx);
209212
Py_END_ALLOW_THREADS;
210213

211214
if (rv < 0) {
212215
PyXmlSec_SetLastError("failed to verify");
213216
goto ON_FAIL;
214217
}
215-
if (handle->status != xmlSecDSigStatusSucceeded) {
218+
if (ctx->status != xmlSecDSigStatusSucceeded) {
216219
PyErr_SetString(PyXmlSec_VerificationError, "Signature is invalid.");
217220
goto ON_FAIL;
218221
}

src/enc.c

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static PyObject* PyXmlSec_EncryptionContextReset(PyObject* self, PyObject* args,
113113
xmlSecEncCtxPtr ctx = ((PyXmlSec_EncryptionContext*)self)->handle;
114114
Py_BEGIN_ALLOW_THREADS;
115115
xmlSecEncCtxReset(ctx);
116+
PYXMLSEC_DUMP(xmlSecEncCtxDebugDump, ctx);
116117
Py_END_ALLOW_THREADS;
117118
PYXMLSEC_DEBUGF("%p: reset context - ok", self);
118119
Py_RETURN_NONE;
@@ -141,6 +142,7 @@ static PyObject* PyXmlSec_EncryptionContextEncryptBinary(PyObject* self, PyObjec
141142
int rv;
142143
Py_BEGIN_ALLOW_THREADS;
143144
rv = xmlSecEncCtxBinaryEncrypt(ctx, template->_c_node, (const xmlSecByte*)data, (xmlSecSize)data_size);
145+
PYXMLSEC_DUMP(xmlSecEncCtxDebugDump, ctx);
144146
Py_END_ALLOW_THREADS;
145147

146148
if (rv < 0) {
@@ -226,6 +228,7 @@ static PyObject* PyXmlSec_EncryptionContextEncryptXml(PyObject* self, PyObject*
226228
xnew_node = NULL;
227229
}
228230
}
231+
PYXMLSEC_DUMP(xmlSecEncCtxDebugDump, ctx);
229232
Py_END_ALLOW_THREADS;
230233

231234
PyXmlSec_ClearReplacedNodes(ctx, node->_doc);
@@ -268,6 +271,7 @@ static PyObject* PyXmlSec_EncryptionContextEncryptUri(PyObject* self, PyObject*
268271
int rv;
269272
Py_BEGIN_ALLOW_THREADS;
270273
rv = xmlSecEncCtxUriEncrypt(ctx, template->_c_node, (const xmlSecByte*)uri);
274+
PYXMLSEC_DUMP(xmlSecEncCtxDebugDump, ctx);
271275
Py_END_ALLOW_THREADS;
272276

273277
if (rv < 0) {
@@ -329,6 +333,7 @@ static PyObject* PyXmlSec_EncryptionContextDecrypt(PyObject* self, PyObject* arg
329333
ctx->mode = xmlSecCheckNodeName(node->_c_node, xmlSecNodeEncryptedKey, xmlSecEncNs) ? xmlEncCtxModeEncryptedKey : xmlEncCtxModeEncryptedData;
330334
PYXMLSEC_DEBUGF("mode: %d", ctx->mode);
331335
rv = xmlSecEncCtxDecrypt(ctx, node->_c_node);
336+
PYXMLSEC_DUMP(xmlSecEncCtxDebugDump, ctx);
332337
Py_END_ALLOW_THREADS;
333338

334339
PyXmlSec_ClearReplacedNodes(ctx, node->_doc);

0 commit comments

Comments
 (0)