From 90eadda3cb9dbf7aadab78c4b3ec9364cc5bc471 Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Thu, 29 Sep 2022 20:08:23 +0100 Subject: [PATCH] Add Python binding for loading trusted setup from filename --- min-bindings/c_kzg_4844.swg | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/min-bindings/c_kzg_4844.swg b/min-bindings/c_kzg_4844.swg index 0397d6e..926690c 100644 --- a/min-bindings/c_kzg_4844.swg +++ b/min-bindings/c_kzg_4844.swg @@ -55,6 +55,21 @@ #endif } +#if defined(SWIGPYTHON) +%typemap(in) FILE* { + if (PyUnicode_Check($input)) { + $1 = fopen(PyUnicode_AsUTF8($input), "r"); + if ($1 == NULL) { + PyErr_SetString(PyExc_RuntimeError, "failed to load file"); + SWIG_fail; + } + } else { + PyErr_SetString(PyExc_TypeError, "expected bytes (utf-8 encoded file path)"); + SWIG_fail; + } +} +#endif + %array_class(scalar_t, scalars) %array_class(BLSFieldElement, BLSFieldElements) %pointer_class(PolynomialEvalForm, PolynomialEvalFormPtr)