Skip to content

Commit b8eee59

Browse files
authored
Merge pull request #158 from openfheorg/157-deserializecryptocontext-fix
Fix DeserializeCryptoContextString not creating proper CryptoContext object
2 parents b7ee5b0 + 6a68dce commit b8eee59

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/lib/pke/serialization.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ T DeserializeFromStringWrapper(const std::string& str, const ST& sertype) {
111111
return obj;
112112
}
113113

114+
template <typename ST>
115+
CryptoContext<DCRTPoly> DeserializeCCFromStringWrapper(const std::string& str, const ST& sertype) {
116+
CryptoContext<DCRTPoly> obj;
117+
std::istringstream iss(str);
118+
Serial::Deserialize<DCRTPoly>(obj, iss, sertype);
119+
return obj;
120+
}
121+
114122
template <typename T, typename ST>
115123
T DeserializeFromBytesWrapper(const py::bytes& bytes, const ST& sertype) {
116124
T obj;
@@ -120,6 +128,15 @@ T DeserializeFromBytesWrapper(const py::bytes& bytes, const ST& sertype) {
120128
return obj;
121129
}
122130

131+
template <typename ST>
132+
CryptoContext<DCRTPoly> DeserializeCCFromBytesWrapper(const py::bytes& bytes, const ST& sertype) {
133+
CryptoContext<DCRTPoly> obj;
134+
std::string str(bytes);
135+
std::istringstream iss(str, std::ios::binary);
136+
Serial::Deserialize<DCRTPoly>(obj, iss, sertype);
137+
return obj;
138+
}
139+
123140

124141
void bind_serialization(pybind11::module &m) {
125142
// Json Serialization
@@ -147,7 +164,7 @@ void bind_serialization(pybind11::module &m) {
147164
// JSON Serialization to string
148165
m.def("Serialize", &SerializeToStringWrapper<CryptoContext<DCRTPoly>, SerType::SERJSON>,
149166
py::arg("obj"), py::arg("sertype"));
150-
m.def("DeserializeCryptoContextString", &DeserializeFromStringWrapper<CryptoContext<DCRTPoly>, SerType::SERJSON>,
167+
m.def("DeserializeCryptoContextString", &DeserializeCCFromStringWrapper<SerType::SERJSON>,
151168
py::arg("str"), py::arg("sertype"));
152169
m.def("Serialize", &SerializeToStringWrapper<PublicKey<DCRTPoly>, SerType::SERJSON>,
153170
py::arg("obj"), py::arg("sertype"));
@@ -191,7 +208,7 @@ void bind_serialization(pybind11::module &m) {
191208
// Binary Serialization to bytes
192209
m.def("Serialize", &SerializeToBytesWrapper<CryptoContext<DCRTPoly>, SerType::SERBINARY>,
193210
py::arg("obj"), py::arg("sertype"));
194-
m.def("DeserializeCryptoContextString", &DeserializeFromBytesWrapper<CryptoContext<DCRTPoly>, SerType::SERBINARY>,
211+
m.def("DeserializeCryptoContextString", &DeserializeCCFromBytesWrapper<SerType::SERBINARY>,
195212
py::arg("str"), py::arg("sertype"));
196213
m.def("Serialize", &SerializeToBytesWrapper<PublicKey<DCRTPoly>, SerType::SERBINARY>,
197214
py::arg("obj"), py::arg("sertype"));
@@ -210,4 +227,3 @@ void bind_serialization(pybind11::module &m) {
210227
m.def("DeserializeEvalKeyString", &DeserializeFromBytesWrapper<EvalKey<DCRTPoly>, SerType::SERBINARY>,
211228
py::arg("str"), py::arg("sertype"));
212229
}
213-

0 commit comments

Comments
 (0)