Skip to content

Commit

Permalink
Make the library backward compatible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mxamin committed Mar 13, 2024
1 parent 53eb69b commit 595aeaa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion doc/source/modules/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ KeyData

The DSA key klass.

.. data:: xmlsec.constants.KeyDataEcdsa

(Deprecated. The EC key klass) The ECDSA key klass.

.. data:: xmlsec.constants.KeyDataEc

The ECDSA key klass.
The EC key klass.

.. data:: xmlsec.constants.KeyDataHmac

Expand Down
7 changes: 5 additions & 2 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
#ifndef XMLSEC_NO_DSA
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataDsa, "DSA")
#endif
#if XMLSEC_VERSION_HEX > 0x10212
// from version 1.2.19
#if XMLSEC_VERSION_HEX > 0x10212 && XMLSEC_VERSION_HEX < 0x10303
// from version 1.2.19 to version 1.3.2 (inclusive)
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEcdsa, "ECDSA")
#elif XMLSEC_VERSION_HEX >= 0x10303
// from version 1.3.3 (inclusive)
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEc, "ECDSA")
#endif
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataHmac, "HMAC")
Expand Down
15 changes: 12 additions & 3 deletions src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ static PyObject* PyXmlSec_KeyFromFile(PyObject* self, PyObject* args, PyObject*
if (is_content) {
key->handle = xmlSecCryptoAppKeyLoadMemory((const xmlSecByte*)data, (xmlSecSize)data_size, format, password, NULL, NULL);
} else {
key->handle = xmlSecCryptoAppKeyLoadEx(data, xmlSecKeyDataTypePrivate, format, password, NULL, NULL);
#if XMLSEC_VERSION_HEX >= 0x10303
// from version 1.3.3 (inclusive)
key->handle = xmlSecCryptoAppKeyLoadEx(data, xmlSecKeyDataTypePrivate, format, password, NULL, NULL);
#else
key->handle = xmlSecCryptoAppKeyLoad(data, format, password, NULL, NULL);
#endif
}
Py_END_ALLOW_THREADS;

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

Py_BEGIN_ALLOW_THREADS;
key->handle = xmlSecCryptoAppKeyLoadEx(engine_and_key_id, xmlSecKeyDataTypePrivate, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(),
(void*)engine_and_key_id);
#if XMLSEC_VERSION_HEX >= 0x10303
// from version 1.3.3 (inclusive)
key->handle = xmlSecCryptoAppKeyLoadEx(engine_and_key_id, xmlSecKeyDataTypePrivate, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(), (void*)engine_and_key_id);
#else
key->handle = xmlSecCryptoAppKeyLoad(engine_and_key_id, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(), (void*)engine_and_key_id);
#endif
Py_END_ALLOW_THREADS;

if (key->handle == NULL) {
Expand Down
1 change: 1 addition & 0 deletions src/xmlsec/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ KeyDataAes: Final[__KeyData]
KeyDataDes: Final[__KeyData]
KeyDataDsa: Final[__KeyData]
KeyDataEc: Final[__KeyData]
KeyDataEcdsa: Final[__KeyData]
KeyDataEncryptedKey: Final[__KeyData]
KeyDataFormatBinary: Final[int]
KeyDataFormatCertDer: Final[int]
Expand Down

0 comments on commit 595aeaa

Please sign in to comment.