@@ -126,6 +126,9 @@ bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, CredentialTyp
126
126
{
127
127
return (0 == credentialIndex); // 0 is required index for Programming PIN
128
128
}
129
+
130
+ credentialIndex--;
131
+
129
132
return (credentialIndex < kMaxCredentialsPerUser );
130
133
}
131
134
@@ -484,15 +487,7 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
484
487
485
488
VerifyOrReturnValue (IsValidCredentialType (credentialType), false );
486
489
487
- if (CredentialTypeEnum::kProgrammingPIN == credentialType)
488
- {
489
- VerifyOrReturnValue (IsValidCredentialIndex (credentialIndex, credentialType),
490
- false ); // programming pin index is only index allowed to contain 0
491
- }
492
- else
493
- {
494
- VerifyOrReturnValue (IsValidCredentialIndex (--credentialIndex, credentialType), false ); // otherwise, indices are one-indexed
495
- }
490
+ VerifyOrReturnValue (IsValidCredentialIndex (credentialIndex, credentialType), false );
496
491
497
492
ChipLogProgress (Zcl, " Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d" ,
498
493
to_underlying (credentialType), credentialIndex);
@@ -516,18 +511,18 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
516
511
{
517
512
credential.status = mCredentialInStorage .status ;
518
513
ChipLogDetail (Zcl, " CredentialStatus: %d, CredentialIndex: %d " , (int ) credential.status , credentialIndex);
514
+ if (DlCredentialStatus::kAvailable == credential.status )
515
+ {
516
+ ChipLogDetail (Zcl, " Found unoccupied credential " );
517
+ return true ;
518
+ }
519
519
}
520
520
else
521
521
{
522
522
ChipLogError (Zcl, " Error reading KVS key" );
523
523
return false ;
524
524
}
525
525
526
- if (DlCredentialStatus::kAvailable == credential.status )
527
- {
528
- ChipLogDetail (Zcl, " Found unoccupied credential " );
529
- return true ;
530
- }
531
526
credential.credentialType = mCredentialInStorage .credentialType ;
532
527
credential.credentialData = chip::ByteSpan{ mCredentialInStorage .credentialData , mCredentialInStorage .credentialDataSize };
533
528
credential.createdBy = mCredentialInStorage .createdBy ;
@@ -537,8 +532,7 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
537
532
credential.creationSource = DlAssetSource::kMatterIM ;
538
533
credential.modificationSource = DlAssetSource::kMatterIM ;
539
534
540
- ChipLogDetail (Zcl, " Found occupied credential [type=%u,dataSize=%u]" , to_underlying (credential.credentialType ),
541
- credential.credentialData .size ());
535
+ ChipLogDetail (Zcl, " Found occupied credential" );
542
536
543
537
return true ;
544
538
}
@@ -553,15 +547,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
553
547
554
548
VerifyOrReturnValue (IsValidCredentialType (credentialType), false );
555
549
556
- if (CredentialTypeEnum::kProgrammingPIN == credentialType)
557
- {
558
- VerifyOrReturnValue (IsValidCredentialIndex (credentialIndex, credentialType),
559
- false ); // programming pin index is only index allowed to contain 0
560
- }
561
- else
562
- {
563
- VerifyOrReturnValue (IsValidCredentialIndex (--credentialIndex, credentialType), false ); // otherwise, indices are one-indexed
564
- }
550
+ VerifyOrReturnValue (IsValidCredentialIndex (credentialIndex, credentialType), false );
565
551
566
552
VerifyOrReturnValue (credentialData.size () <= kMaxCredentialSize , false );
567
553
@@ -585,7 +571,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
585
571
// Clear mCredentialInStorage.credentialData
586
572
memset (mCredentialInStorage .credentialData , 0 , kMaxCredentialSize );
587
573
588
- if (( error != CHIP_NO_ERROR) )
574
+ if (error != CHIP_NO_ERROR)
589
575
{
590
576
ChipLogError (Zcl, " Error reading from KVS key" );
591
577
return false ;
@@ -904,17 +890,17 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
904
890
905
891
error = mStorage ->SyncGetKeyValue (userKey.KeyName (), &mUserInStorage , userSize);
906
892
907
- // No user exists at this index
893
+ // User exists at this index
908
894
if (error == CHIP_NO_ERROR)
909
895
{
910
896
chip::StorageKeyName credentialKey = LockUserCredentialMap (userIndex);
911
897
912
- uint16_t credentialSize = CredentialStructSize * mUserInStorage .currentCredentialCount ;
898
+ uint16_t credentialStructSize = CredentialStructSize * mUserInStorage .currentCredentialCount ;
913
899
914
900
// Get array of credential indices and types associated to user
915
- error = mStorage ->SyncGetKeyValue (credentialKey.KeyName (), &mCredentials , credentialSize );
901
+ error = mStorage ->SyncGetKeyValue (credentialKey.KeyName (), &mCredentials , credentialStructSize );
916
902
917
- // No credential data associated with user
903
+ // Credential data associated with user
918
904
if (error == CHIP_NO_ERROR)
919
905
{
920
906
// Loop through each credential attached to the user
@@ -933,7 +919,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
933
919
934
920
error = mStorage ->SyncGetKeyValue (key.KeyName (), &mCredentialInStorage , credentialSize);
935
921
936
- if (( error == CHIP_NO_ERROR) || (error == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND) )
922
+ if (error == CHIP_NO_ERROR)
937
923
{
938
924
if (mCredentialInStorage .status == DlCredentialStatus::kOccupied )
939
925
{
@@ -959,7 +945,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
959
945
}
960
946
}
961
947
}
962
- else
948
+ else if (error != CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
963
949
{
964
950
ChipLogError (Zcl, " Error reading credential" );
965
951
return false ;
0 commit comments