Skip to content

Commit 595aeaa

Browse files
committed
Make the library backward compatible
Starting from version xmlsec1-1.3.3, some of the constant and keys that were deprecated, removed from the library entirely. This change would add version awareness and backward compatible.
1 parent 53eb69b commit 595aeaa

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

Diff for: doc/source/modules/constants.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ KeyData
4747

4848
The DSA key klass.
4949

50+
.. data:: xmlsec.constants.KeyDataEcdsa
51+
52+
(Deprecated. The EC key klass) The ECDSA key klass.
53+
5054
.. data:: xmlsec.constants.KeyDataEc
5155

52-
The ECDSA key klass.
56+
The EC key klass.
5357

5458
.. data:: xmlsec.constants.KeyDataHmac
5559

Diff for: src/constants.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,11 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
445445
#ifndef XMLSEC_NO_DSA
446446
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataDsa, "DSA")
447447
#endif
448-
#if XMLSEC_VERSION_HEX > 0x10212
449-
// from version 1.2.19
448+
#if XMLSEC_VERSION_HEX > 0x10212 && XMLSEC_VERSION_HEX < 0x10303
449+
// from version 1.2.19 to version 1.3.2 (inclusive)
450+
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEcdsa, "ECDSA")
451+
#elif XMLSEC_VERSION_HEX >= 0x10303
452+
// from version 1.3.3 (inclusive)
450453
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEc, "ECDSA")
451454
#endif
452455
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataHmac, "HMAC")

Diff for: src/keys.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ static PyObject* PyXmlSec_KeyFromFile(PyObject* self, PyObject* args, PyObject*
163163
if (is_content) {
164164
key->handle = xmlSecCryptoAppKeyLoadMemory((const xmlSecByte*)data, (xmlSecSize)data_size, format, password, NULL, NULL);
165165
} else {
166-
key->handle = xmlSecCryptoAppKeyLoadEx(data, xmlSecKeyDataTypePrivate, format, password, NULL, NULL);
166+
#if XMLSEC_VERSION_HEX >= 0x10303
167+
// from version 1.3.3 (inclusive)
168+
key->handle = xmlSecCryptoAppKeyLoadEx(data, xmlSecKeyDataTypePrivate, format, password, NULL, NULL);
169+
#else
170+
key->handle = xmlSecCryptoAppKeyLoad(data, format, password, NULL, NULL);
171+
#endif
167172
}
168173
Py_END_ALLOW_THREADS;
169174

@@ -206,8 +211,12 @@ static PyObject* PyXmlSec_KeyFromEngine(PyObject* self, PyObject* args, PyObject
206211
if ((key = PyXmlSec_NewKey1((PyTypeObject*)self)) == NULL) goto ON_FAIL;
207212

208213
Py_BEGIN_ALLOW_THREADS;
209-
key->handle = xmlSecCryptoAppKeyLoadEx(engine_and_key_id, xmlSecKeyDataTypePrivate, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(),
210-
(void*)engine_and_key_id);
214+
#if XMLSEC_VERSION_HEX >= 0x10303
215+
// from version 1.3.3 (inclusive)
216+
key->handle = xmlSecCryptoAppKeyLoadEx(engine_and_key_id, xmlSecKeyDataTypePrivate, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(), (void*)engine_and_key_id);
217+
#else
218+
key->handle = xmlSecCryptoAppKeyLoad(engine_and_key_id, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(), (void*)engine_and_key_id);
219+
#endif
211220
Py_END_ALLOW_THREADS;
212221

213222
if (key->handle == NULL) {

Diff for: src/xmlsec/constants.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ KeyDataAes: Final[__KeyData]
3030
KeyDataDes: Final[__KeyData]
3131
KeyDataDsa: Final[__KeyData]
3232
KeyDataEc: Final[__KeyData]
33+
KeyDataEcdsa: Final[__KeyData]
3334
KeyDataEncryptedKey: Final[__KeyData]
3435
KeyDataFormatBinary: Final[int]
3536
KeyDataFormatCertDer: Final[int]

0 commit comments

Comments
 (0)