Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the library backward compatible #286

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading