summaryrefslogtreecommitdiff
path: root/src/SWIG/_util.i
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2021-01-13 11:47:29 +0100
committerMatěj Cepl <mcepl@cepl.eu>2021-01-14 14:29:59 +0100
commit9178c4d56b7270a6b813995f55a4828ce96256d8 (patch)
treeac6a539983294f42cc2b97d404f95912d2c7a8fe /src/SWIG/_util.i
parentd93ee3c676929ae1ca9b3acb94a8ce9c3f9c936d (diff)
downloadm2crypto-9178c4d56b7270a6b813995f55a4828ce96256d8.tar.gz
Move project to src/ layout
Diffstat (limited to 'src/SWIG/_util.i')
-rw-r--r--src/SWIG/_util.i60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/SWIG/_util.i b/src/SWIG/_util.i
new file mode 100644
index 0000000..bc2ee61
--- /dev/null
+++ b/src/SWIG/_util.i
@@ -0,0 +1,60 @@
+/* Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.
+ * Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
+*/
+/* $Id$ */
+
+%{
+#include <openssl/x509v3.h>
+%}
+
+%warnfilter(454) _util_err;
+%inline %{
+static PyObject *_util_err;
+
+void util_init(PyObject *util_err) {
+ Py_INCREF(util_err);
+ _util_err = util_err;
+}
+
+PyObject *util_hex_to_string(PyObject *blob) {
+ PyObject *obj;
+ const void *buf;
+ char *ret;
+ Py_ssize_t len;
+
+ if (PyObject_AsReadBuffer(blob, &buf, &len) == -1)
+ return NULL;
+
+ ret = hex_to_string((unsigned char *)buf, len);
+ if (!ret) {
+ m2_PyErr_Msg(_util_err);
+ return NULL;
+ }
+
+ obj = PyBytes_FromString(ret);
+
+ OPENSSL_free(ret);
+ return obj;
+}
+
+PyObject *util_string_to_hex(PyObject *blob) {
+ PyObject *obj;
+ const void *buf;
+ unsigned char *ret;
+ Py_ssize_t len0;
+ long len;
+
+ if (PyObject_AsReadBuffer(blob, &buf, &len0) == -1)
+ return NULL;
+
+ len = len0;
+ ret = string_to_hex((char *)buf, &len);
+ if (ret == NULL) {
+ m2_PyErr_Msg(_util_err);
+ return NULL;
+ }
+ obj = PyBytes_FromStringAndSize((char*)ret, len);
+ OPENSSL_free(ret);
+ return obj;
+}
+%}