mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 10:27:49 +00:00
[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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user