diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp index a246558af8bf3a..e5167d05dea768 100644 --- a/src/credentials/CHIPCert.cpp +++ b/src/credentials/CHIPCert.cpp @@ -607,7 +607,10 @@ bool ChipRDN::IsEqual(const ChipRDN & other) const return mString.data_equal(other.mString); } -ChipDN::ChipDN() {} +ChipDN::ChipDN() +{ + Clear(); +} ChipDN::~ChipDN() {} diff --git a/src/credentials/CHIPCert.h b/src/credentials/CHIPCert.h index d95671ee74c3a4..af45c71957fad8 100644 --- a/src/credentials/CHIPCert.h +++ b/src/credentials/CHIPCert.h @@ -193,7 +193,13 @@ struct ChipRDN bool IsEqual(const ChipRDN & other) const; bool IsEmpty() const { return mAttrOID == chip::ASN1::kOID_NotSpecified; } - void Clear() { mAttrOID = chip::ASN1::kOID_NotSpecified; } + void Clear() + { + mAttrOID = chip::ASN1::kOID_NotSpecified; + mAttrIsPrintableString = false; + mChipVal = 0; + mString = CharSpan{}; + } }; /** diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index c84b18db79024c..3725f00acd1a6b 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -220,15 +220,24 @@ static void TestChipCert_ChipDN(nlTestSuite * inSuite, void * inContext) const static CATValues noc_cats = { { 0xABCD0001, chip::kUndefinedCAT, chip::kUndefinedCAT } }; ChipDN chip_dn; + uint8_t certType = kCertType_FirmwareSigning; // Start with non-default value + + NL_TEST_ASSERT(inSuite, chip_dn.IsEmpty()); + NL_TEST_ASSERT(inSuite, chip_dn.RDNCount() == 0); + NL_TEST_ASSERT(inSuite, chip_dn.GetCertType(certType) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, chip_dn.IsEmpty() == true); + NL_TEST_ASSERT(inSuite, certType == kCertType_NotSpecified); + NL_TEST_ASSERT(inSuite, chip_dn.AddAttribute_CommonName(CharSpan(noc_rdn, strlen(noc_rdn)), false) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, chip_dn.AddAttribute_MatterNodeId(0xAAAABBBBCCCCDDDD) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, chip_dn.AddAttribute_MatterFabricId(0xFAB00000FAB00001) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, chip_dn.AddAttribute_GivenName(CharSpan(noc_rdn2, strlen(noc_rdn2)), true) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, chip_dn.AddCATs(noc_cats) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, chip_dn.RDNCount() == 5); NL_TEST_ASSERT(inSuite, chip_dn.AddAttribute_GivenName(CharSpan(noc_rdn2, strlen(noc_rdn2)), true) == CHIP_ERROR_NO_MEMORY); + NL_TEST_ASSERT(inSuite, chip_dn.RDNCount() == 5); - uint8_t certType; NL_TEST_ASSERT(inSuite, chip_dn.GetCertType(certType) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, certType == kCertType_Node);