|
1 | | -#include <pybind11/pybind11.h> |
| 1 | +//================================================================================== |
| 2 | +// BSD 2-Clause License |
| 3 | +// |
| 4 | +// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors |
| 5 | +// |
| 6 | +// All rights reserved. |
| 7 | +// |
| 8 | +// Author TPOC: contact@openfhe.org |
| 9 | +// |
| 10 | +// Redistribution and use in source and binary forms, with or without |
| 11 | +// modification, are permitted provided that the following conditions are met: |
| 12 | +// |
| 13 | +// 1. Redistributions of source code must retain the above copyright notice, this |
| 14 | +// list of conditions and the following disclaimer. |
| 15 | +// |
| 16 | +// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 17 | +// this list of conditions and the following disclaimer in the documentation |
| 18 | +// and/or other materials provided with the distribution. |
| 19 | +// |
| 20 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 24 | +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 28 | +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | +//================================================================================== |
| 31 | +#include "bindings.h" |
| 32 | + |
2 | 33 | #include <pybind11/stl.h> |
3 | 34 | #include <pybind11/stl_bind.h> |
4 | 35 | #include <pybind11/complex.h> |
5 | 36 | #include <pybind11/functional.h> |
6 | 37 | #include <pybind11/operators.h> |
7 | 38 | #include <pybind11/iostream.h> |
8 | | -#include <iostream> |
9 | | -#include <map> |
| 39 | + |
10 | 40 | #include "openfhe.h" |
| 41 | + |
11 | 42 | #include "key/key-ser.h" |
12 | | -#include "bindings.h" |
13 | | -#include "cryptocontext_wrapper.h" |
14 | 43 | #include "binfhe_bindings.h" |
| 44 | + |
| 45 | +#include "cryptocontext_wrapper.h" |
15 | 46 | #include "cryptocontext_docs.h" |
16 | 47 | #include "cryptoparameters_docs.h" |
17 | 48 | #include "plaintext_docs.h" |
18 | 49 | #include "ciphertext_docs.h" |
19 | | -#include "serialization.h" |
20 | 50 |
|
21 | 51 | using namespace lbcrypto; |
22 | 52 | namespace py = pybind11; |
| 53 | + |
| 54 | +// disable the PYBIND11 template-based conversion for this type |
23 | 55 | PYBIND11_MAKE_OPAQUE(std::map<usint, EvalKey<DCRTPoly>>); |
24 | 56 |
|
25 | 57 | template <typename T> |
@@ -100,6 +132,12 @@ void bind_parameters(py::module &m,const std::string name) |
100 | 132 |
|
101 | 133 | void bind_crypto_context(py::module &m) |
102 | 134 | { |
| 135 | + //Parameters Type |
| 136 | + /*TODO (Oliveira): If we expose Poly's and ParmType, this block will go somewhere else */ |
| 137 | + using ParmType = typename DCRTPoly::Params; |
| 138 | + using ParmTypePtr = std::shared_ptr<ParmType>; |
| 139 | + py::class_<ParmType, ParmTypePtr>(m, "ParmType"); |
| 140 | + |
103 | 141 | py::class_<CryptoContextImpl<DCRTPoly>, std::shared_ptr<CryptoContextImpl<DCRTPoly>>>(m, "CryptoContext") |
104 | 142 | .def(py::init<>()) |
105 | 143 | .def("GetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::GetKeyGenLevel, cc_GetKeyGenLevel_docs) |
@@ -1028,15 +1066,8 @@ void bind_enums_and_constants(py::module &m) |
1028 | 1066 | m.attr("HEStd_256_classic") = py::cast(SecurityLevel::HEStd_256_classic); |
1029 | 1067 | m.attr("HEStd_NotSet") = py::cast(SecurityLevel::HEStd_NotSet); |
1030 | 1068 |
|
1031 | | - //Parameters Type |
1032 | | - /*TODO (Oliveira): If we expose Poly's and ParmType, this block will go somewhere else */ |
1033 | | - using ParmType = typename DCRTPoly::Params; |
1034 | | - py::class_<ParmType, std::shared_ptr<ParmType>>(m, "ParmType"); |
1035 | | - |
1036 | 1069 | //NATIVEINT function |
1037 | 1070 | m.def("get_native_int", &get_native_int); |
1038 | | - |
1039 | | - |
1040 | 1071 | } |
1041 | 1072 |
|
1042 | 1073 | void bind_keys(py::module &m) |
|
0 commit comments