[message] introduce RemoveFooter() (#10012)

This commit is contained in:
Abtin Keshavarzian
2024-04-09 17:06:14 -07:00
committed by GitHub
parent 51b94bb879
commit 30aa3e881d
6 changed files with 19 additions and 15 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ void Message::Finish(void)
if (GetHelpData().mPayloadMarkerSet && (GetHelpData().mHeaderLength == GetLength()))
{
IgnoreError(SetLength(GetLength() - 1));
RemoveFooter(sizeof(uint8_t));
}
WriteBytes(0, &GetHelpData().mHeader, GetOptionStart());
+2
View File
@@ -547,6 +547,8 @@ exit:
return error;
}
void Message::RemoveFooter(uint16_t aLength) { IgnoreError(SetLength(GetLength() - Min(aLength, GetLength()))); }
void Message::GetFirstChunk(uint16_t aOffset, uint16_t &aLength, Chunk &aChunk) const
{
// This method gets the first message chunk (contiguous data
+11
View File
@@ -666,6 +666,17 @@ public:
*/
Error InsertHeader(uint16_t aOffset, uint16_t aLength);
/**
* Removes footer bytes from the end of the message.
*
* The caller should ensure the message contains the bytes to be removed, otherwise as many bytes as available
* will be removed.
*
* @param[in] aLength Number of footer bytes to remove from end of the `Message`.
*
*/
void RemoveFooter(uint16_t aLength);
/**
* Appends bytes to the end of the message.
*
+1 -4
View File
@@ -974,10 +974,7 @@ void Server::ProxyQueryInfo::ReadFrom(const ProxyQuery &aQuery)
SuccessOrAssert(aQuery.Read(aQuery.GetLength() - sizeof(ProxyQueryInfo), *this));
}
void Server::ProxyQueryInfo::RemoveFrom(ProxyQuery &aQuery) const
{
SuccessOrAssert(aQuery.SetLength(aQuery.GetLength() - sizeof(ProxyQueryInfo)));
}
void Server::ProxyQueryInfo::RemoveFrom(ProxyQuery &aQuery) const { aQuery.RemoveFooter(sizeof(ProxyQueryInfo)); }
void Server::ProxyQueryInfo::UpdateIn(ProxyQuery &aQuery) const
{
+1 -4
View File
@@ -465,10 +465,7 @@ void Mpl::Metadata::ReadFrom(const Message &aMessage)
IgnoreError(aMessage.Read(length - sizeof(*this), *this));
}
void Mpl::Metadata::RemoveFrom(Message &aMessage) const
{
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
}
void Mpl::Metadata::RemoveFrom(Message &aMessage) const { aMessage.RemoveFooter(sizeof(*this)); }
void Mpl::Metadata::UpdateIn(Message &aMessage) const { aMessage.Write(aMessage.GetLength() - sizeof(*this), *this); }
+3 -6
View File
@@ -2397,7 +2397,7 @@ Error Mle::ProcessMessageSecurity(Crypto::AesCcm::Mode aMode,
if (aMode == Crypto::AesCcm::kDecrypt)
{
// Skip decrypting the message under fuzz build mode
IgnoreError(aMessage.SetLength(aMessage.GetLength() - kMleSecurityTagSize));
aMessage.RemoveFooter(kMleSecurityTagSize);
ExitNow();
}
#endif
@@ -2412,7 +2412,7 @@ Error Mle::ProcessMessageSecurity(Crypto::AesCcm::Mode aMode,
else
{
VerifyOrExit(aMessage.Compare(aMessage.GetLength() - kMleSecurityTagSize, tag), error = kErrorSecurity);
IgnoreError(aMessage.SetLength(aMessage.GetLength() - kMleSecurityTagSize));
aMessage.RemoveFooter(kMleSecurityTagSize);
}
exit:
@@ -4423,10 +4423,7 @@ void Mle::DelayedResponseMetadata::ReadFrom(const Message &aMessage)
IgnoreError(aMessage.Read(length - sizeof(*this), *this));
}
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
{
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
}
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const { aMessage.RemoveFooter(sizeof(*this)); }
//---------------------------------------------------------------------------------------------------------------------
// TxMessage