5
5
#include < pybind11/stl.h>
6
6
#include " seal/seal.h"
7
7
#include < fstream>
8
- #include " base64.h"
9
8
10
9
using namespace std ;
11
10
using namespace seal ;
@@ -19,44 +18,6 @@ PYBIND11_MAKE_OPAQUE(std::vector<std::int64_t>);
19
18
20
19
using parms_id_type = std::array<std::uint64_t , 4 >;
21
20
22
- template <class T >
23
- py::tuple serialize (T &c)
24
- {
25
- std::stringstream output (std::ios::binary | std::ios::out);
26
- c.save (output);
27
- std::string cipherstr = output.str ();
28
- std::string base64_encoded_cipher = base64_encode (reinterpret_cast <const unsigned char *>(cipherstr.c_str ()), cipherstr.length ());
29
- return py::make_tuple (base64_encoded_cipher);
30
- }
31
-
32
- template <class T >
33
- T deserialize (py::tuple t)
34
- {
35
- if (t.size () != 1 )
36
- throw std::runtime_error (" (Pickle) Invalid input tuple!" );
37
- T c = T ();
38
- std::string cipherstr_encoded = t[0 ].cast <std::string>();
39
- std::string cipherstr_decoded = base64_decode (cipherstr_encoded);
40
- std::stringstream input (std::ios::binary | std::ios::in);
41
- input.str (cipherstr_decoded);
42
- c.load (input);
43
- return c;
44
- }
45
-
46
- template <class T >
47
- T deserialize_context (py::tuple t)
48
- {
49
- if (t.size () != 2 )
50
- throw std::runtime_error (" (Pickle) Invalid input tuple!" );
51
- T c = T ();
52
- std::string cipherstr_encoded = t[1 ].cast <std::string>();
53
- std::string cipherstr_decoded = base64_decode (cipherstr_encoded);
54
- std::stringstream input (std::ios::binary | std::ios::in);
55
- input.str (cipherstr_decoded);
56
- c.load (t[0 ].cast <std::shared_ptr<SEALContext>>(), input);
57
- return c;
58
- }
59
-
60
21
PYBIND11_MODULE (seal, m)
61
22
{
62
23
m.doc () = " Microsoft SEAL (3.4.5) For Python. From https://github.com/Huelse/SEAL-Python" ;
@@ -100,8 +61,7 @@ PYBIND11_MODULE(seal, m)
100
61
std::ifstream in (path, std::ifstream::binary);
101
62
p.load (in);
102
63
in.close ();
103
- })
104
- .def (py::pickle (&serialize<EncryptionParameters>, &deserialize<EncryptionParameters>));
64
+ });
105
65
106
66
// context.h
107
67
py::class_<EncryptionParameterQualifiers, std::unique_ptr<EncryptionParameterQualifiers, py::nodelete>>(m, " EncryptionParameterQualifiers" )
@@ -187,8 +147,7 @@ PYBIND11_MODULE(seal, m)
187
147
std::ifstream in (path, std::ifstream::binary);
188
148
c.load (context, in);
189
149
in.close ();
190
- })
191
- .def (py::pickle (&serialize<Plaintext>, &deserialize_context<Plaintext>));
150
+ });
192
151
193
152
// ciphertext.h
194
153
py::class_<Ciphertext>(m, " Ciphertext" )
@@ -218,8 +177,7 @@ PYBIND11_MODULE(seal, m)
218
177
std::ifstream in (path, std::ifstream::binary);
219
178
c.load (context, in);
220
179
in.close ();
221
- })
222
- .def (py::pickle (&serialize<Ciphertext>, &deserialize_context<Ciphertext>));
180
+ });
223
181
224
182
// secretkey.h
225
183
py::class_<SecretKey>(m, " SecretKey" )
@@ -234,8 +192,7 @@ PYBIND11_MODULE(seal, m)
234
192
std::ifstream in (path, std::ifstream::binary);
235
193
c.load (context, in);
236
194
in.close ();
237
- })
238
- .def (py::pickle (&serialize<SecretKey>, &deserialize_context<SecretKey>));
195
+ });
239
196
240
197
// publickey.h
241
198
py::class_<PublicKey>(m, " PublicKey" )
@@ -250,8 +207,7 @@ PYBIND11_MODULE(seal, m)
250
207
std::ifstream in (path, std::ifstream::binary);
251
208
c.load (context, in);
252
209
in.close ();
253
- })
254
- .def (py::pickle (&serialize<PublicKey>, &deserialize_context<PublicKey>));
210
+ });
255
211
256
212
// kswitchkeys.h
257
213
py::class_<KSwitchKeys>(m, " KSwitchKeys" )
@@ -266,8 +222,7 @@ PYBIND11_MODULE(seal, m)
266
222
std::ifstream in (path, std::ifstream::binary);
267
223
c.load (context, in);
268
224
in.close ();
269
- })
270
- .def (py::pickle (&serialize<KSwitchKeys>, &deserialize_context<KSwitchKeys>));
225
+ });
271
226
272
227
// relinKeys.h
273
228
py::class_<RelinKeys, KSwitchKeys>(m, " RelinKeys" )
@@ -282,8 +237,7 @@ PYBIND11_MODULE(seal, m)
282
237
std::ifstream in (path, std::ifstream::binary);
283
238
c.load (context, in);
284
239
in.close ();
285
- })
286
- .def (py::pickle (&serialize<RelinKeys>, &deserialize_context<RelinKeys>));
240
+ });
287
241
288
242
// galoisKeys.h
289
243
py::class_<GaloisKeys, KSwitchKeys>(m, " GaloisKeys" )
@@ -298,8 +252,7 @@ PYBIND11_MODULE(seal, m)
298
252
std::ifstream in (path, std::ifstream::binary);
299
253
c.load (context, in);
300
254
in.close ();
301
- })
302
- .def (py::pickle (&serialize<GaloisKeys>, &deserialize_context<GaloisKeys>));
255
+ });
303
256
304
257
// keygenerator.h
305
258
py::class_<KeyGenerator>(m, " KeyGenerator" )
0 commit comments