Skip to content

Commit

Permalink
fix PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xylophone21 committed Mar 25, 2022
1 parent 5f60bbf commit 060fafc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/platform/android/AndroidChipPlatform-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ JNI_METHOD(jboolean, updateCommissionableDataProviderData)
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CommissionableDataProviderMgrImpl().Update(env, spake2pVerifierBase64, Spake2pSaltBase64,
spake2pIterationCount, setupPasscode, discriminator);


if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to update commissionable data provider data: %s", ErrorStr(err));
return false;
}

return err == CHIP_NO_ERROR;
return true;
}
14 changes: 7 additions & 7 deletions src/platform/android/CommissionableDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,32 @@ CHIP_ERROR CommissionableDataProviderImpl::Update(JNIEnv * env, jstring spake2pV
}

// Set to global CommissionableDataProvider once success first time
if (!mIsInitialized)
if (!mFirstUpdated)
{
DeviceLayer::SetCommissionableDataProvider(this);
}
mIsInitialized = true;
mFirstUpdated = true;

return CHIP_NO_ERROR;
}

CHIP_ERROR CommissionableDataProviderImpl::GetSetupDiscriminator(uint16_t & setupDiscriminator)
{
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE);
setupDiscriminator = mDiscriminator;
return CHIP_NO_ERROR;
}

CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pIterationCount(uint32_t & iterationCount)
{
VerifyOrReturnLogError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnLogError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE);
iterationCount = mPaseIterationCount;
return CHIP_NO_ERROR;
}

CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pSalt(chip::MutableByteSpan & saltBuf)
{
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE);

VerifyOrReturnError(saltBuf.size() >= kSpake2p_Max_PBKDF_Salt_Length, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(saltBuf.data(), mPaseSalt.data(), mPaseSalt.size());
Expand All @@ -191,7 +191,7 @@ CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pSalt(chip::MutableByteSpan

CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pVerifier(chip::MutableByteSpan & verifierBuf, size_t & outVerifierLen)
{
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE);

// By now, serialized verifier from Init should be correct size
VerifyOrReturnError(mSerializedPaseVerifier.size() == kSpake2p_VerifierSerialized_Length, CHIP_ERROR_INTERNAL);
Expand All @@ -206,7 +206,7 @@ CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pVerifier(chip::MutableByteS

CHIP_ERROR CommissionableDataProviderImpl::GetSetupPasscode(uint32_t & setupPasscode)
{
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE);

// Pretend not implemented if we don't have a passcode value externally set
if (!mSetupPasscode.HasValue())
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/CommissionableDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CommissionableDataProviderImpl : public chip::DeviceLayer::CommissionableD
private:
friend CommissionableDataProviderImpl & CommissionableDataProviderMgrImpl();
static CommissionableDataProviderImpl sInstance;
bool mIsInitialized = false;
bool mFirstUpdated = false;
std::vector<uint8_t> mSerializedPaseVerifier;
std::vector<uint8_t> mPaseSalt;
uint32_t mPaseIterationCount = 0;
Expand Down

0 comments on commit 060fafc

Please sign in to comment.