1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-06 22:22:38 +03:00

Introduce a ByteRange typealias

Summary: See title

Reviewed By: kvtsoy

Differential Revision: D73444489

fbshipit-source-id: f83566ce023e8237335d3bb43d89fc471f053afa
This commit is contained in:
Aman Sharma
2025-04-22 23:17:46 -07:00
committed by Facebook GitHub Bot
parent 048e64e2f1
commit bcbe5adce4
43 changed files with 126 additions and 139 deletions

View File

@@ -35,6 +35,7 @@ using SystemClock = folly::chrono::SystemClock;
namespace quic {
using ByteRange = folly::ByteRange;
using BufHelpers = folly::IOBuf; // For stuff like BufHelpers::create, etc.
using Buf = folly::IOBuf; // Used when we're not wrapping the buffer in an
// std::unique_ptr

View File

@@ -866,7 +866,7 @@ class QuicSocketLite {
*/
virtual Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) const = 0;
/**

View File

@@ -51,7 +51,7 @@ class MockQuicSocket : public QuicSocket {
MOCK_METHOD(
(Optional<std::vector<uint8_t>>),
getExportedKeyingMaterial,
(const std::string&, const Optional<folly::ByteRange>&, uint16_t),
(const std::string&, const Optional<ByteRange>&, uint16_t),
(const));
MOCK_METHOD(std::shared_ptr<QuicEventBase>, getEventBase, (), (const));
MOCK_METHOD(

View File

@@ -281,7 +281,7 @@ TEST_F(QuicBatchWriterTest, TestBatchingSendmmsgInplaceIovecMatches) {
size_t size = 0;
for (auto& message : messages) {
auto buf = folly::IOBuf::copyBuffer(
folly::ByteRange((unsigned char*)message.data(), message.size()));
ByteRange((unsigned char*)message.data(), message.size()));
batchWriter->append(
std::move(buf), message.size(), folly::SocketAddress(), nullptr);
size += message.size();
@@ -306,7 +306,7 @@ TEST_F(QuicBatchWriterTest, TestBatchingSendmmsgInplaceIovecMatches) {
folly::IOBufEqualTo eq;
EXPECT_TRUE(
eq(wrappedIovBuffer,
folly::IOBuf::copyBuffer(folly::ByteRange(
folly::IOBuf::copyBuffer(ByteRange(
(unsigned char*)messages[i].data(), messages[i].size()))));
}
@@ -356,8 +356,8 @@ TEST_F(QuicBatchWriterTest, TestBatchingSendmmsgNewlyAllocatedIovecMatches) {
for (auto& message : messages) {
auto buf = std::make_unique<folly::IOBuf>();
for (size_t j = 0; j < message.size(); j++) {
auto partBuf = folly::IOBuf::copyBuffer(folly::ByteRange(
(unsigned char*)message[j].data(), message[j].size()));
auto partBuf = folly::IOBuf::copyBuffer(
ByteRange((unsigned char*)message[j].data(), message[j].size()));
buf->appendToChain(std::move(partBuf));
}
buffers.emplace_back(std::move(buf));

View File

@@ -603,7 +603,7 @@ class TestQuicTransport
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string&,
const Optional<folly::ByteRange>&,
const Optional<ByteRange>&,
uint16_t) const override {
return none;
}

View File

@@ -293,15 +293,14 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) {
EXPECT_EQ(rt1.offset, 0);
std::string expected = "hey w";
EXPECT_EQ(
folly::ByteRange((uint8_t*)expected.data(), expected.size()),
ByteRange((uint8_t*)expected.data(), expected.size()),
rt1.data.getHead()->getRange());
EXPECT_EQ(stream2->retransmissionBuffer.size(), 1);
auto& rt2 = *stream2->retransmissionBuffer.at(0);
EXPECT_EQ(rt2.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->buffer(), buf->length()),
rt2.data.getHead()->getRange());
ByteRange(buf->buffer(), buf->length()), rt2.data.getHead()->getRange());
EXPECT_TRUE(rt2.eof);
// Testing retransmission
@@ -358,13 +357,13 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) {
auto& rt3 = *stream1->retransmissionBuffer.at(5);
expected = "hats up";
EXPECT_EQ(
folly::ByteRange((uint8_t*)expected.data(), expected.size()),
ByteRange((uint8_t*)expected.data(), expected.size()),
rt3.data.getHead()->getRange());
auto& rt4 = *stream1->retransmissionBuffer.at(0);
expected = "hey w";
EXPECT_EQ(
folly::ByteRange((uint8_t*)expected.data(), expected.size()),
ByteRange((uint8_t*)expected.data(), expected.size()),
rt4.data.getHead()->getRange());
// loss buffer should be split into 2. Part in retransmission buffer and
@@ -374,7 +373,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) {
auto& rt5 = *stream2->retransmissionBuffer.at(0);
expected = "hey wh";
EXPECT_EQ(
folly::ByteRange((uint8_t*)expected.data(), expected.size()),
ByteRange((uint8_t*)expected.data(), expected.size()),
rt5.data.getHead()->getRange());
EXPECT_EQ(rt5.offset, 0);
EXPECT_EQ(rt5.eof, 0);
@@ -382,7 +381,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) {
auto& rt6 = stream2->lossBuffer.front();
expected = "ats up";
EXPECT_EQ(
folly::ByteRange((uint8_t*)expected.data(), expected.size()),
ByteRange((uint8_t*)expected.data(), expected.size()),
rt6.data.getHead()->getRange());
EXPECT_EQ(rt6.offset, 6);
EXPECT_EQ(rt6.eof, 1);
@@ -494,8 +493,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPacketRetrans) {
auto& rt = *stream1->retransmissionBuffer.at(0);
EXPECT_EQ(rt.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->data(), buf->length()),
rt.data.getHead()->getRange());
ByteRange(buf->data(), buf->length()), rt.data.getHead()->getRange());
EXPECT_TRUE(rt.eof);
stream1->lossBuffer.push_back(std::move(rt));
}
@@ -504,8 +502,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPacketRetrans) {
auto& rt = *stream2->retransmissionBuffer.at(0);
EXPECT_EQ(rt.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->data(), buf->length()),
rt.data.getHead()->getRange());
ByteRange(buf->data(), buf->length()), rt.data.getHead()->getRange());
EXPECT_TRUE(rt.eof);
stream2->lossBuffer.push_back(std::move(rt));
}
@@ -670,8 +667,7 @@ TEST_F(
auto& rt = *stream1->retransmissionBuffer.at(0);
EXPECT_EQ(rt.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->data(), buf->length()),
rt.data.getHead()->getRange());
ByteRange(buf->data(), buf->length()), rt.data.getHead()->getRange());
EXPECT_TRUE(rt.eof);
stream1->lossBuffer.push_back(std::move(rt));
}
@@ -681,7 +677,7 @@ TEST_F(
EXPECT_EQ(rt.offset, 0);
auto expectedBuf = IOBuf::copyBuffer("hey w");
EXPECT_EQ(
folly::ByteRange(expectedBuf->data(), expectedBuf->length()),
ByteRange(expectedBuf->data(), expectedBuf->length()),
rt.data.getHead()->getRange());
EXPECT_FALSE(rt.eof);
stream2->lossBuffer.push_back(std::move(rt));
@@ -691,8 +687,7 @@ TEST_F(
auto& rt = *stream3->retransmissionBuffer.at(0);
EXPECT_EQ(rt.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->data(), buf->length()),
rt.data.getHead()->getRange());
ByteRange(buf->data(), buf->length()), rt.data.getHead()->getRange());
EXPECT_FALSE(rt.eof);
stream3->lossBuffer.push_back(std::move(rt));
}

View File

@@ -200,7 +200,7 @@ class TestQuicTransport
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string&,
const Optional<folly::ByteRange>&,
const Optional<ByteRange>&,
uint16_t) const override {
return none;
}

View File

@@ -113,7 +113,7 @@ class QuicClientTransportLite
*/
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) const override {
return clientConn_->clientHandshakeLayer->getExportedKeyingMaterial(
label, context, keyLength);

View File

@@ -153,7 +153,7 @@ bool ClientHandshake::waitingForData() const {
return waitForData_;
}
void ClientHandshake::computeCiphers(CipherKind kind, folly::ByteRange secret) {
void ClientHandshake::computeCiphers(CipherKind kind, ByteRange secret) {
std::unique_ptr<Aead> aead = buildAead(kind, secret);
std::unique_ptr<PacketNumberCipher> packetNumberCipher =
buildHeaderCipher(secret);

View File

@@ -145,7 +145,7 @@ class ClientHandshake : public Handshake {
ZeroRttWrite,
};
void computeCiphers(CipherKind kind, folly::ByteRange secret);
void computeCiphers(CipherKind kind, ByteRange secret);
/**
* Various utilities for concrete implementations to use.
@@ -176,7 +176,7 @@ class ClientHandshake : public Handshake {
* Given secret_n, returns secret_n+1 to be used for generating the next Aead
* on key updates.
*/
virtual BufPtr getNextTrafficSecret(folly::ByteRange secret) const = 0;
virtual BufPtr getNextTrafficSecret(ByteRange secret) const = 0;
BufPtr readTrafficSecret_;
BufPtr writeTrafficSecret_;
@@ -192,9 +192,9 @@ class ClientHandshake : public Handshake {
virtual bool matchEarlyParameters() = 0;
virtual std::unique_ptr<Aead> buildAead(
CipherKind kind,
folly::ByteRange secret) = 0;
ByteRange secret) = 0;
virtual std::unique_ptr<PacketNumberCipher> buildHeaderCipher(
folly::ByteRange secret) = 0;
ByteRange secret) = 0;
// Represents the packet type that should be used to write the data currently
// in the stream.

View File

@@ -62,7 +62,7 @@ class MockClientHandshake : public ClientHandshake {
Optional<std::vector<uint8_t>>,
getExportedKeyingMaterial,
(const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength),
());
MOCK_METHOD(Optional<bool>, getZeroRttRejected, ());
@@ -82,12 +82,12 @@ class MockClientHandshake : public ClientHandshake {
MOCK_METHOD(
std::unique_ptr<Aead>,
buildAead,
(ClientHandshake::CipherKind kind, folly::ByteRange secret));
(ClientHandshake::CipherKind kind, ByteRange secret));
MOCK_METHOD(
std::unique_ptr<PacketNumberCipher>,
buildHeaderCipher,
(folly::ByteRange secret));
MOCK_METHOD(BufPtr, getNextTrafficSecret, (folly::ByteRange secret), (const));
(ByteRange secret));
MOCK_METHOD(BufPtr, getNextTrafficSecret, (ByteRange secret), (const));
MOCK_METHOD(
const Optional<std::string>&,
getApplicationProtocol,

View File

@@ -50,7 +50,7 @@ folly::Expected<PaddingFrame, QuicError> decodePaddingFrame(
// Let's consume all the padding and return 1 padding frame for everything.
static_assert(
static_cast<int>(FrameType::PADDING) == 0, "Padding value is 0");
folly::ByteRange paddingBytes = cursor.peekBytes();
ByteRange paddingBytes = cursor.peekBytes();
if (paddingBytes.size() == 0) {
return PaddingFrame();
}
@@ -1337,7 +1337,7 @@ size_t parsePacketNumberLength(uint8_t initialByte) {
*/
std::pair<PacketNum, size_t> parsePacketNumber(
uint8_t initialByte,
folly::ByteRange packetNumberRange,
ByteRange packetNumberRange,
PacketNum expectedNextPacketNum) {
size_t packetNumLen = parsePacketNumberLength(initialByte);
uint32_t encodedPacketNum = 0;

View File

@@ -242,7 +242,7 @@ size_t parsePacketNumberLength(uint8_t initialByte);
*/
std::pair<PacketNum, size_t> parsePacketNumber(
uint8_t initialByte,
folly::ByteRange packetNumberRange,
ByteRange packetNumberRange,
PacketNum expectedNextPacketNum);
// cursor: has to be point to the byte just past initialByte

View File

@@ -14,7 +14,7 @@
namespace quic {
void PacketNumberCipher::decipherHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes,
uint8_t initialByteMask,
@@ -31,7 +31,7 @@ void PacketNumberCipher::decipherHeader(
}
void PacketNumberCipher::cipherHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes,
uint8_t initialByteMask,
@@ -47,7 +47,7 @@ void PacketNumberCipher::cipherHeader(
}
void PacketNumberCipher::decryptLongHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const {
decipherHeader(
@@ -59,7 +59,7 @@ void PacketNumberCipher::decryptLongHeader(
}
void PacketNumberCipher::decryptShortHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const {
decipherHeader(
@@ -71,7 +71,7 @@ void PacketNumberCipher::decryptShortHeader(
}
void PacketNumberCipher::encryptLongHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const {
cipherHeader(
@@ -83,7 +83,7 @@ void PacketNumberCipher::encryptLongHeader(
}
void PacketNumberCipher::encryptShortHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const {
cipherHeader(

View File

@@ -20,9 +20,9 @@ class PacketNumberCipher {
public:
virtual ~PacketNumberCipher() = default;
virtual void setKey(folly::ByteRange key) = 0;
virtual void setKey(ByteRange key) = 0;
virtual HeaderProtectionMask mask(folly::ByteRange sample) const = 0;
virtual HeaderProtectionMask mask(ByteRange sample) const = 0;
/**
* Decrypts a long header from a sample.
@@ -31,7 +31,7 @@ class PacketNumberCipher {
* packetNumberBytes should be supplied with at least 4 bytes.
*/
virtual void decryptLongHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const;
@@ -42,7 +42,7 @@ class PacketNumberCipher {
* packetNumberBytes should be supplied with at least 4 bytes.
*/
virtual void decryptShortHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const;
@@ -52,7 +52,7 @@ class PacketNumberCipher {
* initialByte is the initial byte.
*/
virtual void encryptLongHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const;
@@ -62,7 +62,7 @@ class PacketNumberCipher {
* initialByte is the initial byte.
*/
virtual void encryptShortHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes) const;
@@ -78,14 +78,14 @@ class PacketNumberCipher {
protected:
virtual void cipherHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes,
uint8_t initialByteMask,
uint8_t packetNumLengthMask) const;
virtual void decipherHeader(
folly::ByteRange sample,
ByteRange sample,
folly::MutableByteRange initialByte,
folly::MutableByteRange packetNumberBytes,
uint8_t initialByteMask,

View File

@@ -25,7 +25,7 @@ uint8_t ConnectionId::size() const {
}
std::string ConnectionId::hex() const {
return folly::hexlify(folly::ByteRange(connid.data(), connidLen));
return folly::hexlify(ByteRange(connid.data(), connidLen));
}
ConnectionId::ConnectionId(const std::vector<uint8_t>& connidIn) {

View File

@@ -290,8 +290,7 @@ CodecResult QuicReadCodec::tryParseShortHeaderPacket(
folly::MutableByteRange initialByteRange(data->writableData(), 1);
folly::MutableByteRange packetNumberByteRange(
data->writableData() + packetNumberOffset, kMaxPacketNumEncodingSize);
folly::ByteRange sampleByteRange(
data->writableData() + sampleOffset, sample.size());
ByteRange sampleByteRange(data->writableData() + sampleOffset, sample.size());
oneRttHeaderCipher_->decryptShortHeader(
sampleByteRange, initialByteRange, packetNumberByteRange);
@@ -447,8 +446,8 @@ CodecResult QuicReadCodec::parsePacket(
}
// Only allocate & copy the token if it matches the token we have
if (cryptoEqual_(
folly::ByteRange(tokenSource, sizeof(StatelessResetToken)),
folly::ByteRange(
ByteRange(tokenSource, sizeof(StatelessResetToken)),
ByteRange(
statelessResetToken_->data(), sizeof(StatelessResetToken)))) {
token = StatelessResetToken();
memcpy(token->data(), tokenSource, token->size());
@@ -569,7 +568,7 @@ void QuicReadCodec::setStatelessResetToken(
}
void QuicReadCodec::setCryptoEqual(
std::function<bool(folly::ByteRange, folly::ByteRange)> cryptoEqual) {
std::function<bool(ByteRange, ByteRange)> cryptoEqual) {
cryptoEqual_ = std::move(cryptoEqual);
}

View File

@@ -166,8 +166,7 @@ class QuicReadCodec {
void setClientConnectionId(ConnectionId connId);
void setServerConnectionId(ConnectionId connId);
void setStatelessResetToken(StatelessResetToken statelessResetToken);
void setCryptoEqual(
std::function<bool(folly::ByteRange, folly::ByteRange)> cryptoEqual);
void setCryptoEqual(std::function<bool(ByteRange, ByteRange)> cryptoEqual);
const ConnectionId& getClientConnectionId() const;
const ConnectionId& getServerConnectionId() const;
@@ -237,7 +236,7 @@ class QuicReadCodec {
std::unique_ptr<PacketNumberCipher> handshakeHeaderCipher_;
Optional<StatelessResetToken> statelessResetToken_;
std::function<bool(folly::ByteRange, folly::ByteRange)> cryptoEqual_;
std::function<bool(ByteRange, ByteRange)> cryptoEqual_;
Optional<TimePoint> handshakeDoneTime_;
QuicTransportStatsCallback* statsCallback_{nullptr};

View File

@@ -127,7 +127,7 @@ ChainedByteRangeHead ChainedByteRangeHead::splitAtMost(size_t len) {
if (head_.length() > len) {
// Just need to trim a little off the head.
ret.head_.range_ =
folly::ByteRange(head_.range_.begin(), head_.range_.begin() + len);
ByteRange(head_.range_.begin(), head_.range_.begin() + len);
ret.head_.next_ = nullptr;
ret.tail_ = &ret.head_;
head_.trimStart(len);
@@ -184,9 +184,9 @@ ChainedByteRangeHead ChainedByteRangeHead::splitAtMost(size_t len) {
*/
ret.head_.range_ = head_.range_;
head_.range_ =
folly::ByteRange(current->range_.begin() + len, current->range_.end());
current->range_ = folly::ByteRange(
current->range_.begin(), current->range_.begin() + len);
ByteRange(current->range_.begin() + len, current->range_.end());
current->range_ =
ByteRange(current->range_.begin(), current->range_.begin() + len);
ret.head_.next_ = head_.next_;
ret.tail_ = current;

View File

@@ -30,7 +30,7 @@ class ChainedByteRangeHead {
public:
ChainedByteRange() = default;
explicit ChainedByteRange(folly::ByteRange range) : range_(range) {}
explicit ChainedByteRange(ByteRange range) : range_(range) {}
/**
* Returns the length only of this ChainedByteRange
@@ -47,7 +47,7 @@ class ChainedByteRangeHead {
range_.advance(n);
}
[[nodiscard]] folly::ByteRange getRange() const {
[[nodiscard]] ByteRange getRange() const {
return range_;
}
@@ -56,7 +56,7 @@ class ChainedByteRangeHead {
}
private:
folly::ByteRange range_;
ByteRange range_;
ChainedByteRange* next_{nullptr};
friend class ChainedByteRangeHead;
};

View File

@@ -778,7 +778,7 @@ FizzCryptoTestFactory::makePacketNumberCipher(fizz::CipherSuite) const {
}
std::unique_ptr<PacketNumberCipher>
FizzCryptoTestFactory::makePacketNumberCipher(folly::ByteRange secret) const {
FizzCryptoTestFactory::makePacketNumberCipher(ByteRange secret) const {
return _makePacketNumberCipher(secret);
}
@@ -789,7 +789,7 @@ void FizzCryptoTestFactory::setMockPacketNumberCipher(
void FizzCryptoTestFactory::setDefault() {
ON_CALL(*this, _makePacketNumberCipher(_))
.WillByDefault(Invoke([&](folly::ByteRange secret) {
.WillByDefault(Invoke([&](ByteRange secret) {
return FizzCryptoFactory::makePacketNumberCipher(secret);
}));
}

View File

@@ -354,11 +354,11 @@ class FizzCryptoTestFactory : public FizzCryptoFactory {
MOCK_METHOD(
std::unique_ptr<PacketNumberCipher>,
_makePacketNumberCipher,
(folly::ByteRange),
(ByteRange),
(const));
std::unique_ptr<PacketNumberCipher> makePacketNumberCipher(
folly::ByteRange secret) const override;
ByteRange secret) const override;
void setMockPacketNumberCipher(
std::unique_ptr<PacketNumberCipher> packetNumberCipher);
@@ -553,11 +553,11 @@ class FakeServerHandshake : public FizzServerHandshake {
writeTrafficSecret_ = folly::IOBuf::copyBuffer(getRandSecret());
}
std::unique_ptr<Aead> buildAead(folly::ByteRange /*secret*/) override {
std::unique_ptr<Aead> buildAead(ByteRange /*secret*/) override {
return createNoOpAead();
}
BufPtr getNextTrafficSecret(folly::ByteRange /*secret*/) const override {
BufPtr getNextTrafficSecret(ByteRange /*secret*/) const override {
return folly::IOBuf::copyBuffer(getRandSecret());
}

View File

@@ -140,7 +140,7 @@ bool FizzClientHandshake::isTLSResumed() const {
Optional<std::vector<uint8_t>> FizzClientHandshake::getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) {
const auto& ems = state_.exporterMasterSecret();
const auto cipherSuite = state_.cipher();
@@ -176,7 +176,7 @@ bool FizzClientHandshake::matchEarlyParameters() {
std::unique_ptr<Aead> FizzClientHandshake::buildAead(
CipherKind kind,
folly::ByteRange secret) {
ByteRange secret) {
bool isEarlyTraffic = kind == CipherKind::ZeroRttWrite;
fizz::CipherSuite cipher =
isEarlyTraffic ? state_.earlyDataParams()->cipher : *state_.cipher();
@@ -198,12 +198,11 @@ std::unique_ptr<Aead> FizzClientHandshake::buildAead(
}
std::unique_ptr<PacketNumberCipher> FizzClientHandshake::buildHeaderCipher(
folly::ByteRange secret) {
ByteRange secret) {
return cryptoFactory_->makePacketNumberCipher(secret);
}
BufPtr FizzClientHandshake::getNextTrafficSecret(
folly::ByteRange secret) const {
BufPtr FizzClientHandshake::getNextTrafficSecret(ByteRange secret) const {
auto deriver =
state_.context()->getFactory()->makeKeyDeriver(*state_.cipher());
auto nextSecret = deriver->expandLabel(

View File

@@ -41,7 +41,7 @@ class FizzClientHandshake : public ClientHandshake {
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) override;
const fizz::client::State& getState() const {
@@ -75,11 +75,10 @@ class FizzClientHandshake : public ClientHandshake {
EncryptionLevel getReadRecordLayerEncryptionLevel() override;
void processSocketData(folly::IOBufQueue& queue) override;
bool matchEarlyParameters() override;
std::unique_ptr<Aead> buildAead(CipherKind kind, folly::ByteRange secret)
override;
std::unique_ptr<Aead> buildAead(CipherKind kind, ByteRange secret) override;
std::unique_ptr<PacketNumberCipher> buildHeaderCipher(
folly::ByteRange secret) override;
BufPtr getNextTrafficSecret(folly::ByteRange secret) const override;
ByteRange secret) override;
BufPtr getNextTrafficSecret(ByteRange secret) const override;
class ActionMoveVisitor;
void processActions(fizz::client::Actions actions);

View File

@@ -314,7 +314,7 @@ TEST_F(ClientHandshakeTest, TestGetExportedKeyingMaterial) {
EXPECT_EQ(ekm->size(), 32);
ekm = handshake->getExportedKeyingMaterial(
"EXPORTER-Some-Label", folly::ByteRange(), 32);
"EXPORTER-Some-Label", ByteRange(), 32);
ASSERT_TRUE(ekm.has_value());
EXPECT_EQ(ekm->size(), 32);
}

View File

@@ -329,7 +329,7 @@ class FakeOneRttHandshakeLayer : public FizzClientHandshake {
return params_;
}
BufPtr getNextTrafficSecret(folly::ByteRange /*secret*/) const override {
BufPtr getNextTrafficSecret(ByteRange /*secret*/) const override {
return folly::IOBuf::copyBuffer(getRandSecret());
}
@@ -382,12 +382,11 @@ class FakeOneRttHandshakeLayer : public FizzClientHandshake {
throw std::runtime_error("matchEarlyParameters not implemented");
}
std::unique_ptr<Aead> buildAead(CipherKind, folly::ByteRange) override {
std::unique_ptr<Aead> buildAead(CipherKind, ByteRange) override {
return createNoOpAead();
}
std::unique_ptr<PacketNumberCipher> buildHeaderCipher(
folly::ByteRange) override {
std::unique_ptr<PacketNumberCipher> buildHeaderCipher(ByteRange) override {
throw std::runtime_error("buildHeaderCipher not implemented");
}
};
@@ -405,7 +404,7 @@ class QuicClientTransportTestBase : public virtual testing::Test {
folly::SocketAddress addr;
Optional<int> err;
TestReadData(folly::ByteRange dataIn, folly::SocketAddress addrIn)
TestReadData(ByteRange dataIn, folly::SocketAddress addrIn)
: udpPacket(folly::IOBuf::copyBuffer(dataIn)),
addr(std::move(addrIn)) {}
@@ -799,7 +798,7 @@ class QuicClientTransportTestBase : public virtual testing::Test {
void deliverDataWithoutErrorCheck(
const folly::SocketAddress& addr,
folly::ByteRange data,
ByteRange data,
bool writes = true) {
ASSERT_TRUE(networkReadCallback);
socketReads.emplace_back(data, addr);
@@ -810,7 +809,7 @@ class QuicClientTransportTestBase : public virtual testing::Test {
}
void deliverDataWithoutErrorCheck(
folly::ByteRange data,
ByteRange data,
bool writes = true,
folly::SocketAddress* peer = nullptr) {
deliverDataWithoutErrorCheck(
@@ -831,7 +830,7 @@ class QuicClientTransportTestBase : public virtual testing::Test {
void deliverData(
const folly::SocketAddress& addr,
folly::ByteRange data,
ByteRange data,
bool writes = true) {
deliverDataWithoutErrorCheck(addr, data, writes);
if (client->getConn().localConnectionError) {
@@ -849,7 +848,7 @@ class QuicClientTransportTestBase : public virtual testing::Test {
}
void deliverData(
folly::ByteRange data,
ByteRange data,
bool writes = true,
folly::SocketAddress* peer = nullptr) {
deliverData(peer == nullptr ? serverAddr : *peer, data, writes);

View File

@@ -57,7 +57,7 @@ std::unique_ptr<Aead> FizzCryptoFactory::makeInitialAead(
}
std::unique_ptr<PacketNumberCipher> FizzCryptoFactory::makePacketNumberCipher(
folly::ByteRange baseSecret) const {
ByteRange baseSecret) const {
auto pnCipher =
makePacketNumberCipher(fizz::CipherSuite::TLS_AES_128_GCM_SHA256);
auto deriver =
@@ -80,7 +80,7 @@ std::unique_ptr<PacketNumberCipher> FizzCryptoFactory::makePacketNumberCipher(
}
}
std::function<bool(folly::ByteRange, folly::ByteRange)>
std::function<bool(ByteRange, ByteRange)>
FizzCryptoFactory::getCryptoEqualFunction() const {
return fizz::CryptoUtils::equal;
}

View File

@@ -27,12 +27,12 @@ class FizzCryptoFactory : public CryptoFactory {
QuicVersion version) const override;
std::unique_ptr<PacketNumberCipher> makePacketNumberCipher(
folly::ByteRange baseSecret) const override;
ByteRange baseSecret) const override;
virtual std::unique_ptr<PacketNumberCipher> makePacketNumberCipher(
fizz::CipherSuite cipher) const;
[[nodiscard]] std::function<bool(folly::ByteRange, folly::ByteRange)>
[[nodiscard]] std::function<bool(ByteRange, ByteRange)>
getCryptoEqualFunction() const override;
std::shared_ptr<fizz::Factory> getFizzFactory() {

View File

@@ -12,7 +12,7 @@ namespace quic {
static void setKeyImpl(
folly::ssl::EvpCipherCtxUniquePtr& context,
const EVP_CIPHER* cipher,
folly::ByteRange key) {
ByteRange key) {
DCHECK_EQ(key.size(), EVP_CIPHER_key_length(cipher));
context.reset(EVP_CIPHER_CTX_new());
if (context == nullptr) {
@@ -26,7 +26,7 @@ static void setKeyImpl(
static HeaderProtectionMask maskImpl(
const folly::ssl::EvpCipherCtxUniquePtr& context,
folly::ByteRange sample) {
ByteRange sample) {
HeaderProtectionMask outMask;
CHECK_EQ(sample.size(), outMask.size());
int outLen = 0;
@@ -42,12 +42,12 @@ static HeaderProtectionMask maskImpl(
return outMask;
}
void Aes128PacketNumberCipher::setKey(folly::ByteRange key) {
void Aes128PacketNumberCipher::setKey(ByteRange key) {
pnKey_ = BufHelpers::copyBuffer(key);
return setKeyImpl(encryptCtx_, EVP_aes_128_ecb(), key);
}
void Aes256PacketNumberCipher::setKey(folly::ByteRange key) {
void Aes256PacketNumberCipher::setKey(ByteRange key) {
pnKey_ = BufHelpers::copyBuffer(key);
return setKeyImpl(encryptCtx_, EVP_aes_256_ecb(), key);
}
@@ -60,13 +60,11 @@ const BufPtr& Aes256PacketNumberCipher::getKey() const {
return pnKey_;
}
HeaderProtectionMask Aes128PacketNumberCipher::mask(
folly::ByteRange sample) const {
HeaderProtectionMask Aes128PacketNumberCipher::mask(ByteRange sample) const {
return maskImpl(encryptCtx_, sample);
}
HeaderProtectionMask Aes256PacketNumberCipher::mask(
folly::ByteRange sample) const {
HeaderProtectionMask Aes256PacketNumberCipher::mask(ByteRange sample) const {
return maskImpl(encryptCtx_, sample);
}

View File

@@ -17,11 +17,11 @@ class Aes128PacketNumberCipher : public PacketNumberCipher {
public:
~Aes128PacketNumberCipher() override = default;
void setKey(folly::ByteRange key) override;
void setKey(ByteRange key) override;
const BufPtr& getKey() const override;
HeaderProtectionMask mask(folly::ByteRange sample) const override;
HeaderProtectionMask mask(ByteRange sample) const override;
size_t keyLength() const override;
@@ -35,11 +35,11 @@ class Aes256PacketNumberCipher : public PacketNumberCipher {
public:
~Aes256PacketNumberCipher() override = default;
void setKey(folly::ByteRange key) override;
void setKey(ByteRange key) override;
const BufPtr& getKey() const override;
HeaderProtectionMask mask(folly::ByteRange sample) const override;
HeaderProtectionMask mask(ByteRange sample) const override;
size_t keyLength() const override;

View File

@@ -49,7 +49,7 @@ class FizzCryptoFactoryTest : public Test {
std::unique_ptr<MockPacketNumberCipher> createMockPacketNumberCipher() {
auto mockPacketNumberCipher = std::make_unique<MockPacketNumberCipher>();
EXPECT_CALL(*mockPacketNumberCipher, setKey(_))
.WillOnce(Invoke([&](folly::ByteRange key) {
.WillOnce(Invoke([&](ByteRange key) {
packetCipherKey_ = folly::IOBuf::copyBuffer(key);
}));
EXPECT_CALL(*mockPacketNumberCipher, keyLength())

View File

@@ -87,7 +87,7 @@ void FizzServerHandshake::processSocketData(folly::IOBufQueue& queue) {
machine_.processSocketData(state_, queue, fizz::Aead::AeadOptions()));
}
std::unique_ptr<Aead> FizzServerHandshake::buildAead(folly::ByteRange secret) {
std::unique_ptr<Aead> FizzServerHandshake::buildAead(ByteRange secret) {
return FizzAead::wrap(fizz::Protocol::deriveRecordAeadWithLabel(
*state_.context()->getFactory(),
*state_.keyScheduler(),
@@ -98,12 +98,11 @@ std::unique_ptr<Aead> FizzServerHandshake::buildAead(folly::ByteRange secret) {
}
std::unique_ptr<PacketNumberCipher> FizzServerHandshake::buildHeaderCipher(
folly::ByteRange secret) {
ByteRange secret) {
return cryptoFactory_->makePacketNumberCipher(secret);
}
BufPtr FizzServerHandshake::getNextTrafficSecret(
folly::ByteRange secret) const {
BufPtr FizzServerHandshake::getNextTrafficSecret(ByteRange secret) const {
auto deriver =
state_.context()->getFactory()->makeKeyDeriver(*state_.cipher());
auto nextSecret = deriver->expandLabel(

View File

@@ -39,10 +39,10 @@ class FizzServerHandshake : public ServerHandshake {
EncryptionLevel getReadRecordLayerEncryptionLevel() override;
void processSocketData(folly::IOBufQueue& queue) override;
std::unique_ptr<Aead> buildAead(folly::ByteRange secret) override;
std::unique_ptr<Aead> buildAead(ByteRange secret) override;
std::unique_ptr<PacketNumberCipher> buildHeaderCipher(
folly::ByteRange secret) override;
BufPtr getNextTrafficSecret(folly::ByteRange secret) const override;
ByteRange secret) override;
BufPtr getNextTrafficSecret(ByteRange secret) const override;
void processAccept() override;
bool processPendingCryptoEvent() override;

View File

@@ -62,9 +62,9 @@ class CryptoFactory {
QuicVersion version) const = 0;
virtual std::unique_ptr<PacketNumberCipher> makePacketNumberCipher(
folly::ByteRange baseSecret) const = 0;
ByteRange baseSecret) const = 0;
[[nodiscard]] virtual std::function<bool(folly::ByteRange, folly::ByteRange)>
[[nodiscard]] virtual std::function<bool(ByteRange, ByteRange)>
getCryptoEqualFunction() const = 0;
virtual ~CryptoFactory() = default;

View File

@@ -48,7 +48,7 @@ class Handshake {
*/
virtual Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) = 0;
virtual void handshakeConfirmed() {

View File

@@ -23,8 +23,8 @@ class MockPacketNumberCipher : public PacketNumberCipher {
public:
virtual ~MockPacketNumberCipher() = default;
MOCK_METHOD(void, setKey, (folly::ByteRange key));
MOCK_METHOD(HeaderProtectionMask, mask, (folly::ByteRange), (const));
MOCK_METHOD(void, setKey, (ByteRange key));
MOCK_METHOD(HeaderProtectionMask, mask, (ByteRange), (const));
MOCK_METHOD(size_t, keyLength, (), (const));
MOCK_METHOD(const BufPtr&, getKey, (), (const));

View File

@@ -87,7 +87,7 @@ void FileQLogger::writeToStream(folly::StringPiece message) {
bool inputConsumed = false;
while (!inputConsumed) {
compressionBuffer_->clear();
folly::ByteRange inputRange(message);
ByteRange inputRange(message);
auto outputRange = folly::MutableByteRange(
compressionBuffer_->writableData(), compressionBuffer_->capacity());
compressionCodec_->compressStream(inputRange, outputRange);
@@ -148,7 +148,7 @@ void FileQLogger::finishStream() {
bool ended = false;
while (!ended) {
compressionBuffer_->clear();
folly::ByteRange inputRange(folly::StringPiece(""));
ByteRange inputRange(folly::StringPiece(""));
auto outputRange = folly::MutableByteRange(
compressionBuffer_->writableData(), compressionBuffer_->capacity());
ended = compressionCodec_->compressStream(

View File

@@ -544,8 +544,7 @@ TEST_F(QuicLossFunctionsTest, TestMarkPacketLoss) {
auto& buffer = stream1->lossBuffer.front();
EXPECT_EQ(buffer.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf->data(), buf->length()),
buffer.data.getHead()->getRange());
ByteRange(buf->data(), buf->length()), buffer.data.getHead()->getRange());
}
bool areEqual(folly::IOBuf* ptr, ChainedByteRangeHead* rch) {
@@ -721,13 +720,13 @@ TEST_F(QuicLossFunctionsTest, TestMarkPacketLossNoMerge) {
auto& buffer1 = stream1->lossBuffer[0];
EXPECT_EQ(buffer1.offset, 0);
EXPECT_EQ(
folly::ByteRange(buf1->data(), buf1->length()),
ByteRange(buf1->data(), buf1->length()),
buffer1.data.getHead()->getRange());
auto& buffer3 = stream1->lossBuffer[1];
EXPECT_EQ(buffer3.offset, 40);
EXPECT_EQ(
folly::ByteRange(buf3->data(), buf3->length()),
ByteRange(buf3->data(), buf3->length()),
buffer3.data.getHead()->getRange());
}
@@ -2557,7 +2556,7 @@ TEST_F(QuicLossFunctionsTest, LossVisitorDSRTest) {
ASSERT_FALSE(retxIter->second->eof);
auto expectedBuf = folly::IOBuf::copyBuffer("grape");
ASSERT_EQ(
folly::ByteRange(expectedBuf->buffer(), expectedBuf->length()),
ByteRange(expectedBuf->buffer(), expectedBuf->length()),
retxIter->second->data.getHead()->getRange());
ASSERT_EQ(stream->currentWriteOffset, bufMetaStartingOffset);

View File

@@ -181,7 +181,7 @@ class QuicServerTransport
*/
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) const override {
return serverConn_->serverHandshakeLayer->getExportedKeyingMaterial(
label, context, keyLength);

View File

@@ -207,7 +207,7 @@ const fizz::server::State& ServerHandshake::getState() const {
Optional<std::vector<uint8_t>> ServerHandshake::getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) {
const auto cipherSuite = state_.cipher();
const auto& ems = state_.exporterMasterSecret();
@@ -521,7 +521,7 @@ void ServerHandshake::processActions(
processPendingEvents();
}
void ServerHandshake::computeCiphers(CipherKind kind, folly::ByteRange secret) {
void ServerHandshake::computeCiphers(CipherKind kind, ByteRange secret) {
std::unique_ptr<Aead> aead = buildAead(secret);
std::unique_ptr<PacketNumberCipher> headerCipher = buildHeaderCipher(secret);
switch (kind) {

View File

@@ -207,7 +207,7 @@ class ServerHandshake : public Handshake {
*/
Optional<std::vector<uint8_t>> getExportedKeyingMaterial(
const std::string& label,
const Optional<folly::ByteRange>& context,
const Optional<ByteRange>& context,
uint16_t keyLength) override;
/**
@@ -219,7 +219,7 @@ class ServerHandshake : public Handshake {
* Given secret_n, returns secret_n+1 to be used for generating the next Aead
* on key updates.
*/
virtual BufPtr getNextTrafficSecret(folly::ByteRange secret) const = 0;
virtual BufPtr getNextTrafficSecret(ByteRange secret) const = 0;
~ServerHandshake() override = default;
@@ -270,7 +270,7 @@ class ServerHandshake : public Handshake {
ZeroRttRead,
};
void computeCiphers(CipherKind kind, folly::ByteRange secret);
void computeCiphers(CipherKind kind, ByteRange secret);
fizz::server::State state_;
fizz::server::ServerStateMachine machine_;
@@ -321,9 +321,9 @@ class ServerHandshake : public Handshake {
virtual EncryptionLevel getReadRecordLayerEncryptionLevel() = 0;
virtual void processSocketData(folly::IOBufQueue& queue) = 0;
virtual std::unique_ptr<Aead> buildAead(folly::ByteRange secret) = 0;
virtual std::unique_ptr<Aead> buildAead(ByteRange secret) = 0;
virtual std::unique_ptr<PacketNumberCipher> buildHeaderCipher(
folly::ByteRange secret) = 0;
ByteRange secret) = 0;
virtual void processAccept() = 0;
/*

View File

@@ -20,7 +20,7 @@ const std::vector<std::string> kCipherContexts = {"RetryToken_V2"};
namespace quic {
TokenGenerator::TokenGenerator(TokenSecret secret) : cipher_(kCipherContexts) {
std::vector<folly::ByteRange> secrets;
std::vector<ByteRange> secrets;
secrets.emplace_back(folly::range(secret));
cipher_.setSecrets(secrets);
}

View File

@@ -402,7 +402,7 @@ TEST_F(ServerHandshakeTest, TestGetExportedKeyingMaterial) {
EXPECT_EQ(ekm->size(), 32);
ekm = handshake->getExportedKeyingMaterial(
"EXPORTER-Some-Label", folly::ByteRange(), 32);
"EXPORTER-Some-Label", ByteRange(), 32);
ASSERT_TRUE(ekm.has_value());
EXPECT_EQ(ekm->size(), 32);
}