Skip to content

Commit

Permalink
Restlyed the code
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Jan 12, 2024
1 parent 9a27932 commit 0e34be0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,7 @@ class OpCredsFabricTableDelegate : public chip::FabricTable::Delegate
}

// Gets called when a fabric is added/updated, but not necessarily committed to storage
void OnFabricUpdated(const FabricTable & fabricTable, FabricIndex fabricIndex) override
{
NotifyFabricTableChanged();
}
void OnFabricUpdated(const FabricTable & fabricTable, FabricIndex fabricIndex) override { NotifyFabricTableChanged(); }

// Gets called when a fabric in FabricTable is persisted to storage
void OnFabricCommitted(const FabricTable & fabricTable, FabricIndex fabricIndex) override
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ static_library("credentials") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform",
"${chip_root}/src/protocols:type_definitions",
"${chip_root}/src/tracing",
"${chip_root}/src/tracing:macros",
"${chip_root}/src/protocols:type_definitions",
"${nlassert_root}:nlassert",
]
}
Expand Down
34 changes: 17 additions & 17 deletions src/credentials/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ CHIP_ERROR FabricTable::ValidateIncomingNOCChain(const ByteSpan & noc, const Byt
NodeId & outNodeId, Crypto::P256PublicKey & outNocPubkey,
Crypto::P256PublicKey & outRootPubkey)
{
MATTER_TRACE_SCOPE("ValidateIncomingNOCChain","Fabric");
MATTER_TRACE_SCOPE("ValidateIncomingNOCChain", "Fabric");
Credentials::ValidationContext validContext;

// Note that we do NOT set a time in the validation context. This will
Expand Down Expand Up @@ -330,15 +330,15 @@ CHIP_ERROR FabricTable::ValidateIncomingNOCChain(const ByteSpan & noc, const Byt

CHIP_ERROR FabricInfo::SignWithOpKeypair(ByteSpan message, P256ECDSASignature & outSignature) const
{
MATTER_TRACE_SCOPE("SignWithOpKeypair","Fabric");
MATTER_TRACE_SCOPE("SignWithOpKeypair", "Fabric");
VerifyOrReturnError(mOperationalKey != nullptr, CHIP_ERROR_KEY_NOT_FOUND);

return mOperationalKey->ECDSA_sign_msg(message.data(), message.size(), outSignature);
}

CHIP_ERROR FabricInfo::FetchRootPubkey(Crypto::P256PublicKey & outPublicKey) const
{
MATTER_TRACE_SCOPE("FetchRootPubKey","Fabric");
MATTER_TRACE_SCOPE("FetchRootPubKey", "Fabric");
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_KEY_NOT_FOUND);
outPublicKey = mRootPublicKey;
return CHIP_NO_ERROR;
Expand All @@ -349,7 +349,7 @@ CHIP_ERROR FabricTable::VerifyCredentials(FabricIndex fabricIndex, const ByteSpa
FabricId & outFabricId, NodeId & outNodeId, Crypto::P256PublicKey & outNocPubkey,
Crypto::P256PublicKey * outRootPublicKey) const
{
MATTER_TRACE_SCOPE("VerifyCredentials","Fabric");
MATTER_TRACE_SCOPE("VerifyCredentials", "Fabric");
assertChipStackLockedByCurrentThread();
uint8_t rootCertBuf[kMaxCHIPCertLength];
MutableByteSpan rootCertSpan{ rootCertBuf };
Expand Down Expand Up @@ -567,14 +567,14 @@ const FabricInfo * FabricTable::FindFabricWithCompressedId(CompressedFabricId co

CHIP_ERROR FabricTable::FetchRootCert(FabricIndex fabricIndex, MutableByteSpan & outCert) const
{
MATTER_TRACE_SCOPE("FetchRootCert","Fabric");
MATTER_TRACE_SCOPE("FetchRootCert", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
return mOpCertStore->GetCertificate(fabricIndex, CertChainElement::kRcac, outCert);
}

CHIP_ERROR FabricTable::FetchPendingNonFabricAssociatedRootCert(MutableByteSpan & outCert) const
{
MATTER_TRACE_SCOPE("FetchPendingNonFabricAssociatedRootCert","Fabric");
MATTER_TRACE_SCOPE("FetchPendingNonFabricAssociatedRootCert", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
if (!mStateFlags.Has(StateFlags::kIsTrustedRootPending))
{
Expand All @@ -593,7 +593,7 @@ CHIP_ERROR FabricTable::FetchPendingNonFabricAssociatedRootCert(MutableByteSpan

CHIP_ERROR FabricTable::FetchICACert(FabricIndex fabricIndex, MutableByteSpan & outCert) const
{
MATTER_TRACE_SCOPE("FetchICACert","Fabric");
MATTER_TRACE_SCOPE("FetchICACert", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);

CHIP_ERROR err = mOpCertStore->GetCertificate(fabricIndex, CertChainElement::kIcac, outCert);
Expand All @@ -613,14 +613,14 @@ CHIP_ERROR FabricTable::FetchICACert(FabricIndex fabricIndex, MutableByteSpan &

CHIP_ERROR FabricTable::FetchNOCCert(FabricIndex fabricIndex, MutableByteSpan & outCert) const
{
MATTER_TRACE_SCOPE("FetchNOCCert","Fabric");
MATTER_TRACE_SCOPE("FetchNOCCert", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
return mOpCertStore->GetCertificate(fabricIndex, CertChainElement::kNoc, outCert);
}

CHIP_ERROR FabricTable::FetchRootPubkey(FabricIndex fabricIndex, Crypto::P256PublicKey & outPublicKey) const
{
MATTER_TRACE_SCOPE("FetchRootPubkey","Fabric");
MATTER_TRACE_SCOPE("FetchRootPubkey", "Fabric");
const FabricInfo * fabricInfo = FindFabricWithIndex(fabricIndex);
ReturnErrorCodeIf(fabricInfo == nullptr, CHIP_ERROR_INVALID_FABRIC_INDEX);
return fabricInfo->FetchRootPubkey(outPublicKey);
Expand Down Expand Up @@ -758,7 +758,7 @@ class NotBeforeCollector : public Credentials::CertificateValidityPolicy

CHIP_ERROR FabricTable::NotifyFabricUpdated(FabricIndex fabricIndex)
{
MATTER_TRACE_SCOPE("NotifyFabricUpdated","Fabric");
MATTER_TRACE_SCOPE("NotifyFabricUpdated", "Fabric");
FabricTable::Delegate * delegate = mDelegateListRoot;
while (delegate)
{
Expand All @@ -773,7 +773,7 @@ CHIP_ERROR FabricTable::NotifyFabricUpdated(FabricIndex fabricIndex)

CHIP_ERROR FabricTable::NotifyFabricCommitted(FabricIndex fabricIndex)
{
MATTER_TRACE_SCOPE("NotifyFabricCommitted","Fabric");
MATTER_TRACE_SCOPE("NotifyFabricCommitted", "Fabric");

FabricTable::Delegate * delegate = mDelegateListRoot;
while (delegate)
Expand Down Expand Up @@ -933,7 +933,7 @@ FabricTable::AddOrUpdateInner(FabricIndex fabricIndex, bool isAddition, Crypto::

CHIP_ERROR FabricTable::Delete(FabricIndex fabricIndex)
{
MATTER_TRACE_SCOPE("Delete","Fabric");
MATTER_TRACE_SCOPE("Delete", "Fabric");
VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_ARGUMENT);

Expand Down Expand Up @@ -1623,7 +1623,7 @@ CHIP_ERROR FabricTable::AddNewPendingTrustedRootCert(const ByteSpan & rcac)
CHIP_ERROR FabricTable::FindExistingFabricByNocChaining(FabricIndex pendingFabricIndex, const ByteSpan & noc,
FabricIndex & outMatchingFabricIndex) const
{
MATTER_TRACE_SCOPE("FindExistingFabricByNocChaining","Fabric");
MATTER_TRACE_SCOPE("FindExistingFabricByNocChaining", "Fabric");
// Check whether we already have a matching fabric from a cert chain perspective.
// To do so we have to extract the FabricID from the NOC and the root public key from the RCAC.
// We assume the RCAC is currently readable from OperationalCertificateStore, whether pending
Expand Down Expand Up @@ -1669,7 +1669,7 @@ CHIP_ERROR FabricTable::AddNewPendingFabricCommon(const ByteSpan & noc, const By
Crypto::P256Keypair * existingOpKey, bool isExistingOpKeyExternallyOwned,
AdvertiseIdentity advertiseIdentity, FabricIndex * outNewFabricIndex)
{
MATTER_TRACE_SCOPE("AddNewPendingFabricCommon","Fabric");
MATTER_TRACE_SCOPE("AddNewPendingFabricCommon", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(outNewFabricIndex != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
static_assert(kMaxValidFabricIndex <= UINT8_MAX, "Cannot create more fabrics than UINT8_MAX");
Expand Down Expand Up @@ -1741,7 +1741,7 @@ CHIP_ERROR FabricTable::UpdatePendingFabricCommon(FabricIndex fabricIndex, const
Crypto::P256Keypair * existingOpKey, bool isExistingOpKeyExternallyOwned,
AdvertiseIdentity advertiseIdentity)
{
MATTER_TRACE_SCOPE("UpdatePendingFabricCommon","Fabric");
MATTER_TRACE_SCOPE("UpdatePendingFabricCommon", "Fabric");
VerifyOrReturnError(mOpCertStore != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_ARGUMENT);

Expand Down Expand Up @@ -2027,7 +2027,7 @@ CHIP_ERROR FabricTable::CommitPendingFabricData()

void FabricTable::RevertPendingFabricData()
{
MATTER_TRACE_SCOPE("RevertPendingFabricData","Fabric");
MATTER_TRACE_SCOPE("RevertPendingFabricData", "Fabric");
// Will clear pending UpdateNoc/AddNOC
RevertPendingOpCertsExceptRoot();

Expand All @@ -2050,7 +2050,7 @@ void FabricTable::RevertPendingFabricData()

void FabricTable::RevertPendingOpCertsExceptRoot()
{
MATTER_TRACE_SCOPE("RevertPendingOpCertsExceptRoot","Fabric");
MATTER_TRACE_SCOPE("RevertPendingOpCertsExceptRoot", "Fabric");
mPendingFabric.Reset();

if (mStateFlags.Has(StateFlags::kIsPendingFabricDataPresent))
Expand Down

0 comments on commit 0e34be0

Please sign in to comment.