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