1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-07-30 14:43:05 +03:00

Remove throw from inplaceEncrypt

Summary: Continuing the theme, this time with inplaceEncrypt. We have to catch the exceptions from Fizz for the bridge version.

Reviewed By: kvtsoy

Differential Revision: D75886829

fbshipit-source-id: f74d5ce73e242e20e4c62552748970b2d5d7cb79
This commit is contained in:
Matt Joras
2025-06-03 15:41:15 -07:00
committed by Facebook GitHub Bot
parent 2d2b3ced01
commit 4b26b9ede1
8 changed files with 59 additions and 18 deletions

View File

@ -302,8 +302,12 @@ continuousMemoryBuildScheduleEncrypt(
connection.bufAccessor->trimStart(prevSize + headerLen);
// buf and packetBuf is actually the same.
auto buf = connection.bufAccessor->obtain();
auto packetBuf =
auto encryptResult =
aead.inplaceEncrypt(std::move(buf), &packet->header, packetNum);
if (encryptResult.hasError()) {
return folly::makeUnexpected(encryptResult.error());
}
auto packetBuf = std::move(encryptResult.value());
CHECK(packetBuf->headroom() == headerLen + prevSize);
// Include header back.
packetBuf->prepend(headerLen);
@ -410,8 +414,12 @@ iobufChainBasedBuildScheduleEncrypt(
bodyCursor.pull(unencrypted->writableData() + headerLen, bodyLen);
unencrypted->advance(headerLen);
unencrypted->append(bodyLen);
auto packetBuf =
auto encryptResult =
aead.inplaceEncrypt(std::move(unencrypted), &packet->header, packetNum);
if (encryptResult.hasError()) {
return folly::makeUnexpected(encryptResult.error());
}
auto packetBuf = std::move(encryptResult.value());
DCHECK(packetBuf->headroom() == headerLen);
packetBuf->clear();
auto headerCursor = Cursor(&packet->header);
@ -1447,8 +1455,13 @@ void writeCloseCommon(
auto packet = std::move(packetBuilder).buildPacket();
CHECK_GE(packet.body.tailroom(), aead.getCipherOverhead());
auto bufUniquePtr = packet.body.clone();
bufUniquePtr =
auto encryptResult =
aead.inplaceEncrypt(std::move(bufUniquePtr), &packet.header, packetNum);
if (encryptResult.hasError()) {
LOG(ERROR) << "Error encrypting packet: " << encryptResult.error().message;
return;
}
bufUniquePtr = std::move(encryptResult.value());
bufUniquePtr->coalesce();
encryptPacketHeader(
headerForm,