diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt index 329da6ccc..b98826cb3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDB.kt @@ -25,6 +25,7 @@ import com.kunzisoft.encrypt.aes.AESTransformer import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory +import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.element.entry.EntryKDB import com.kunzisoft.keepass.database.element.group.GroupKDB @@ -32,7 +33,8 @@ import com.kunzisoft.keepass.database.element.icon.IconImageStandard import com.kunzisoft.keepass.database.element.node.NodeIdInt import com.kunzisoft.keepass.database.element.node.NodeIdUUID import com.kunzisoft.keepass.database.element.node.NodeVersioned -import com.kunzisoft.keepass.database.element.MainCredential +import com.kunzisoft.keepass.database.exception.EmptyKeyDatabaseException +import com.kunzisoft.keepass.database.exception.HardwareKeyDatabaseException import java.io.IOException import java.nio.charset.Charset import java.util.* @@ -131,10 +133,10 @@ class DatabaseKDB : DatabaseVersioned() { mainCredential: MainCredential ) { // Exception when no password - if (mainCredential.password == null && mainCredential.keyFileUri == null) - throw IllegalArgumentException("Key cannot be empty.") if (mainCredential.hardwareKey != null) - throw IllegalArgumentException("Hardware key is not supported.") + throw HardwareKeyDatabaseException() + if (mainCredential.password == null && mainCredential.keyFileUri == null) + throw EmptyKeyDatabaseException() // Retrieve plain data val password = mainCredential.password diff --git a/app/src/main/java/com/kunzisoft/keepass/database/exception/DatabaseException.kt b/app/src/main/java/com/kunzisoft/keepass/database/exception/DatabaseException.kt index 4adc2cf5e..6cfd2eaaa 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/exception/DatabaseException.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/exception/DatabaseException.kt @@ -105,6 +105,16 @@ class UnknownDatabaseLocationException : DatabaseException() { override var errorId: Int = R.string.error_location_unknown } +class HardwareKeyDatabaseException : DatabaseException() { + @StringRes + override var errorId: Int = R.string.error_hardware_key_unsupported +} + +class EmptyKeyDatabaseException : DatabaseException() { + @StringRes + override var errorId: Int = R.string.error_empty_key +} + class SignatureDatabaseException : DatabaseInputException() { @StringRes override var errorId: Int = R.string.invalid_db_sig diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e22b2177..cdd6f74f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -205,6 +205,8 @@ Driver for %1$s is required. Unable to merge from a database V1. Database location is unknown, database action cannot be performed. + Hardware key is not supported. + "Key cannot be empty." Field name Field value Could not find file. Try reopening it from your file browser.