mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 10:35:50 +00:00
Reduce likelihood of malformed SOTemplate:
Formerly an SOTemplate was default constructed and its elements added using push_back(). This left open the possibility of a malformed SOTemplate if adding one of the elements caused a throw. With this commit the SOTemplate requires an initializer_list of its elements at construction. Elements may not be added after construction. With this approach either the SOTemplate is fully constructed with all of its elements or the constructor throws, which prevents an invalid SOTemplate from even existing. This change requires all SOTemplate construction to be adjusted at the call site. Those changes are also in this commit. The SOE_Flags enum is also renamed to SOEStyle, which harmonizes the name with other uses in the code base. SOEStyle elements are renamed (slightly) to have an "soe" prefix rather than "SOE_". This heads toward reserving identifiers with all upper case for macros. The new style also aligns with other prominent enums in the code base like the collection of TER identifiers. SOElement is adjusted so it can be stored directly in an STL container, rather than requiring storage in a unique_ptr. Correspondingly, unique_ptr usage is removed from both SOTemplate and KnownFormats.
This commit is contained in:
committed by
Nik Bougalis
parent
57fe197d3e
commit
afcc4ff296
@@ -39,32 +39,30 @@ boost::optional<Manifest> deserializeManifest(Slice s)
|
||||
if (s.empty())
|
||||
return boost::none;
|
||||
|
||||
static SOTemplate const manifestFormat (
|
||||
[](SOTemplate& t)
|
||||
{
|
||||
static SOTemplate const manifestFormat {
|
||||
// A manifest must include:
|
||||
// - the master public key
|
||||
t.push_back (SOElement (sfPublicKey, SOE_REQUIRED));
|
||||
{sfPublicKey, soeREQUIRED},
|
||||
|
||||
// - a signature with that public key
|
||||
t.push_back (SOElement (sfMasterSignature, SOE_REQUIRED));
|
||||
{sfMasterSignature, soeREQUIRED},
|
||||
|
||||
// - a sequence number
|
||||
t.push_back (SOElement (sfSequence, SOE_REQUIRED));
|
||||
{sfSequence, soeREQUIRED},
|
||||
|
||||
// It may, optionally, contain:
|
||||
// - a version number which defaults to 0
|
||||
t.push_back (SOElement (sfVersion, SOE_DEFAULT));
|
||||
{sfVersion, soeDEFAULT},
|
||||
|
||||
// - a domain name
|
||||
t.push_back (SOElement (sfDomain, SOE_OPTIONAL));
|
||||
{sfDomain, soeOPTIONAL},
|
||||
|
||||
// - an ephemeral signing key that can be changed as necessary
|
||||
t.push_back (SOElement (sfSigningPubKey, SOE_OPTIONAL));
|
||||
{sfSigningPubKey, soeOPTIONAL},
|
||||
|
||||
// - a signature using the ephemeral signing key, if it is present
|
||||
t.push_back (SOElement (sfSignature, SOE_OPTIONAL));
|
||||
});
|
||||
{sfSignature, soeOPTIONAL},
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user