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