diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-09-09 21:32:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-15 00:42:05 +0000 |
commit | 58828b0ce9556ee9cb38c484d1226663a0dcd993 (patch) | |
tree | dfea448799d9bd4328114199a9767dd18d045be3 /src/mongo/db/pipeline | |
parent | 22a77301a5b63b9bb7ef6dd73eabb4865c63a921 (diff) | |
download | mongo-58828b0ce9556ee9cb38c484d1226663a0dcd993.tar.gz |
SERVER-43909 clarify and repair util/hex.h API
- hexblob namespace
- Throwy hexblob::decode (nee fromHex)
- StringData overloads of hex codec ops
- add unsignedHex<T> and zeroPaddedHex<T>
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r-- | src/mongo/db/pipeline/resume_token.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/pipeline/resume_token_test.cpp | 10 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/mongo/db/pipeline/resume_token.cpp b/src/mongo/db/pipeline/resume_token.cpp index e6b876769f7..2272bf1d434 100644 --- a/src/mongo/db/pipeline/resume_token.cpp +++ b/src/mongo/db/pipeline/resume_token.cpp @@ -119,7 +119,7 @@ ResumeToken::ResumeToken(const ResumeTokenData& data) { data.documentKey.addToBsonObj(&builder, ""); auto keyObj = builder.obj(); KeyString::Builder encodedToken(KeyString::Version::V1, keyObj, Ordering::make(BSONObj())); - _hexKeyString = toHex(encodedToken.getBuffer(), encodedToken.getSize()); + _hexKeyString = hexblob::encode(encodedToken.getBuffer(), encodedToken.getSize()); const auto& typeBits = encodedToken.getTypeBits(); if (!typeBits.isAllZeros()) _typeBits = Value( @@ -146,10 +146,10 @@ ResumeTokenData ResumeToken::getData() const { uassert(ErrorCodes::FailedToParse, "resume token string was not a valid hex string", - isValidHex(_hexKeyString)); + hexblob::validate(_hexKeyString)); BufBuilder hexDecodeBuf; // Keep this in scope until we've decoded the bytes. - fromHexString(_hexKeyString, &hexDecodeBuf); + hexblob::decode(_hexKeyString, &hexDecodeBuf); BSONBinData keyStringBinData = BSONBinData(hexDecodeBuf.buf(), hexDecodeBuf.len(), BinDataType::BinDataGeneral); auto internalBson = KeyString::toBsonSafe(static_cast<const char*>(keyStringBinData.data), diff --git a/src/mongo/db/pipeline/resume_token_test.cpp b/src/mongo/db/pipeline/resume_token_test.cpp index 7f9e5010ab8..88be9cdc940 100644 --- a/src/mongo/db/pipeline/resume_token_test.cpp +++ b/src/mongo/db/pipeline/resume_token_test.cpp @@ -160,17 +160,17 @@ TEST(ResumeToken, FailsToDecodeInvalidKeyString) { const unsigned char nonsense[] = {165, 85, 77, 86, 255}; // Data of correct type, but empty. - const auto emptyToken = ResumeToken::parse(Document{{"_data"_sd, toHex(zeroes, 0)}}); + const auto emptyToken = ResumeToken::parse(Document{{"_data"_sd, hexblob::encode(zeroes, 0)}}); ASSERT_THROWS_CODE(emptyToken.getData(), AssertionException, 40649); // Data of correct type with a bunch of zeros. const auto zeroesToken = - ResumeToken::parse(Document{{"_data"_sd, toHex(zeroes, sizeof(zeroes))}}); + ResumeToken::parse(Document{{"_data"_sd, hexblob::encode(zeroes, sizeof(zeroes))}}); ASSERT_THROWS_CODE(zeroesToken.getData(), AssertionException, 50811); // Data of correct type with a bunch of nonsense. const auto nonsenseToken = - ResumeToken::parse(Document{{"_data"_sd, toHex(nonsense, sizeof(nonsense))}}); + ResumeToken::parse(Document{{"_data"_sd, hexblob::encode(nonsense, sizeof(nonsense))}}); ASSERT_THROWS_CODE(nonsenseToken.getData(), AssertionException, 50811); // Valid data, bad typeBits; note that an all-zeros typebits is valid so it is not tested here. @@ -183,8 +183,8 @@ TEST(ResumeToken, FailsToDecodeInvalidKeyString) { 60, // CType::kStringLike 55, // Non-null terminated }; - auto invalidStringToken = - ResumeToken::parse(Document{{"_data"_sd, toHex(invalidString, sizeof(invalidString))}}); + auto invalidStringToken = ResumeToken::parse( + Document{{"_data"_sd, hexblob::encode(invalidString, sizeof(invalidString))}}); // invalidStringToken.getData(); ASSERT_THROWS_WITH_CHECK( invalidStringToken.getData(), AssertionException, [](const AssertionException& exception) { |