Skip to content

Commit e422bf5

Browse files
authored
Merge pull request #3 from gisce/fix_no_md5_compat
Multiple Patches to Work with newest distributions like Ubuntu 24.04
2 parents 9926890 + 63cc551 commit e422bf5

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

.github/workflows/install_test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: 'Check installable'
33
on:
44
push:
55
branches: [ gisce ]
6-
6+
pull_request:
7+
branches: [ gisce ]
78

89
jobs:
910
check-package-installable:

src/constants.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
512512
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformEcdsaSha512, "ECDSA_SHA512");
513513
#endif
514514

515+
#ifndef XMLSEC_NO_MD5
515516
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacMd5, "HMAC_MD5");
517+
#endif
518+
516519
#ifndef XMLSEC_NO_RIPEMD160
517520
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacRipemd160, "HMAC_RIPEMD160");
518521
#endif
@@ -522,7 +525,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
522525
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacSha384, "HMAC_SHA384");
523526
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacSha512, "HMAC_SHA512");
524527

528+
#ifndef XMLSEC_NO_MD5
525529
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaMd5, "RSA_MD5");
530+
#endif
531+
526532
#ifndef XMLSEC_NO_RIPEMD160
527533
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaRipemd160, "RSA_RIPEMD160");
528534
#endif
@@ -534,7 +540,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
534540
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaPkcs1, "RSA_PKCS1");
535541
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaOaep, "RSA_OAEP");
536542

543+
#ifndef XMLSEC_NO_MD5
537544
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformMd5, "MD5");
545+
#endif
546+
538547
#ifndef XMLSEC_NO_RIPEMD160
539548
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRipemd160, "RIPEMD160");
540549
#endif

src/enc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void PyXmlSec_ClearReplacedNodes(xmlSecEncCtxPtr ctx, PyXmlSec_LxmlDocume
192192
PYXMLSEC_DEBUGF("clear replaced node %p", n);
193193
nn = n->next;
194194
// if n has references, it will not be deleted
195-
elem = PyXmlSec_elementFactory(doc, n);
195+
elem = (PyXmlSec_LxmlElementPtr*)PyXmlSec_elementFactory(doc, n);
196196
if (NULL == elem)
197197
xmlFreeNode(n);
198198
else

src/exception.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
PyObject* PyXmlSec_Error;
2323
PyObject* PyXmlSec_InternalError;
2424
PyObject* PyXmlSec_VerificationError;
25-
25+
//#if PY_MINOR_VERSION >= 7
26+
#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
27+
static Py_tss_t PyXmlSec_LastErrorKey;
28+
#else
2629
static int PyXmlSec_LastErrorKey = 0;
30+
#endif
2731

2832
static int PyXmlSec_PrintErrorMessage = 0;
2933

@@ -71,16 +75,28 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e)
7175
PyXmlSec_ErrorHolder* v;
7276
int r;
7377

78+
// #if PY_MINOR_VERSION >= 7
79+
#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
80+
if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) == 0) {
81+
#else
7482
if (PyXmlSec_LastErrorKey == 0) {
83+
#endif
7584
PYXMLSEC_DEBUG("WARNING: There is no error key.");
7685
PyXmlSec_ErrorHolderFree(e);
7786
return NULL;
7887
}
7988

8089
// get_key_value and set_key_value are gil free
90+
// #if PY_MINOR_VERSION >= 7
91+
#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
92+
v = (PyXmlSec_ErrorHolder*)PyThread_tss_get(&PyXmlSec_LastErrorKey);
93+
//PyThread_tss_delete(&PyXmlSec_LastErrorKey);
94+
r = PyThread_tss_set(&PyXmlSec_LastErrorKey, (void*)e);
95+
#else
8196
v = (PyXmlSec_ErrorHolder*)PyThread_get_key_value(PyXmlSec_LastErrorKey);
8297
PyThread_delete_key_value(PyXmlSec_LastErrorKey);
8398
r = PyThread_set_key_value(PyXmlSec_LastErrorKey, (void*)e);
99+
#endif
84100
PYXMLSEC_DEBUGF("set_key_value returns %d", r);
85101
return v;
86102
}
@@ -165,6 +181,17 @@ void PyXmlSecEnableDebugTrace(int v) {
165181
PyXmlSec_PrintErrorMessage = v;
166182
}
167183

184+
void PyXmlSec_InstallErrorCallback() {
185+
// #if PY_MINOR_VERSION >= 7
186+
#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
187+
if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) != 0) {
188+
#else
189+
if (PyXmlSec_LastErrorKey != 0) {
190+
#endif
191+
xmlSecErrorsSetCallback(PyXmlSec_ErrorCallback);
192+
}
193+
}
194+
168195
// initializes errors module
169196
int PyXmlSec_ExceptionsModule_Init(PyObject* package) {
170197
PyXmlSec_Error = NULL;
@@ -184,10 +211,15 @@ int PyXmlSec_ExceptionsModule_Init(PyObject* package) {
184211
if (PyModule_AddObject(package, "InternalError", PyXmlSec_InternalError) < 0) goto ON_FAIL;
185212
if (PyModule_AddObject(package, "VerificationError", PyXmlSec_VerificationError) < 0) goto ON_FAIL;
186213

187-
PyXmlSec_LastErrorKey = PyThread_create_key();
188-
if (PyXmlSec_LastErrorKey != 0) {
189-
xmlSecErrorsSetCallback(&PyXmlSec_ErrorCallback);
214+
// #if PY_MINOR_VERSION >= 7
215+
#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
216+
if (PyThread_tss_create(&PyXmlSec_LastErrorKey) == 0) {
217+
PyXmlSec_InstallErrorCallback();
190218
}
219+
#else
220+
PyXmlSec_LastErrorKey = PyThread_create_key();
221+
PyXmlSec_InstallErrorCallback();
222+
#endif
191223

192224
return 0;
193225

src/keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static int PyXmlSec_KeyNameSet(PyObject* self, PyObject* value, void* closure) {
453453
}
454454

455455
if (value == NULL) {
456-
if (xmlSecKeySetName(key->handle, value) < 0) {
456+
if (xmlSecKeySetName(key->handle, NULL) < 0) {
457457
PyXmlSec_SetLastError("cannot delete name");
458458
return -1;
459459
}

0 commit comments

Comments
 (0)