Skip to content

Commit e6ebb4e

Browse files
author
Huelse
committed
Revert "Merge pull request Huelse#20 from CarmenLee111/master"
This reverts commit ca3d42f, reversing changes made to e837b8f.
1 parent ca3d42f commit e6ebb4e

File tree

3 files changed

+8
-181
lines changed

3 files changed

+8
-181
lines changed

src/base64.cpp

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/base64.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/wrapper.cpp

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <pybind11/stl.h>
66
#include "seal/seal.h"
77
#include <fstream>
8-
#include "base64.h"
98

109
using namespace std;
1110
using namespace seal;
@@ -19,44 +18,6 @@ PYBIND11_MAKE_OPAQUE(std::vector<std::int64_t>);
1918

2019
using parms_id_type = std::array<std::uint64_t, 4>;
2120

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-
6021
PYBIND11_MODULE(seal, m)
6122
{
6223
m.doc() = "Microsoft SEAL (3.4.5) For Python. From https://github.com/Huelse/SEAL-Python";
@@ -100,8 +61,7 @@ PYBIND11_MODULE(seal, m)
10061
std::ifstream in(path, std::ifstream::binary);
10162
p.load(in);
10263
in.close();
103-
})
104-
.def(py::pickle(&serialize<EncryptionParameters>, &deserialize<EncryptionParameters>));
64+
});
10565

10666
// context.h
10767
py::class_<EncryptionParameterQualifiers, std::unique_ptr<EncryptionParameterQualifiers, py::nodelete>>(m, "EncryptionParameterQualifiers")
@@ -187,8 +147,7 @@ PYBIND11_MODULE(seal, m)
187147
std::ifstream in(path, std::ifstream::binary);
188148
c.load(context, in);
189149
in.close();
190-
})
191-
.def(py::pickle(&serialize<Plaintext>, &deserialize_context<Plaintext>));
150+
});
192151

193152
// ciphertext.h
194153
py::class_<Ciphertext>(m, "Ciphertext")
@@ -218,8 +177,7 @@ PYBIND11_MODULE(seal, m)
218177
std::ifstream in(path, std::ifstream::binary);
219178
c.load(context, in);
220179
in.close();
221-
})
222-
.def(py::pickle(&serialize<Ciphertext>, &deserialize_context<Ciphertext>));
180+
});
223181

224182
// secretkey.h
225183
py::class_<SecretKey>(m, "SecretKey")
@@ -234,8 +192,7 @@ PYBIND11_MODULE(seal, m)
234192
std::ifstream in(path, std::ifstream::binary);
235193
c.load(context, in);
236194
in.close();
237-
})
238-
.def(py::pickle(&serialize<SecretKey>, &deserialize_context<SecretKey>));
195+
});
239196

240197
// publickey.h
241198
py::class_<PublicKey>(m, "PublicKey")
@@ -250,8 +207,7 @@ PYBIND11_MODULE(seal, m)
250207
std::ifstream in(path, std::ifstream::binary);
251208
c.load(context, in);
252209
in.close();
253-
})
254-
.def(py::pickle(&serialize<PublicKey>, &deserialize_context<PublicKey>));
210+
});
255211

256212
// kswitchkeys.h
257213
py::class_<KSwitchKeys>(m, "KSwitchKeys")
@@ -266,8 +222,7 @@ PYBIND11_MODULE(seal, m)
266222
std::ifstream in(path, std::ifstream::binary);
267223
c.load(context, in);
268224
in.close();
269-
})
270-
.def(py::pickle(&serialize<KSwitchKeys>, &deserialize_context<KSwitchKeys>));
225+
});
271226

272227
// relinKeys.h
273228
py::class_<RelinKeys, KSwitchKeys>(m, "RelinKeys")
@@ -282,8 +237,7 @@ PYBIND11_MODULE(seal, m)
282237
std::ifstream in(path, std::ifstream::binary);
283238
c.load(context, in);
284239
in.close();
285-
})
286-
.def(py::pickle(&serialize<RelinKeys>, &deserialize_context<RelinKeys>));
240+
});
287241

288242
// galoisKeys.h
289243
py::class_<GaloisKeys, KSwitchKeys>(m, "GaloisKeys")
@@ -298,8 +252,7 @@ PYBIND11_MODULE(seal, m)
298252
std::ifstream in(path, std::ifstream::binary);
299253
c.load(context, in);
300254
in.close();
301-
})
302-
.def(py::pickle(&serialize<GaloisKeys>, &deserialize_context<GaloisKeys>));
255+
});
303256

304257
// keygenerator.h
305258
py::class_<KeyGenerator>(m, "KeyGenerator")

0 commit comments

Comments
 (0)