Force scanned codes to uppercase alpha characters (#85)

This commit is contained in:
Patrick Honkonen 2024-05-07 15:50:43 -04:00 committed by GitHub
parent d9e29d3c81
commit 31669cf457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,8 @@
package com.bitwarden.authenticator.ui.authenticator.feature.qrcodescan
import android.net.Uri
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.toUpperCase
import com.bitwarden.authenticator.data.authenticator.manager.TotpCodeManager
import com.bitwarden.authenticator.data.authenticator.repository.AuthenticatorRepository
import com.bitwarden.authenticator.data.authenticator.repository.model.TotpCodeResult
@ -53,8 +55,12 @@ class QrCodeScanViewModel @Inject constructor(
}
val scannedCodeUri = Uri.parse(scannedCode)
val secretValue = scannedCodeUri.getQueryParameter(TotpCodeManager.SECRET_PARAM)
if (secretValue == null || !secretValue.isBase32()) {
val secretValue = scannedCodeUri
.getQueryParameter(TotpCodeManager.SECRET_PARAM)
.orEmpty()
.toUpperCase(Locale.current)
if (secretValue.isEmpty() || !secretValue.isBase32()) {
authenticatorRepository.emitTotpCodeResult(TotpCodeResult.CodeScanningError)
sendEvent(QrCodeScanEvent.NavigateBack)
return