2 #ifndef SSP21_SECUREFILE_H 3 #define SSP21_SECUREFILE_H 5 #include "ssp21/util/SequenceTypes.h" 6 #include "ssp21/crypto/gen/FormatError.h" 8 #include "ssp21/util/SerializationUtils.h" 9 #include "ssp21/util/SecureDynamicBuffer.h" 22 static std::unique_ptr<SecureDynamicBuffer> read(
const std::string& path, uint32_t max_file_size = 4096);
25 static void write(
const std::string& path,
const T& item)
27 auto buffer = serialize::to_secure_buffer(item);
28 write(path, buffer->as_wslice());
33 static void write(
const std::string& path,
const wseq32_t& data)
35 std::ofstream stream(path, std::ios::binary);
37 if (!stream.is_open())
throw std::runtime_error(strings::join(
"Unable to open file: ", path));
39 const uint8_t* buffer = data;
41 if (!stream.write(reinterpret_cast<const char*>(buffer), data.length()))
43 throw std::runtime_error(strings::join(
"Unable to write file: ", path));
SSP21-cpp main namespace.