feat: Crash Fix for invalid secret key (#888)

This commit is contained in:
Yogesh Choudhary Paliyal
2024-06-16 17:51:35 +05:30
committed by GitHub
parent 60c195edc0
commit e0a3b7a104
4 changed files with 14 additions and 2 deletions

View File

@@ -1 +1 @@
openjdk64-11.0.11 openjdk64-17.0.7

View File

@@ -31,16 +31,19 @@ import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import com.yogeshpaliyal.common.constants.ScannerType import com.yogeshpaliyal.common.constants.ScannerType
import com.yogeshpaliyal.common.utils.TOTPHelper import com.yogeshpaliyal.common.utils.TOTPHelper
import com.yogeshpaliyal.keypass.R
import com.yogeshpaliyal.keypass.ui.detail.components.BottomBar import com.yogeshpaliyal.keypass.ui.detail.components.BottomBar
import com.yogeshpaliyal.keypass.ui.detail.components.Fields import com.yogeshpaliyal.keypass.ui.detail.components.Fields
import com.yogeshpaliyal.keypass.ui.redux.actions.CopyToClipboard import com.yogeshpaliyal.keypass.ui.redux.actions.CopyToClipboard
import com.yogeshpaliyal.keypass.ui.redux.actions.GoBackAction import com.yogeshpaliyal.keypass.ui.redux.actions.GoBackAction
import com.yogeshpaliyal.keypass.ui.redux.actions.NavigationAction import com.yogeshpaliyal.keypass.ui.redux.actions.NavigationAction
import com.yogeshpaliyal.keypass.ui.redux.actions.ToastAction
import com.yogeshpaliyal.keypass.ui.redux.states.PasswordGeneratorState import com.yogeshpaliyal.keypass.ui.redux.states.PasswordGeneratorState
import org.reduxkotlin.compose.rememberDispatcher import org.reduxkotlin.compose.rememberDispatcher
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.OutputStream import java.io.OutputStream
import java.net.MalformedURLException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
@@ -80,7 +83,13 @@ fun AccountDetailPage(
} }
ScannerType.Secret -> { ScannerType.Secret -> {
it.scannedText ?: return@rememberLauncherForActivityResult it.scannedText ?: return@rememberLauncherForActivityResult
val totp = TOTPHelper(it.scannedText) var totp: TOTPHelper? = null
try {
totp = TOTPHelper(it.scannedText)
} catch (e: MalformedURLException) {
dispatchAction(ToastAction(R.string.invalid_secret_key))
return@rememberLauncherForActivityResult
}
var newAccountModel = accountModel.copy(secret = totp.secret) var newAccountModel = accountModel.copy(secret = totp.secret)
if (newAccountModel.title.isNullOrEmpty()) { if (newAccountModel.title.isNullOrEmpty()) {

View File

@@ -110,5 +110,6 @@
<string name="keepass_backup">KeePass Backup</string> <string name="keepass_backup">KeePass Backup</string>
<string name="keepass_backup_desc">Choose KeePass CSV file to import</string> <string name="keepass_backup_desc">Choose KeePass CSV file to import</string>
<string name="generate_qr_code">Export</string> <string name="generate_qr_code">Export</string>
<string name="invalid_secret_key">Invalid secret key format</string>
</resources> </resources>

View File

@@ -26,4 +26,6 @@ android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false android.nonTransitiveRClass=false
android.nonFinalResIds=false android.nonFinalResIds=false
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true