@@ -257,6 +257,49 @@ static PyObject* PyXmlSec_KeyFromBinaryFile(PyObject* self, PyObject* args, PyOb
257257 return NULL ;
258258}
259259
260+ static const char PyXmlSec_KeyFromBinaryData__doc__ [] = \
261+ "Loads (symmetric) key of kind *klass* from *data*.\n\n"
262+ ":param klass: the key value data klass\n"
263+ ":param data: the key binary data\n"
264+ ":return: pointer to newly created key\n" ;
265+ static PyObject * PyXmlSec_KeyFromBinaryData (PyObject * self , PyObject * args , PyObject * kwargs ) {
266+ static char * kwlist [] = { "klass" , "data" , NULL };
267+
268+ PyXmlSec_KeyData * keydata = NULL ;
269+ const char * data = NULL ;
270+ Py_ssize_t data_size = 0 ;
271+
272+ PyXmlSec_Key * key = NULL ;
273+
274+ PYXMLSEC_DEBUG ("load symmetric key from memory - start" );
275+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O!s#:from_binary_data" , kwlist ,
276+ PyXmlSec_KeyDataType , & keydata , & data , & data_size ))
277+ {
278+ goto ON_FAIL ;
279+ }
280+
281+ if ((key = PyXmlSec_NewKey1 ((PyTypeObject * )self )) == NULL ) goto ON_FAIL ;
282+
283+ Py_BEGIN_ALLOW_THREADS ;
284+ key -> handle = xmlSecKeyReadMemory (keydata -> id , (const xmlSecByte * )data , (xmlSecSize )data_size );
285+ Py_END_ALLOW_THREADS ;
286+
287+ if (key -> handle == NULL ) {
288+ PyXmlSec_SetLastError ("cannot read key" );
289+ goto ON_FAIL ;
290+ }
291+
292+ key -> is_own = 1 ;
293+
294+ PYXMLSEC_DEBUG ("load symmetric key from memory - ok" );
295+ return (PyObject * )key ;
296+
297+ ON_FAIL :
298+ PYXMLSEC_DEBUG ("load symmetric key from memory - fail" );
299+ Py_XDECREF (key );
300+ return NULL ;
301+ }
302+
260303static const char PyXmlSec_KeyCertFromMemory__doc__ [] = \
261304 "Loads certificate from memory.\n\n"
262305 ":param data: the certificate binary data\n"
@@ -413,6 +456,12 @@ static PyMethodDef PyXmlSec_KeyMethods[] = {
413456 METH_CLASS |METH_VARARGS |METH_KEYWORDS ,
414457 PyXmlSec_KeyFromBinaryFile__doc__
415458 },
459+ {
460+ "from_binary_data" ,
461+ (PyCFunction )PyXmlSec_KeyFromBinaryData ,
462+ METH_CLASS |METH_VARARGS |METH_KEYWORDS ,
463+ PyXmlSec_KeyFromBinaryData__doc__
464+ },
416465 {
417466 "load_cert_from_memory" ,
418467 (PyCFunction )PyXmlSec_KeyCertFromMemory ,
0 commit comments