Prefer std::optional over boost:optional:

Some of the boost::optionals must remain for now.  Both
boost::beast and SOCI have interfaces that require
boost::optional.
This commit is contained in:
Scott Schurr
2020-11-13 15:09:18 -08:00
committed by Nik Bougalis
parent 85307b29d0
commit 3b33318dc8
241 changed files with 1293 additions and 1248 deletions

View File

@@ -46,11 +46,11 @@ to_string(Manifest const& m)
toBase58(TokenType::NodePublic, m.signingKey) + ")";
}
boost::optional<Manifest>
std::optional<Manifest>
deserializeManifest(Slice s)
{
if (s.empty())
return boost::none;
return std::nullopt;
static SOTemplate const manifestFormat{
// A manifest must include:
@@ -86,12 +86,12 @@ deserializeManifest(Slice s)
// We only understand "version 0" manifests at this time:
if (st.isFieldPresent(sfVersion) && st.getFieldU16(sfVersion) != 0)
return boost::none;
return std::nullopt;
auto const pk = st.getFieldVL(sfPublicKey);
if (!publicKeyType(makeSlice(pk)))
return boost::none;
return std::nullopt;
Manifest m;
m.serialized.assign(reinterpret_cast<char const*>(s.data()), s.size());
@@ -105,7 +105,7 @@ deserializeManifest(Slice s)
m.domain.assign(reinterpret_cast<char const*>(d.data()), d.size());
if (!isProperlyFormedTomlDomain(m.domain))
return boost::none;
return std::nullopt;
}
bool const hasEphemeralKey = st.isFieldPresent(sfSigningPubKey);
@@ -116,38 +116,38 @@ deserializeManifest(Slice s)
// Revocation manifests should not specify a new signing key
// or a signing key signature.
if (hasEphemeralKey)
return boost::none;
return std::nullopt;
if (hasEphemeralSig)
return boost::none;
return std::nullopt;
}
else
{
// Regular manifests should contain a signing key and an
// associated signature.
if (!hasEphemeralKey)
return boost::none;
return std::nullopt;
if (!hasEphemeralSig)
return boost::none;
return std::nullopt;
auto const spk = st.getFieldVL(sfSigningPubKey);
if (!publicKeyType(makeSlice(spk)))
return boost::none;
return std::nullopt;
m.signingKey = PublicKey(makeSlice(spk));
// The signing and master keys can't be the same
if (m.signingKey == m.masterKey)
return boost::none;
return std::nullopt;
}
return m;
}
catch (std::exception const&)
{
return boost::none;
return std::nullopt;
}
}
@@ -215,14 +215,14 @@ Manifest::revoked() const
return sequence == std::numeric_limits<std::uint32_t>::max();
}
boost::optional<Blob>
std::optional<Blob>
Manifest::getSignature() const
{
STObject st(sfGeneric);
SerialIter sit(serialized.data(), serialized.size());
st.set(sit);
if (!get(st, sfSignature))
return boost::none;
return std::nullopt;
return st.getFieldVL(sfSignature);
}
@@ -235,7 +235,7 @@ Manifest::getMasterSignature() const
return st.getFieldVL(sfMasterSignature);
}
boost::optional<ValidatorToken>
std::optional<ValidatorToken>
loadValidatorToken(std::vector<std::string> const& blob)
{
try
@@ -272,11 +272,11 @@ loadValidatorToken(std::vector<std::string> const& blob)
}
}
return boost::none;
return std::nullopt;
}
catch (std::exception const&)
{
return boost::none;
return std::nullopt;
}
}
@@ -304,7 +304,7 @@ ManifestCache::getMasterKey(PublicKey const& pk) const
return pk;
}
boost::optional<std::uint32_t>
std::optional<std::uint32_t>
ManifestCache::getSequence(PublicKey const& pk) const
{
std::lock_guard lock{read_mutex_};
@@ -313,10 +313,10 @@ ManifestCache::getSequence(PublicKey const& pk) const
if (iter != map_.end() && !iter->second.revoked())
return iter->second.sequence;
return boost::none;
return std::nullopt;
}
boost::optional<std::string>
std::optional<std::string>
ManifestCache::getDomain(PublicKey const& pk) const
{
std::lock_guard lock{read_mutex_};
@@ -325,10 +325,10 @@ ManifestCache::getDomain(PublicKey const& pk) const
if (iter != map_.end() && !iter->second.revoked())
return iter->second.domain;
return boost::none;
return std::nullopt;
}
boost::optional<std::string>
std::optional<std::string>
ManifestCache::getManifest(PublicKey const& pk) const
{
std::lock_guard lock{read_mutex_};
@@ -337,7 +337,7 @@ ManifestCache::getManifest(PublicKey const& pk) const
if (iter != map_.end() && !iter->second.revoked())
return iter->second.serialized;
return boost::none;
return std::nullopt;
}
bool