@@ -49,6 +49,16 @@ PYBIND11_MODULE(seal, m)
49
49
parms.load (in);
50
50
in.close ();
51
51
})
52
+ .def (" dumpb" , [](const EncryptionParameters &parms){
53
+ std::stringstream out (std::ios::binary | std::ios::out);
54
+ parms.save (out);
55
+ return py::bytes (out.str ());
56
+ })
57
+ .def (" loadb" , [](EncryptionParameters &parms, const py::bytes &bytes){
58
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
59
+ parms.load (in);
60
+ })
61
+ // remove pickle support?
52
62
.def (py::pickle (
53
63
[](const EncryptionParameters &parms){
54
64
std::stringstream out_stream (std::ios::binary | std::ios::out);
@@ -183,7 +193,17 @@ PYBIND11_MODULE(seal, m)
183
193
})
184
194
.def (" save_size" , [](const Plaintext &plain){
185
195
return plain.save_size ();
186
- });
196
+ })
197
+ .def (" dumpb" , [](const Plaintext &plain){
198
+ std::stringstream out (std::ios::binary | std::ios::out);
199
+ plain.save (out);
200
+ return py::bytes (out.str ());
201
+ })
202
+ .def (" loadb" , [](Plaintext &plain, const SEALContext &context, const py::bytes &bytes){
203
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
204
+ plain.load (context, in);
205
+ })
206
+ ;
187
207
188
208
// ciphertext.h
189
209
py::class_<Ciphertext>(m, " Ciphertext" )
@@ -215,7 +235,17 @@ PYBIND11_MODULE(seal, m)
215
235
})
216
236
.def (" save_size" , [](const Ciphertext &cipher){
217
237
return cipher.save_size ();
218
- });
238
+ })
239
+ .def (" dumpb" , [](const Ciphertext &cipher){
240
+ std::stringstream out (std::ios::binary | std::ios::out);
241
+ cipher.save (out);
242
+ return py::bytes (out.str ());
243
+ })
244
+ .def (" loadb" , [](Ciphertext &cipher, const SEALContext &context, const py::bytes &bytes){
245
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
246
+ cipher.load (context, in);
247
+ })
248
+ ;
219
249
220
250
// secretkey.h
221
251
py::class_<SecretKey>(m, " SecretKey" )
@@ -231,7 +261,17 @@ PYBIND11_MODULE(seal, m)
231
261
std::ifstream in (path, std::ifstream::binary);
232
262
sk.load (context, in);
233
263
in.close ();
234
- });
264
+ })
265
+ .def (" dumpb" , [](const SecretKey &sk){
266
+ std::stringstream out (std::ios::binary | std::ios::out);
267
+ sk.save (out);
268
+ return py::bytes (out.str ());
269
+ })
270
+ .def (" loadb" , [](SecretKey &sk, const SEALContext &context, const py::bytes &bytes){
271
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
272
+ sk.load (context, in);
273
+ })
274
+ ;
235
275
236
276
// publickey.h
237
277
py::class_<PublicKey>(m, " PublicKey" )
@@ -247,7 +287,17 @@ PYBIND11_MODULE(seal, m)
247
287
std::ifstream in (path, std::ifstream::binary);
248
288
pk.load (context, in);
249
289
in.close ();
250
- });
290
+ })
291
+ .def (" dumpb" , [](const PublicKey &pk){
292
+ std::stringstream out (std::ios::binary | std::ios::out);
293
+ pk.save (out);
294
+ return py::bytes (out.str ());
295
+ })
296
+ .def (" loadb" , [](PublicKey &pk, const SEALContext &context, const py::bytes &bytes){
297
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
298
+ pk.load (context, in);
299
+ })
300
+ ;
251
301
252
302
// kswitchkeys.h
253
303
py::class_<KSwitchKeys>(m, " KSwitchKeys" )
@@ -264,7 +314,17 @@ PYBIND11_MODULE(seal, m)
264
314
std::ifstream in (path, std::ifstream::binary);
265
315
ksk.load (context, in);
266
316
in.close ();
267
- });
317
+ })
318
+ .def (" dumpb" , [](const KSwitchKeys &ksk){
319
+ std::stringstream out (std::ios::binary | std::ios::out);
320
+ ksk.save (out);
321
+ return py::bytes (out.str ());
322
+ })
323
+ .def (" loadb" , [](KSwitchKeys &ksk, const SEALContext &context, const py::bytes &bytes){
324
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
325
+ ksk.load (context, in);
326
+ })
327
+ ;
268
328
269
329
// relinKeys.h
270
330
py::class_<RelinKeys, KSwitchKeys>(m, " RelinKeys" )
@@ -283,7 +343,17 @@ PYBIND11_MODULE(seal, m)
283
343
std::ifstream in (path, std::ifstream::binary);
284
344
rk.load (context, in);
285
345
in.close ();
286
- });
346
+ })
347
+ .def (" dumpb" , [](const RelinKeys &rk){
348
+ std::stringstream out (std::ios::binary | std::ios::out);
349
+ rk.save (out);
350
+ return py::bytes (out.str ());
351
+ })
352
+ .def (" loadb" , [](RelinKeys &rk, const SEALContext &context, const py::bytes &bytes){
353
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
354
+ rk.load (context, in);
355
+ })
356
+ ;
287
357
288
358
// galoisKeys.h
289
359
py::class_<GaloisKeys, KSwitchKeys>(m, " GaloisKeys" )
@@ -302,7 +372,17 @@ PYBIND11_MODULE(seal, m)
302
372
std::ifstream in (path, std::ifstream::binary);
303
373
gk.load (context, in);
304
374
in.close ();
305
- });
375
+ })
376
+ .def (" dumpb" , [](const GaloisKeys &gk){
377
+ std::stringstream out (std::ios::binary | std::ios::out);
378
+ gk.save (out);
379
+ return py::bytes (out.str ());
380
+ })
381
+ .def (" loadb" , [](GaloisKeys &gk, const SEALContext &context, const py::bytes &bytes){
382
+ std::stringstream in (bytes, std::ios::binary | std::ios::in);
383
+ gk.load (context, in);
384
+ })
385
+ ;
306
386
307
387
// keygenerator.h
308
388
py::class_<KeyGenerator>(m, " KeyGenerator" )
0 commit comments