123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "ServerService.hpp"
- const unsigned int ServerService::kPIRParamsOptions = 2;
- int ServerService::writePIRParameters(const PIRParameters& pir_params, const std::string& file_path)
- {
- std::ofstream file(file_path);
- if(!file.is_open()) return 1;
- file << "d " << pir_params.d << std::endl;
- file << "dim ";
- for (unsigned int i = 0; i < pir_params.d ; i++) file << std::to_string(pir_params.n[i]) << " ";
- file << std::endl;
- file << pir_params.crypto_params << std::endl;
- file.close();
- return 0;
- }
- int ServerService::readPIRParameters(PIRParameters& pir_params, const std::string& file_path)
- {
- std::ifstream file(file_path);
- if (!file.is_open()) return 1;
- std::string line;
- std::vector<std::string> fields;
- std::getline(file, line);
- boost::algorithm::split(fields, line, boost::algorithm::is_any_of(" "));
- pir_params.d = atoi(fields.at(1).c_str());
- if (file.eof()) return 1;
- std::getline(file, line);
- boost::algorithm::split(fields, line, boost::algorithm::is_any_of(" "));
- unsigned int i;
- for (i = 0 ; i < pir_params.d && i < fields.size() - 1 ; i++)
- {
- pir_params.n[i] = atoi(fields.at(i+1).c_str());
- }
- if (i != pir_params.d) return 1;
-
- std::getline(file, line);
- pir_params.crypto_params = line;
- file.close();
- return 0;
- }
|