Skip to content

Commit

Permalink
Replace virtual destructor with a protected one
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Dec 6, 2023
1 parent adaa141 commit b74bb95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/crypto/CHIPCryptoPAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ CHIP_ERROR Find16BitUpperCaseHexAfterPrefix(const ByteSpan & buffer, const char

} // namespace

Symmetric128BitsKeyHandle::~Symmetric128BitsKeyHandle()
{
ClearSecretData(mContext.mOpaque);
}

using HKDF_sha_crypto = HKDF_sha;

CHIP_ERROR Spake2p::InternalHash(const uint8_t * in, size_t in_len)
Expand Down
16 changes: 7 additions & 9 deletions src/crypto/CHIPCryptoPAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,11 @@ using Symmetric128BitsKeyByteArray = uint8_t[CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BY
*
* @note Symmetric128BitsKeyHandle is an abstract class to force child classes for each key handle type.
* Symmetric128BitsKeyHandle class implements all the necessary components for handles.
* Child classes only need to implement a constructor, implement a destructor and delete all the copy operators.
* Child classes only need to implement a constructor and delete all the copy operators.
*/
class Symmetric128BitsKeyHandle
{
public:
Symmetric128BitsKeyHandle() = default;
// Destructor is implemented in the .cpp. It is pure virtual only to force the class to be abstract.
virtual ~Symmetric128BitsKeyHandle() = 0;

Symmetric128BitsKeyHandle(const Symmetric128BitsKeyHandle &) = delete;
Symmetric128BitsKeyHandle(Symmetric128BitsKeyHandle &&) = delete;
void operator=(const Symmetric128BitsKeyHandle &) = delete;
Expand All @@ -606,6 +602,10 @@ class Symmetric128BitsKeyHandle
return *SafePointerCast<T *>(&mContext);
}

protected:
Symmetric128BitsKeyHandle() = default;
~Symmetric128BitsKeyHandle() { ClearSecretData(mContext.mOpaque); }

private:
static constexpr size_t kContextSize = CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES;

Expand All @@ -618,11 +618,10 @@ class Symmetric128BitsKeyHandle
/**
* @brief Platform-specific AES key handle
*/
class Aes128KeyHandle : public Symmetric128BitsKeyHandle
class Aes128KeyHandle final : public Symmetric128BitsKeyHandle
{
public:
Aes128KeyHandle() = default;
virtual ~Aes128KeyHandle() {}

Aes128KeyHandle(const Aes128KeyHandle &) = delete;
Aes128KeyHandle(Aes128KeyHandle &&) = delete;
Expand All @@ -633,11 +632,10 @@ class Aes128KeyHandle : public Symmetric128BitsKeyHandle
/**
* @brief Platform-specific HMAC key handle
*/
class Hmac128KeyHandle : public Symmetric128BitsKeyHandle
class Hmac128KeyHandle final : public Symmetric128BitsKeyHandle
{
public:
Hmac128KeyHandle() = default;
virtual ~Hmac128KeyHandle() {}

Hmac128KeyHandle(const Hmac128KeyHandle &) = delete;
Hmac128KeyHandle(Hmac128KeyHandle &&) = delete;
Expand Down

0 comments on commit b74bb95

Please sign in to comment.