|
core-adapters 0.1.1
Third-party adapters for snicholls-core: nanobind helpers, nlohmann/json hooks, the snicholls_core Python package
|
nlohmann/json hook for snicholls::secret<T>: read only. A secret is never written to JSON.
More...
#include <string>#include <utility>#include <snicholls/core_adapters/nlohmann/json.hpp>#include <snicholls/core/secret.hpp>Go to the source code of this file.
Functions | |
| template<typename T > | |
| void | snicholls::from_json (const nlohmann::json &j, secret< T > &s) |
Reads a secret from JSON. There is no to_json: a secret is never written. | |
nlohmann/json hook for snicholls::secret<T>: read only. A secret is never written to JSON.
j.get<snicholls::secret<std::string>>() reads the value into a secret straight away, and the plain value never sits in an ordinary variable. The other direction is deliberately missing: there is no to_json for secret<T>, so nlohmann::json j = s; does not compile. Writing the mask would lose the value silently; writing the value would leak it. To send a secret on purpose, write s.reveal() - a call that is easy to find in review.snicholls::secret (secret.hpp); snicholls::json_error (json.hpp).snicholls::json_error for any value that does not convert to T (nlohmann's own type_error / out_of_range are caught and translated, without their message, which may quote the value).nlohmann::json(secret) is ill-formed).snicholls::core_json.T must itself be readable by nlohmann/json (j.get<T>()).Definition in file secret_json.hpp.