[common] adding AsCoreType() to covert from public to core types (#6993)

This commit adds header file `common/as_core_type.hpp` which adds
helper functions `AsCoreType()` which help convert from a
public C OpenThread type to its corresponding C++ core type (e.g.,
`otIp6Address` to `Ip6::Address`). This commit also adds `MapEnum()`
function to convert between public and core `enum` definitions (e.g.,
`otMacFilterAddressMode` and `Mac::Filter::Mode`). These helper
function act as syntactic sugar helping simplify the implementations
of OT API functions (in `api/{module}_api.cpp` files).
This commit is contained in:
Abtin Keshavarzian
2021-09-16 21:15:37 -07:00
committed by GitHub
parent 7d91dd19c6
commit 961fd9ae95
49 changed files with 1141 additions and 1714 deletions
+5 -3
View File
@@ -36,6 +36,7 @@
#include <openthread/crypto.h>
#include <openthread/error.h>
#include "common/as_core_type.hpp"
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/locator_getters.hpp"
@@ -43,6 +44,7 @@
#include "crypto/ecdsa.hpp"
#include "crypto/hmac_sha256.hpp"
using namespace ot;
using namespace ot::Crypto;
void otCryptoHmacSha256(const otCryptoKey *aKey, const uint8_t *aBuf, uint16_t aBufLength, otCryptoSha256Hash *aHash)
@@ -51,9 +53,9 @@ void otCryptoHmacSha256(const otCryptoKey *aKey, const uint8_t *aBuf, uint16_t a
OT_ASSERT((aKey != nullptr) && (aBuf != nullptr) && (aHash != nullptr));
hmac.Start(*static_cast<const Key *>(aKey));
hmac.Start(AsCoreType(aKey));
hmac.Update(aBuf, aBufLength);
hmac.Finish(*static_cast<HmacSha256::Hash *>(aHash));
hmac.Finish(ot::AsCoreType(aHash));
}
void otCryptoAesCcm(const otCryptoKey *aKey,
@@ -71,7 +73,7 @@ void otCryptoAesCcm(const otCryptoKey *aKey,
AesCcm aesCcm;
OT_ASSERT((aNonce != nullptr) && (aPlainText != nullptr) && (aCipherText != nullptr) && (aTag != nullptr));
aesCcm.SetKey(*static_cast<const Key *>(aKey));
aesCcm.SetKey(AsCoreType(aKey));
aesCcm.Init(aHeaderLength, aLength, aTagLength, aNonce, aNonceLength);
if (aHeaderLength != 0)