Skip to content

Commit

Permalink
Restyled by clang-format (#22524)
Browse files Browse the repository at this point in the history
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
restyled-io[bot] and restyled-commits authored Sep 10, 2022
1 parent 31f2dc8 commit 6a625ad
Showing 1 changed file with 40 additions and 42 deletions.
82 changes: 40 additions & 42 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,54 +1737,52 @@ void DeviceCommissioner::OnDone(app::ReadClient *)
// Try to parse as much as we can here before returning, even if this is an error.
return_err = (err == CHIP_NO_ERROR) ? return_err : err;

err =
mAttributeCache->ForEachAttribute(OperationalCredentials::Id, [this, &info](const app::ConcreteAttributePath & path) {
// this code is checking if the device is already on the commissioner's fabric.
// if a matching fabric is found, then remember the nodeId so that the commissioner
// can, if it decides to, cancel commissioning (before it fails in AddNoc) and know
// the device's nodeId on its fabric.
switch (path.mAttributeId)
err = mAttributeCache->ForEachAttribute(OperationalCredentials::Id, [this, &info](const app::ConcreteAttributePath & path) {
// this code is checking if the device is already on the commissioner's fabric.
// if a matching fabric is found, then remember the nodeId so that the commissioner
// can, if it decides to, cancel commissioning (before it fails in AddNoc) and know
// the device's nodeId on its fabric.
switch (path.mAttributeId)
{
case OperationalCredentials::Attributes::Fabrics::Id: {
OperationalCredentials::Attributes::Fabrics::TypeInfo::DecodableType fabrics;
ReturnErrorOnFailure(this->mAttributeCache->Get<OperationalCredentials::Attributes::Fabrics::TypeInfo>(path, fabrics));
auto iter = fabrics.begin();
while (iter.Next())
{
case OperationalCredentials::Attributes::Fabrics::Id: {
OperationalCredentials::Attributes::Fabrics::TypeInfo::DecodableType fabrics;
ReturnErrorOnFailure(
this->mAttributeCache->Get<OperationalCredentials::Attributes::Fabrics::TypeInfo>(path, fabrics));
auto iter = fabrics.begin();
while (iter.Next())
auto & fabricDescriptor = iter.GetValue();
ChipLogProgress(AppServer,
"DeviceCommissioner::OnDone - fabric.vendorId=0x%04X fabric.fabricId=0x" ChipLogFormatX64
" fabric.nodeId=0x" ChipLogFormatX64,
fabricDescriptor.vendorId, ChipLogValueX64(fabricDescriptor.fabricId),
ChipLogValueX64(fabricDescriptor.nodeId));
// need to add check for root public key
if (GetFabricId() == fabricDescriptor.fabricId)
{
auto & fabricDescriptor = iter.GetValue();
ChipLogProgress(AppServer,
"DeviceCommissioner::OnDone - fabric.vendorId=0x%04X fabric.fabricId=0x" ChipLogFormatX64
" fabric.nodeId=0x" ChipLogFormatX64,
fabricDescriptor.vendorId, ChipLogValueX64(fabricDescriptor.fabricId),
ChipLogValueX64(fabricDescriptor.nodeId));
// need to add check for root public key
if (GetFabricId() == fabricDescriptor.fabricId)
{
ChipLogProgress(AppServer, "DeviceCommissioner::OnDone - found a matching fabric id");
chip::ByteSpan rootKeySpan = fabricDescriptor.rootPublicKey;
P256PublicKeySpan rootPubKeySpan(rootKeySpan.data());
Crypto::P256PublicKey deviceRootPublicKey(rootPubKeySpan);
ChipLogProgress(AppServer, "DeviceCommissioner::OnDone - found a matching fabric id");
chip::ByteSpan rootKeySpan = fabricDescriptor.rootPublicKey;
P256PublicKeySpan rootPubKeySpan(rootKeySpan.data());
Crypto::P256PublicKey deviceRootPublicKey(rootPubKeySpan);

Crypto::P256PublicKey commissionerRootPublicKey;
if (CHIP_NO_ERROR != GetRootPublicKey(commissionerRootPublicKey))
{
ChipLogError(AppServer, "DeviceCommissioner::OnDone - error reading commissioner root public key");
}
else if (commissionerRootPublicKey.Matches(deviceRootPublicKey))
{
ChipLogProgress(AppServer, "DeviceCommissioner::OnDone - fabric root keys match");
info.nodeId = fabricDescriptor.nodeId;
}
Crypto::P256PublicKey commissionerRootPublicKey;
if (CHIP_NO_ERROR != GetRootPublicKey(commissionerRootPublicKey))
{
ChipLogError(AppServer, "DeviceCommissioner::OnDone - error reading commissioner root public key");
}
else if (commissionerRootPublicKey.Matches(deviceRootPublicKey))
{
ChipLogProgress(AppServer, "DeviceCommissioner::OnDone - fabric root keys match");
info.nodeId = fabricDescriptor.nodeId;
}
}

return CHIP_NO_ERROR;
}
default:
return CHIP_NO_ERROR;
}
});

return CHIP_NO_ERROR;
}
default:
return CHIP_NO_ERROR;
}
});

// Try to parse as much as we can here before returning, even if this is an error.
return_err = err == CHIP_NO_ERROR ? return_err : err;
Expand Down

0 comments on commit 6a625ad

Please sign in to comment.