25 #ifndef LBCRYPTO_CRYPTO_CRYPTOCONTEXTSER_H 26 #define LBCRYPTO_CRYPTO_CRYPTOCONTEXTSER_H 33 #include "cryptocontext.h" 36 #include "utils/serial.h" 53 template <
typename Element>
54 template <
typename ST>
58 std::map<string, std::vector<LPEvalKey<Element>>>* smap;
59 std::map<string, std::vector<LPEvalKey<Element>>> omap;
61 if (
id.length() == 0) {
62 smap = &GetAllEvalMultKeys();
64 const auto k = GetAllEvalMultKeys().find(
id);
66 if (k == GetAllEvalMultKeys().end())
return false;
69 omap[k->first] = k->second;
72 Serial::Serialize(*smap, ser, sertype);
91 void Deserialize(CryptoContext<T>& obj, std::istream& stream,
const SerType::SERJSON&) {
92 CryptoContext<T> newob;
95 cereal::JSONInputArchive archive(stream);
98 catch (std::exception& e) {
104 newob->GetEncryptionAlgorithm(),
105 newob->getSchemeId());
108 template <
typename T>
109 bool SerializeToFile(
const std::string& filename,
const CryptoContext<T>& obj,
const SerType::SERJSON& sertype) {
110 std::ofstream file(filename, std::ios::out | std::ios::binary);
111 if (file.is_open()) {
112 Serial::Serialize(obj, file, sertype);
119 template <
typename T>
120 bool DeserializeFromFile(
const std::string& filename, CryptoContext<T>& obj,
const SerType::SERJSON& sertype) {
121 std::ifstream file(filename, std::ios::in | std::ios::binary);
122 if (file.is_open()) {
123 Serial::Deserialize(obj, file, sertype);
131 std::istream& stream,
136 std::ostream& ser,
const SerType::SERJSON&,
const CryptoContext<Poly> cc);
138 std::istream& ser,
const SerType::SERJSON&);
140 std::ostream& ser,
const SerType::SERJSON&,
string id);
142 std::ostream& ser,
const SerType::SERJSON&,
const CryptoContext<Poly> cc);
144 std::istream& ser,
const SerType::SERJSON&);
146 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
149 std::ostream& ser,
const SerType::SERJSON&,
const CryptoContext<Poly> cc);
151 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
153 template void Serial::Deserialize(
155 const SerType::SERJSON&);
157 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
159 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
160 const CryptoContext<NativePoly> cc);
162 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
164 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
166 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
167 const CryptoContext<NativePoly> cc);
169 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
171 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
173 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
174 const CryptoContext<NativePoly> cc);
176 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
178 template void Serial::Deserialize(
180 const SerType::SERJSON&);
182 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
184 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
185 const CryptoContext<DCRTPoly> cc);
187 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
189 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
191 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
192 const CryptoContext<DCRTPoly> cc);
194 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
196 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
string id);
198 SerType::SERJSON>(std::ostream& ser,
const SerType::SERJSON&,
199 const CryptoContext<DCRTPoly> cc);
201 SerType::SERJSON>(std::istream& ser,
const SerType::SERJSON&);
215 template <
typename T>
216 void Deserialize(CryptoContext<T>& obj, std::istream& stream,
const SerType::SERBINARY&) {
217 CryptoContext<T> newob;
220 cereal::PortableBinaryInputArchive archive(stream);
223 catch (std::exception& e) {
229 newob->GetEncryptionAlgorithm(),
230 newob->getSchemeId());
233 template <
typename T>
234 bool SerializeToFile(
const std::string& filename,
const CryptoContext<T>& obj,
const SerType::SERBINARY& sertype) {
235 std::ofstream file(filename, std::ios::out | std::ios::binary);
236 if (file.is_open()) {
237 Serial::Serialize(obj, file, sertype);
244 template <
typename T>
245 bool DeserializeFromFile(
const std::string& filename, CryptoContext<T>& obj,
const SerType::SERBINARY& sertype) {
246 std::ifstream file(filename, std::ios::in | std::ios::binary);
247 if (file.is_open()) {
248 Serial::Deserialize(obj, file, sertype);
256 std::istream& stream,
261 std::ostream& ser,
const SerType::SERBINARY&,
const CryptoContext<Poly> cc);
263 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
265 std::ostream& ser,
const SerType::SERBINARY&,
string id);
267 std::ostream& ser,
const SerType::SERBINARY&,
const CryptoContext<Poly> cc);
269 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
272 std::ostream& ser,
const SerType::SERBINARY&,
string id);
275 std::ostream& ser,
const SerType::SERBINARY&,
const CryptoContext<Poly> cc);
277 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
279 template void Serial::Deserialize(
281 const SerType::SERBINARY&);
284 std::ostream& ser,
const SerType::SERBINARY&,
string id);
286 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
287 const CryptoContext<NativePoly> cc);
289 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
292 std::ostream& ser,
const SerType::SERBINARY&,
string id);
294 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
295 const CryptoContext<NativePoly> cc);
297 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
300 std::ostream& ser,
const SerType::SERBINARY&,
string id);
302 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
303 const CryptoContext<NativePoly> cc);
305 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
307 template void Serial::Deserialize(
309 const SerType::SERBINARY&);
312 std::ostream& ser,
const SerType::SERBINARY&,
string id);
314 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
315 const CryptoContext<DCRTPoly> cc);
317 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
320 std::ostream& ser,
const SerType::SERBINARY&,
string id);
322 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
323 const CryptoContext<DCRTPoly> cc);
325 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
328 std::ostream& ser,
const SerType::SERBINARY&,
string id);
330 SerType::SERBINARY>(std::ostream& ser,
const SerType::SERBINARY&,
331 const CryptoContext<DCRTPoly> cc);
333 SerType::SERBINARY>(std::istream& ser,
const SerType::SERBINARY&);
CryptoContextImpl.
Definition: cryptocontext.h:56
CryptoContextFactory.
Definition: cryptocontext.h:53
static bool SerializeEvalMultKey(std::ostream &ser, const ST &sertype, string id="")
Definition: cryptocontext-ser.h:55
Definition: binfhecontext.h:36