mirror of
https://github.com/NixOS/nix
synced 2024-09-19 10:50:24 -04:00
update fetchers::PublicKey
json (de)serialization
This commit is contained in:
parent
ff4c286e80
commit
e3fed2ebcf
|
@ -3,6 +3,7 @@
|
||||||
#include "input-accessor.hh"
|
#include "input-accessor.hh"
|
||||||
#include "source-path.hh"
|
#include "source-path.hh"
|
||||||
#include "fetch-to-store.hh"
|
#include "fetch-to-store.hh"
|
||||||
|
#include "json-utils.hh"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
@ -412,3 +413,20 @@ std::string publicKeys_to_string(const std::vector<PublicKey>& publicKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace nlohmann {
|
||||||
|
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
fetchers::PublicKey adl_serializer<fetchers::PublicKey>::from_json(const json & json) {
|
||||||
|
auto type = optionalValueAt(json, "type").value_or("ssh-ed25519");
|
||||||
|
auto key = valueAt(json, "key");
|
||||||
|
return fetchers::PublicKey { getString(type), getString(key) };
|
||||||
|
}
|
||||||
|
|
||||||
|
void adl_serializer<fetchers::PublicKey>::to_json(json & json, fetchers::PublicKey p) {
|
||||||
|
json["type"] = p.type;
|
||||||
|
json["key"] = p.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
#include "canon-path.hh"
|
#include "canon-path.hh"
|
||||||
|
#include "json-impls.hh"
|
||||||
#include "attrs.hh"
|
#include "attrs.hh"
|
||||||
#include "url.hh"
|
#include "url.hh"
|
||||||
|
|
||||||
|
@ -230,8 +231,9 @@ struct PublicKey
|
||||||
std::string type = "ssh-ed25519";
|
std::string type = "ssh-ed25519";
|
||||||
std::string key;
|
std::string key;
|
||||||
};
|
};
|
||||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(PublicKey, type, key)
|
|
||||||
|
|
||||||
std::string publicKeys_to_string(const std::vector<PublicKey>&);
|
std::string publicKeys_to_string(const std::vector<PublicKey>&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_IMPL(fetchers::PublicKey)
|
||||||
|
|
Loading…
Reference in a new issue