Skip to content

Commit fa2d1fd

Browse files
committed
samples: matter: lock: Reduce code nesting
Address SonarQube warning regarding code nesting. Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent 47b31c8 commit fa2d1fd

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

samples/matter/lock/src/access/access_manager.cpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,34 @@ bool AccessManager<CRED_BIT_MASK>::ValidatePIN(const Optional<ByteSpan> &pinCode
6767

6868
/* Check the PIN code */
6969
for (size_t index = 1; index <= CONFIG_LOCK_MAX_NUM_CREDENTIALS_PER_TYPE; ++index) {
70-
if (CHIP_NO_ERROR == mCredentials.GetCredentials(CredentialTypeEnum::kPin, credential, index)) {
71-
if (credential.status == DlCredentialStatus::kAvailable) {
72-
continue;
73-
}
74-
75-
if (credential.credentialData.data_equal(pinCode.Value())) {
76-
uint32_t credentialUserId;
77-
if (GetCredentialUserId(index, CredentialTypeEnum::kPin, credentialUserId) ==
78-
CHIP_NO_ERROR) {
79-
result = ValidatePINResult{
80-
.userId = static_cast<uint16_t>(credentialUserId),
81-
.credential = LockOpCredentials{ CredentialTypeEnum::kPin,
82-
static_cast<uint16_t>(index) },
83-
};
84-
} else {
85-
result = {};
86-
}
87-
88-
LOG_DBG("Valid lock PIN code provided");
89-
return true;
90-
}
70+
if (CHIP_NO_ERROR != mCredentials.GetCredentials(CredentialTypeEnum::kPin, credential, index)) {
71+
err = OperationErrorEnum::kInvalidCredential;
72+
continue;
9173
}
92-
err = OperationErrorEnum::kInvalidCredential;
74+
75+
if (credential.status == DlCredentialStatus::kAvailable) {
76+
continue;
77+
}
78+
79+
if (!credential.credentialData.data_equal(pinCode.Value())) {
80+
err = OperationErrorEnum::kInvalidCredential;
81+
continue;
82+
}
83+
84+
uint32_t credentialUserId;
85+
if (GetCredentialUserId(index, CredentialTypeEnum::kPin, credentialUserId) == CHIP_NO_ERROR) {
86+
result = ValidatePINResult{
87+
.userId = static_cast<uint16_t>(credentialUserId),
88+
.credential =
89+
LockOpCredentials{ CredentialTypeEnum::kPin, static_cast<uint16_t>(index) },
90+
};
91+
} else {
92+
result = {};
93+
}
94+
95+
LOG_DBG("Valid lock PIN code provided");
96+
err = OperationErrorEnum::kUnspecified;
97+
return true;
9398
}
9499
LOG_DBG("Invalid lock PIN code provided");
95100
return false;

0 commit comments

Comments
 (0)