@@ -227,6 +227,15 @@ PYBIND11_MODULE(seal, m)
227227 plain.load (context, in);
228228 in.close ();
229229 })
230+ .def (" dumpb" , [](const Plaintext &plain){
231+ std::stringstream out (std::ios::binary | std::ios::out);
232+ plain.save (out);
233+ return py::bytes (out.str ());
234+ })
235+ .def (" loadb" , [](Plaintext &plain, const SEALContext &context, const py::bytes &bytes){
236+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
237+ plain.load (context, in);
238+ })
230239 .def (" save_size" , [](const Plaintext &plain){
231240 return plain.save_size ();
232241 })
@@ -264,6 +273,15 @@ PYBIND11_MODULE(seal, m)
264273 cipher.load (context, in);
265274 in.close ();
266275 })
276+ .def (" dumpb" , [](const Ciphertext &cipher){
277+ std::stringstream out (std::ios::binary | std::ios::out);
278+ cipher.save (out);
279+ return py::bytes (out.str ());
280+ })
281+ .def (" loadb" , [](Ciphertext &cipher, const SEALContext &context, const py::bytes &bytes){
282+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
283+ cipher.load (context, in);
284+ })
267285 .def (" save_size" , [](const Ciphertext &cipher){
268286 return cipher.save_size ();
269287 })
@@ -288,6 +306,15 @@ PYBIND11_MODULE(seal, m)
288306 sk.load (context, in);
289307 in.close ();
290308 })
309+ .def (" dumpb" , [](const SecretKey &sk){
310+ std::stringstream out (std::ios::binary | std::ios::out);
311+ sk.save (out);
312+ return py::bytes (out.str ());
313+ })
314+ .def (" loadb" , [](SecretKey &sk, const SEALContext &context, const py::bytes &bytes){
315+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
316+ sk.load (context, in);
317+ })
291318 .def (" to_string" , [](const SecretKey &secret){
292319 std::stringstream out (std::ios::binary | std::ios::out);
293320 secret.save (out);
@@ -309,6 +336,15 @@ PYBIND11_MODULE(seal, m)
309336 pk.load (context, in);
310337 in.close ();
311338 })
339+ .def (" dumpb" , [](const PublicKey &pk){
340+ std::stringstream out (std::ios::binary | std::ios::out);
341+ pk.save (out);
342+ return py::bytes (out.str ());
343+ })
344+ .def (" loadb" , [](PublicKey &pk, const SEALContext &context, const py::bytes &bytes){
345+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
346+ pk.load (context, in);
347+ })
312348 .def (" to_string" , [](const PublicKey &public_){
313349 std::stringstream out (std::ios::binary | std::ios::out);
314350 public_.save (out);
@@ -330,7 +366,16 @@ PYBIND11_MODULE(seal, m)
330366 std::ifstream in (path, std::ios::binary);
331367 ksk.load (context, in);
332368 in.close ();
333- });
369+ })
370+ .def (" dumpb" , [](const KSwitchKeys &ksk){
371+ std::stringstream out (std::ios::binary | std::ios::out);
372+ ksk.save (out);
373+ return py::bytes (out.str ());
374+ })
375+ .def (" loadb" , [](KSwitchKeys &ksk, const SEALContext &context, const py::bytes &bytes){
376+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
377+ ksk.load (context, in);
378+ });
334379
335380 // relinkeys.h
336381 py::class_<RelinKeys, KSwitchKeys>(m, " RelinKeys" )
@@ -350,6 +395,15 @@ PYBIND11_MODULE(seal, m)
350395 rk.load (context, in);
351396 in.close ();
352397 })
398+ .def (" dumpb" , [](const RelinKeys &rk){
399+ std::stringstream out (std::ios::binary | std::ios::out);
400+ rk.save (out);
401+ return py::bytes (out.str ());
402+ })
403+ .def (" loadb" , [](RelinKeys &rk, const SEALContext &context, const py::bytes &bytes){
404+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
405+ rk.load (context, in);
406+ })
353407 .def (" to_string" , [](const RelinKeys &relin){
354408 std::stringstream out (std::ios::binary | std::ios::out);
355409 relin.save (out);
@@ -374,6 +428,15 @@ PYBIND11_MODULE(seal, m)
374428 gk.load (context, in);
375429 in.close ();
376430 })
431+ .def (" dumpb" , [](const GaloisKeys &gk){
432+ std::stringstream out (std::ios::binary | std::ios::out);
433+ gk.save (out);
434+ return py::bytes (out.str ());
435+ })
436+ .def (" loadb" , [](GaloisKeys &gk, const SEALContext &context, const py::bytes &bytes){
437+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
438+ gk.load (context, in);
439+ })
377440 .def (" to_string" , [](const GaloisKeys &galois){
378441 std::stringstream out (std::ios::binary | std::ios::out);
379442 galois.save (out);
0 commit comments