Skip to content

Commit

Permalink
Deprecate IsSpanUsable(Span) in favor of !empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple committed Sep 14, 2023
1 parent bc52e53 commit 314e759
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ CHIP_ERROR DeviceAttestationCredsCC13X2_26X2::SignWithDeviceAttestationKey(const
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// In a non-exemplary implementation, the public key is not needed here. It is used here merely because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::SignWithDeviceAttestationKey(const
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// In a non-exemplary implementation, the public key is not needed here. It is used here merely because
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ CHIP_ERROR DeviceAttestationCredsCC32XX::SignWithDeviceAttestationKey(const Byte
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// In a non-exemplary implementation, the public key is not needed here. It is used here merely because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ CHIP_ERROR ExampleSe05xDACProvider::SignWithDeviceAttestationKey(const ByteSpan

ChipLogDetail(Crypto, "Sign using DA key from se05x");

VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_signature_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// Add public key + reference private key (ref to key inside SE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ CHIP_ERROR ExampleSe05xDACProviderv2::SignWithDeviceAttestationKey(const ByteSpa
CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t signature_se05x[Crypto::kMax_ECDSA_Signature_Length_Der] = { 0 };
size_t signature_se05x_len = sizeof(signature_se05x);
VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);

ChipLogDetail(Crypto, "Sign using DA key from se05x (Using internal sign)");

Expand Down
4 changes: 2 additions & 2 deletions examples/virtual-device-app/android/java/JNIDACProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ CHIP_ERROR JNIDACProvider::SignWithDeviceAttestationKey(const ByteSpan & digest_
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(digest_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!digest_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_signature_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

uint8_t privateKeyBuf[Crypto::kP256_PrivateKey_Length];
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ CHIP_ERROR DefaultOTARequestor::ExtractUpdateDescription(const QueryImageRespons

VerifyOrReturnError(response.imageURI.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
ReturnErrorOnFailure(bdx::ParseURI(response.imageURI.Value(), nodeId, fileDesignator));
VerifyOrReturnError(IsSpanUsable(fileDesignator), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!fileDesignator.empty(), CHIP_ERROR_INVALID_ARGUMENT);
update.nodeId = nodeId;
update.fileDesignator = fileDesignator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace
*/
CHIP_ERROR SetProductIdentifierValue(chip::CharSpan aProductIdentifierValue)
{
VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!aProductIdentifierValue.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(aProductIdentifierValue.size() <= sizeof(productIdentifierValueBuffer), CHIP_ERROR_INVALID_ARGUMENT);

memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size());
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/credentials/TestHarnessDACProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ CHIP_ERROR TestHarnessDACProvider::SignWithDeviceAttestationKey(const ByteSpan &
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_signature_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// In a non-exemplary implementation, the public key is not needed here. It is used here merely because
Expand Down
4 changes: 2 additions & 2 deletions src/credentials/examples/DeviceAttestationCredsExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ CHIP_ERROR ExampleDACProvider::SignWithDeviceAttestationKey(const ByteSpan & mes
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_signature_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

// In a non-exemplary implementation, the public key is not needed here. It is used here merely because
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/CHIPCryptoPAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CHIP_ERROR ReadDerUnsignedIntegerIntoRaw(Reader & reader, MutableByteSpan raw_in
CHIP_ERROR ConvertIntegerRawToDerInternal(const ByteSpan & raw_integer, MutableByteSpan & out_der_integer,
bool include_tag_and_length)
{
if (!IsSpanUsable(raw_integer) || !IsSpanUsable(out_der_integer))
if (raw_integer.empty() || out_der_integer.empty())
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
Expand Down
13 changes: 4 additions & 9 deletions src/lib/support/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,10 @@ inline bool Span<T>::data_equal(const FixedSpan<U, N> & other) const
return other.data_equal(*this);
}

/**
* @brief Returns true if the `span` could be used to access some data,
* false otherwise.
* @param[in] span The Span to validate.
*/
template <typename T>
inline bool IsSpanUsable(const Span<T> & span)
[[deprecated("Use !empty()")]] inline bool IsSpanUsable(const Span<T> & span)
{
return (span.data() != nullptr) && (span.size() > 0);
return !span.empty();
}

template <typename T, size_t N>
Expand All @@ -318,7 +313,7 @@ using MutableCharSpan = Span<char>;

inline CHIP_ERROR CopySpanToMutableSpan(ByteSpan span_to_copy, MutableByteSpan & out_buf)
{
VerifyOrReturnError(IsSpanUsable(span_to_copy), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!span_to_copy.empty(), CHIP_ERROR_INVALID_ARGUMENT); // why?
VerifyOrReturnError(out_buf.size() >= span_to_copy.size(), CHIP_ERROR_BUFFER_TOO_SMALL);

memcpy(out_buf.data(), span_to_copy.data(), span_to_copy.size());
Expand All @@ -329,7 +324,7 @@ inline CHIP_ERROR CopySpanToMutableSpan(ByteSpan span_to_copy, MutableByteSpan &

inline CHIP_ERROR CopyCharSpanToMutableCharSpan(CharSpan cspan_to_copy, MutableCharSpan & out_buf)
{
VerifyOrReturnError(IsSpanUsable(cspan_to_copy), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!cspan_to_copy.empty(), CHIP_ERROR_INVALID_ARGUMENT); // why?
VerifyOrReturnError(out_buf.size() >= cspan_to_copy.size(), CHIP_ERROR_BUFFER_TOO_SMALL);

memcpy(out_buf.data(), cspan_to_copy.data(), cspan_to_copy.size());
Expand Down
8 changes: 0 additions & 8 deletions src/lib/support/tests/TestSpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ static void TestByteSpan(nlTestSuite * inSuite, void * inContext)
uint8_t arr[] = { 1, 2, 3 };

ByteSpan s0 = ByteSpan();
NL_TEST_ASSERT(inSuite, s0.data() == nullptr);
NL_TEST_ASSERT(inSuite, s0.size() == 0);
NL_TEST_ASSERT(inSuite, s0.empty());
NL_TEST_ASSERT(inSuite, s0.data_equal(s0));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s0) == false);

ByteSpan s1(arr, 2);
NL_TEST_ASSERT(inSuite, s1.data() == arr);
NL_TEST_ASSERT(inSuite, s1.size() == 2);
NL_TEST_ASSERT(inSuite, !s1.empty());
NL_TEST_ASSERT(inSuite, s1.data_equal(s1));
NL_TEST_ASSERT(inSuite, !s1.data_equal(s0));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s1) == true);

ByteSpan s2(arr);
NL_TEST_ASSERT(inSuite, s2.data() == arr);
Expand All @@ -55,7 +52,6 @@ static void TestByteSpan(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, !s2.empty());
NL_TEST_ASSERT(inSuite, s2.data_equal(s2));
NL_TEST_ASSERT(inSuite, !s2.data_equal(s1));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s2) == true);
NL_TEST_ASSERT(inSuite, s2.front() == 1);
NL_TEST_ASSERT(inSuite, s2.back() == 3);
NL_TEST_ASSERT(inSuite, s2[0] == 1);
Expand All @@ -68,7 +64,6 @@ static void TestByteSpan(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, s3.data()[2] == 3);
NL_TEST_ASSERT(inSuite, !s3.empty());
NL_TEST_ASSERT(inSuite, s3.data_equal(s2));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s3) == true);

uint8_t arr2[] = { 3, 2, 1 };
ByteSpan s4(arr2);
Expand All @@ -93,19 +88,16 @@ static void TestMutableByteSpan(nlTestSuite * inSuite, void * inContext)
uint8_t arr[] = { 1, 2, 3 };

MutableByteSpan s0 = MutableByteSpan();
NL_TEST_ASSERT(inSuite, s0.data() == nullptr);
NL_TEST_ASSERT(inSuite, s0.size() == 0);
NL_TEST_ASSERT(inSuite, s0.empty());
NL_TEST_ASSERT(inSuite, s0.data_equal(s0));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s0) == false);

MutableByteSpan s1(arr, 2);
NL_TEST_ASSERT(inSuite, s1.data() == arr);
NL_TEST_ASSERT(inSuite, s1.size() == 2);
NL_TEST_ASSERT(inSuite, !s1.empty());
NL_TEST_ASSERT(inSuite, s1.data_equal(s1));
NL_TEST_ASSERT(inSuite, !s1.data_equal(s0));
NL_TEST_ASSERT(inSuite, IsSpanUsable(s1) == true);

MutableByteSpan s2(arr);
NL_TEST_ASSERT(inSuite, s2.data() == arr);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ASR/ASRFactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ CHIP_ERROR ASRFactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan &
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!outSignBuffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!messageToSign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

#if !CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Ameba/AmebaOTAImageProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ CHIP_ERROR AmebaOTAImageProcessor::ProcessHeader(ByteSpan & block)

CHIP_ERROR AmebaOTAImageProcessor::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Ameba/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & me
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!outSignBuffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!messageToSign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

if (kReadFromFlash)
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Beken/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/ESP32FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ CHIP_ERROR ESP32FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!outSignBuffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!messageToSign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

uint8_t privKeyBuf[kDACPrivateKeySize];
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/ESP32SecureCertDACProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ CHIP_ERROR ESP32SecureCertDACProvider ::SignWithDeviceAttestationKey(const ByteS
CHIP_ERROR chipError;
Crypto::P256ECDSASignature signature;

VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!outSignBuffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!messageToSign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

esp_err = esp_secure_cert_get_priv_key_type(&keyType);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down Expand Up @@ -366,7 +366,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessHeader(ByteSpan & block)
CHIP_ERROR OTAImageProcessorImpl::InitEncryptedOTA(const CharSpan & key)
{
VerifyOrReturnError(mEncryptedOTAEnabled == false, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(IsSpanUsable(key), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!key.empty(), CHIP_ERROR_INVALID_ARGUMENT);

mKey = key;
mEncryptedOTAEnabled = true;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

CHIP_ERROR BLEManagerImpl::ConfigureScanResponseData(ByteSpan data)
{
if (!IsSpanUsable(data) || data.size() > MAX_SCAN_RSP_DATA_LEN)
if (data.empty() || data.size() > MAX_SCAN_RSP_DATA_LEN)
{
ChipLogError(DeviceLayer, "scan response data is invalid");
return CHIP_ERROR_INVALID_ARGUMENT;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Infineon/CYW30739/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & me
Crypto::P256ECDSASignature signature;
Crypto::P256Keypair keypair;

VerifyOrReturnError(IsSpanUsable(out_signature_buffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(message_to_sign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!out_signature_buffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!message_to_sign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(out_signature_buffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

uint8_t dac_key_buffer[128];
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Infineon/CYW30739/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
return;
}

if (IsSpanUsable(block))
if (!block.empty())
{
const uint32_t written =
wiced_firmware_upgrade_process_block(imageProcessor->mParams.downloadedBytes, block.data(), block.size());
Expand Down Expand Up @@ -247,7 +247,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessHeader(ByteSpan & block)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Infineon/PSOC6/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessHeader(ByteSpan & block)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/cc13xx_26xx/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/mbed/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mt793x/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
return;
}

if (IsSpanUsable(block))
if (!block.empty())
{
filogic_ota_state_t filogic_err;
filogic_ota_io_write_sync(imageProcessor->mFilogicCtx, block.data(), block.size(), &filogic_err);
Expand All @@ -179,7 +179,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
// // Store block data for HandleProcessBlock to access
CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
ReleaseBlock();
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/k32w/common/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if (!IsSpanUsable(block))
if (block.empty())
{
return CHIP_NO_ERROR;
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/nxp/k32w/k32w0/FactoryDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ CHIP_ERROR FactoryDataProviderImpl::SignWithDacKey(const ByteSpan & messageToSig
Crypto::P256Keypair keypair;
Crypto::P256SerializedKeypair serializedKeypair;

VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!outSignBuffer.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!messageToSign.empty(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL);

/* Get private key of DAC certificate from reserved section */
Expand Down
Loading

0 comments on commit 314e759

Please sign in to comment.