mirror of
https://github.com/espressif/openthread.git
synced 2026-09-09 10:40:09 +00:00
[api] harmonize nullptr assert check of pointer input parameters (#8031)
This commit harmonizes and simplifies the code related to asserting that the OT API pointer parameters are valid and not `nullptr`. `OPENTHREAD_CONFIG_ASSERT_CHECK_API_POINTER_PARAM_FOR_NULL` is added which when used performs assert check on all pointer inputs to APIs. This is either done within `AsCoreType()` when the pointer is converted to its related core type, or by a direct call to newly added macro `AssertPointerIsNotNull()`. Since enabling assert checks on every API parameter can increase code size, this config is disabled by default and it is recommended to use it during debugging only.
This commit is contained in:
@@ -51,11 +51,11 @@ void otCryptoHmacSha256(const otCryptoKey *aKey, const uint8_t *aBuf, uint16_t a
|
||||
{
|
||||
HmacSha256 hmac;
|
||||
|
||||
OT_ASSERT((aKey != nullptr) && (aBuf != nullptr) && (aHash != nullptr));
|
||||
AssertPointerIsNotNull(aBuf);
|
||||
|
||||
hmac.Start(AsCoreType(aKey));
|
||||
hmac.Update(aBuf, aBufLength);
|
||||
hmac.Finish(ot::AsCoreType(aHash));
|
||||
hmac.Finish(AsCoreType(aHash));
|
||||
}
|
||||
|
||||
void otCryptoAesCcm(const otCryptoKey *aKey,
|
||||
@@ -71,7 +71,11 @@ void otCryptoAesCcm(const otCryptoKey *aKey,
|
||||
void * aTag)
|
||||
{
|
||||
AesCcm aesCcm;
|
||||
OT_ASSERT((aNonce != nullptr) && (aPlainText != nullptr) && (aCipherText != nullptr) && (aTag != nullptr));
|
||||
|
||||
AssertPointerIsNotNull(aNonce);
|
||||
AssertPointerIsNotNull(aPlainText);
|
||||
AssertPointerIsNotNull(aCipherText);
|
||||
AssertPointerIsNotNull(aTag);
|
||||
|
||||
aesCcm.SetKey(AsCoreType(aKey));
|
||||
aesCcm.Init(aHeaderLength, aLength, aTagLength, aNonce, aNonceLength);
|
||||
@@ -95,6 +99,11 @@ otError otCryptoEcdsaSign(uint8_t * aOutput,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength)
|
||||
{
|
||||
AssertPointerIsNotNull(aOutput);
|
||||
AssertPointerIsNotNull(aOutputLength);
|
||||
AssertPointerIsNotNull(aInputHash);
|
||||
AssertPointerIsNotNull(aPrivateKey);
|
||||
|
||||
return Ecdsa::Sign(aOutput, *aOutputLength, aInputHash, aInputHashLength, aPrivateKey, aPrivateKeyLength);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user