mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
Replace strUnHex pair return type with optional<Blob>
This commit is contained in:
@@ -267,12 +267,12 @@ ValidatorToken::make_ValidatorToken(std::vector<std::string> const& tokenBlob)
|
||||
token["validation_secret_key"].isString())
|
||||
{
|
||||
auto const ret = strUnHex (token["validation_secret_key"].asString());
|
||||
if (! ret.second || ret.first.empty())
|
||||
if (! ret || ret->empty())
|
||||
return boost::none;
|
||||
|
||||
return ValidatorToken(
|
||||
token["manifest"].asString(),
|
||||
SecretKey(Slice{ret.first.data(), ret.first.size()}));
|
||||
SecretKey(Slice{ret->data(), ret->size()}));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -98,14 +98,14 @@ ValidatorList::load (
|
||||
|
||||
auto const ret = strUnHex (key);
|
||||
|
||||
if (! ret.second || ! publicKeyType(makeSlice(ret.first)))
|
||||
if (! ret || ! publicKeyType(makeSlice(*ret)))
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid validator list publisher key: " << key;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto id = PublicKey(makeSlice(ret.first));
|
||||
auto id = PublicKey(makeSlice(*ret));
|
||||
|
||||
if (publisherManifests_.revoked (id))
|
||||
{
|
||||
@@ -228,10 +228,9 @@ ValidatorList::applyList (
|
||||
val.isMember ("validation_public_key") &&
|
||||
val["validation_public_key"].isString ())
|
||||
{
|
||||
std::pair<Blob, bool> ret (strUnHex (
|
||||
val["validation_public_key"].asString ()));
|
||||
boost::optional<Blob> const ret = strUnHex(val["validation_public_key"].asString());
|
||||
|
||||
if (! ret.second || ! publicKeyType(makeSlice(ret.first)))
|
||||
if (! ret || ! publicKeyType(makeSlice(*ret)))
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid node identity: " <<
|
||||
@@ -240,7 +239,7 @@ ValidatorList::applyList (
|
||||
else
|
||||
{
|
||||
publisherList.push_back (
|
||||
PublicKey(Slice{ ret.first.data (), ret.first.size() }));
|
||||
PublicKey(Slice{ ret->data (), ret->size() }));
|
||||
}
|
||||
|
||||
if (val.isMember ("manifest") && val["manifest"].isString ())
|
||||
@@ -343,11 +342,11 @@ ValidatorList::verify (
|
||||
|
||||
auto const sig = strUnHex(signature);
|
||||
auto const data = base64_decode (blob);
|
||||
if (! sig.second ||
|
||||
if (! sig ||
|
||||
! ripple::verify (
|
||||
publisherManifests_.getSigningKey(pubKey),
|
||||
makeSlice(data),
|
||||
makeSlice(sig.first)))
|
||||
makeSlice(*sig)))
|
||||
return ListDisposition::invalid;
|
||||
|
||||
Json::Reader r;
|
||||
|
||||
@@ -63,7 +63,7 @@ inline static std::string sqlEscape (Blob const& vecSrc)
|
||||
|
||||
uint64_t uintFromHex (std::string const& strSrc);
|
||||
|
||||
std::pair<Blob, bool> strUnHex (std::string const& strSrc);
|
||||
boost::optional<Blob> strUnHex (std::string const& strSrc);
|
||||
|
||||
struct parsedURL
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
std::pair<Blob, bool> strUnHex (std::string const& strSrc)
|
||||
boost::optional<Blob> strUnHex (std::string const& strSrc)
|
||||
{
|
||||
Blob out;
|
||||
|
||||
@@ -43,7 +43,7 @@ std::pair<Blob, bool> strUnHex (std::string const& strSrc)
|
||||
int c = charUnHex (*iter);
|
||||
|
||||
if (c < 0)
|
||||
return std::make_pair (Blob (), false);
|
||||
return {};
|
||||
|
||||
out.push_back(c);
|
||||
++iter;
|
||||
@@ -55,18 +55,18 @@ std::pair<Blob, bool> strUnHex (std::string const& strSrc)
|
||||
++iter;
|
||||
|
||||
if (cHigh < 0)
|
||||
return std::make_pair (Blob (), false);
|
||||
return {};
|
||||
|
||||
int cLow = charUnHex (*iter);
|
||||
++iter;
|
||||
|
||||
if (cLow < 0)
|
||||
return std::make_pair (Blob (), false);
|
||||
return {};
|
||||
|
||||
out.push_back (static_cast<unsigned char>((cHigh << 4) | cLow));
|
||||
}
|
||||
|
||||
return std::make_pair(std::move(out), true);
|
||||
return {std::move(out)};
|
||||
}
|
||||
|
||||
uint64_t uintFromHex (std::string const& strSrc)
|
||||
|
||||
@@ -745,11 +745,11 @@ private:
|
||||
if (parseBase58<PublicKey> (TokenType::AccountPublic, strPk))
|
||||
return true;
|
||||
|
||||
auto [pkHex, pkHexValid] = strUnHex (strPk);
|
||||
if (!pkHexValid)
|
||||
auto pkHex = strUnHex (strPk);
|
||||
if (!pkHex)
|
||||
return false;
|
||||
|
||||
if (!publicKeyType(makeSlice(pkHex)))
|
||||
if (!publicKeyType(makeSlice(*pkHex)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -477,12 +477,15 @@ static boost::optional<detail::STVar> parseLeaf (
|
||||
|
||||
try
|
||||
{
|
||||
auto [vBlob, validVBlob] = strUnHex (value.asString ());
|
||||
|
||||
if (! validVBlob)
|
||||
if (auto vBlob = strUnHex(value.asString()))
|
||||
{
|
||||
ret = detail::make_stvar<STBlob>(
|
||||
field, vBlob->data(), vBlob->size());
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw<std::invalid_argument> ("invalid data");
|
||||
|
||||
ret = detail::make_stvar<STBlob>(field, vBlob.data(), vBlob.size());
|
||||
}
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
|
||||
@@ -428,9 +428,9 @@ isMemoOkay (STObject const& st, std::string& reason)
|
||||
}
|
||||
|
||||
// The raw data is stored as hex-octets, which we want to decode.
|
||||
auto [data, validData] = strUnHex (memoElement.getText ());
|
||||
auto optData = strUnHex (memoElement.getText ());
|
||||
|
||||
if (!validData)
|
||||
if (!optData)
|
||||
{
|
||||
reason = "The MemoType, MemoData and MemoFormat fields may "
|
||||
"only contain hex-encoded data.";
|
||||
@@ -459,7 +459,7 @@ isMemoOkay (STObject const& st, std::string& reason)
|
||||
return a;
|
||||
}();
|
||||
|
||||
for (auto c : data)
|
||||
for (auto c : *optData)
|
||||
{
|
||||
if (!allowedSymbols[c])
|
||||
{
|
||||
|
||||
@@ -102,13 +102,13 @@ Json::Value doChannelVerify (RPC::Context& context)
|
||||
|
||||
if (!pk)
|
||||
{
|
||||
auto [pkHex, pkHexValid] = strUnHex (strPk);
|
||||
if (!pkHexValid)
|
||||
auto pkHex = strUnHex (strPk);
|
||||
if (!pkHex)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
auto const pkType = publicKeyType(makeSlice(pkHex));
|
||||
auto const pkType = publicKeyType(makeSlice(*pkHex));
|
||||
if (!pkType)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
pk.emplace(makeSlice(pkHex));
|
||||
pk.emplace(makeSlice(*pkHex));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ Json::Value doChannelVerify (RPC::Context& context)
|
||||
|
||||
std::uint64_t const drops = *optDrops;
|
||||
|
||||
auto [sig, sigHexValid] = strUnHex (params[jss::signature].asString ());
|
||||
if (!sigHexValid || !sig.size ())
|
||||
auto sig = strUnHex (params[jss::signature].asString ());
|
||||
if (!sig || !sig->size ())
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
|
||||
Serializer msg;
|
||||
@@ -135,7 +135,7 @@ Json::Value doChannelVerify (RPC::Context& context)
|
||||
|
||||
Json::Value result;
|
||||
result[jss::signature_verified] =
|
||||
verify (*pk, msg.slice (), makeSlice (sig), /*canonical*/ true);
|
||||
verify (*pk, msg.slice (), makeSlice (*sig), /*canonical*/ true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,12 +67,12 @@ Json::Value doSubmit (RPC::Context& context)
|
||||
|
||||
Json::Value jvResult;
|
||||
|
||||
auto [ret, validRet] = strUnHex (context.params[jss::tx_blob].asString ());
|
||||
auto ret = strUnHex (context.params[jss::tx_blob].asString ());
|
||||
|
||||
if (!validRet || !ret.size ())
|
||||
if (!ret || !ret->size ())
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
|
||||
SerialIter sitTrans (makeSlice(ret));
|
||||
SerialIter sitTrans (makeSlice(*ret));
|
||||
|
||||
std::shared_ptr<STTx const> stpTrans;
|
||||
|
||||
|
||||
@@ -531,11 +531,11 @@ public:
|
||||
|
||||
// public key with invalid type
|
||||
auto const ret = strUnHex("9930E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020");
|
||||
auto const badKey = Slice{ret.first.data(), ret.first.size()};
|
||||
auto const badKey = Slice{ret->data(), ret->size()};
|
||||
|
||||
// short public key
|
||||
auto const retShort = strUnHex("0330");
|
||||
auto const shortKey = Slice{retShort.first.data(), retShort.first.size()};
|
||||
auto const shortKey = Slice{retShort->data(), retShort->size()};
|
||||
|
||||
auto toString = [](STObject const& st)
|
||||
{
|
||||
|
||||
@@ -143,9 +143,9 @@ struct Regression_test : public beast::unit_test::suite
|
||||
// Set the same key in the STTx.
|
||||
auto secp256r1Sig = std::make_unique<STTx>(*(jt.stx));
|
||||
auto pubKeyBlob = strUnHex (secp256r1PubKey);
|
||||
assert (pubKeyBlob.second); // Hex for public key must be valid
|
||||
assert (pubKeyBlob); // Hex for public key must be valid
|
||||
secp256r1Sig->setFieldVL
|
||||
(sfSigningPubKey, std::move(pubKeyBlob.first));
|
||||
(sfSigningPubKey, std::move(*pubKeyBlob));
|
||||
jt.stx.reset (secp256r1Sig.release());
|
||||
|
||||
env (jt, ter (temINVALID));
|
||||
|
||||
@@ -30,15 +30,14 @@ public:
|
||||
void testUnHexSuccess (std::string const& strIn, std::string const& strExpected)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
BEAST_EXPECT(rv.second);
|
||||
BEAST_EXPECT(makeSlice(rv.first) == makeSlice(strExpected));
|
||||
BEAST_EXPECT(rv);
|
||||
BEAST_EXPECT(makeSlice(*rv) == makeSlice(strExpected));
|
||||
}
|
||||
|
||||
void testUnHexFailure (std::string const& strIn)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
BEAST_EXPECT(! rv.second);
|
||||
BEAST_EXPECT(rv.first.empty());
|
||||
BEAST_EXPECT(! rv);
|
||||
}
|
||||
|
||||
void testUnHex ()
|
||||
|
||||
@@ -246,9 +246,9 @@ public:
|
||||
{
|
||||
auto data = strUnHex(
|
||||
jrr[jss::ledger][jss::ledger_data].asString());
|
||||
if (BEAST_EXPECT(data.second))
|
||||
if (BEAST_EXPECT(data))
|
||||
{
|
||||
Serializer s(data.first.data(), data.first.size());
|
||||
Serializer s(data->data(), data->size());
|
||||
std::uint32_t seq = 0;
|
||||
BEAST_EXPECT(s.getInteger<std::uint32_t>(seq, 0));
|
||||
BEAST_EXPECT(seq == 3);
|
||||
|
||||
Reference in New Issue
Block a user