| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include "io.h" |
| 6 |
|
| 7 |
#include <aws/io/pkcs11.h> |
| 8 |
|
| 9 |
static const char *s_capsule_name = "aws_pkcs11_lib"; |
| 10 |
|
| 11 |
static void s_pkcs11_lib_capsule_destructor(PyObject *capsule) { |
| 12 |
struct aws_pkcs11_lib *pkcs11_lib = PyCapsule_GetPointer(capsule, s_capsule_name); |
| 13 |
aws_pkcs11_lib_release(pkcs11_lib); |
| 14 |
} |
| 15 |
|
| 16 |
struct aws_pkcs11_lib *aws_py_get_pkcs11_lib(PyObject *pkcs11_lib) { |
| 17 |
return aws_py_get_binding(pkcs11_lib, s_capsule_name, "Pkcs11Lib"); |
| 18 |
} |
| 19 |
|
| 20 |
PyObject *aws_py_pkcs11_lib_new(PyObject *self, PyObject *args) { |
| 21 |
(void)self; |
| 22 |
|
| 23 |
struct aws_byte_cursor filename; |
| 24 |
int behavior; |
| 25 |
if (!PyArg_ParseTuple(args, "s#i", &filename.ptr, &filename.len, &behavior)) { |
| 26 |
return NULL; |
| 27 |
} |
| 28 |
|
| 29 |
struct aws_pkcs11_lib_options options = { |
| 30 |
.filename = filename, |
| 31 |
.initialize_finalize_behavior = behavior, |
| 32 |
}; |
| 33 |
struct aws_pkcs11_lib *pkcs11_lib = aws_pkcs11_lib_new(aws_py_get_allocator(), &options); |
| 34 |
if (pkcs11_lib == NULL) { |
| 35 |
return PyErr_AwsLastError(); |
| 36 |
} |
| 37 |
|
| 38 |
PyObject *capsule = PyCapsule_New(pkcs11_lib, s_capsule_name, s_pkcs11_lib_capsule_destructor); |
| 39 |
if (capsule == NULL) { |
| 40 |
aws_pkcs11_lib_release(pkcs11_lib); |
| 41 |
return NULL; |
| 42 |
} |
| 43 |
|
| 44 |
return capsule; |
| 45 |
} |