Небольшая чистка
This commit is contained in:
@@ -19,12 +19,12 @@ class Encryptor(private var secretKey: SecretKey) : DisposableHandle {
|
||||
fun encryptString(str: String): String {
|
||||
val bytesToEncrypt = str.toByteArray(Charsets.UTF_8)
|
||||
val encryptedBytes = encryptBytes(bytesToEncrypt)
|
||||
return Base64.Default.encode(encryptedBytes).replace("/", ".")
|
||||
return Base64.encode(encryptedBytes).replace("/", ".")
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
fun decryptString(str: String): String {
|
||||
val bytesToDecrypt = Base64.Default.decode(str.replace(".", "/"))
|
||||
val bytesToDecrypt = Base64.decode(str.replace(".", "/"))
|
||||
val decryptedBytes = decryptBytes(bytesToDecrypt)
|
||||
return String(decryptedBytes, Charsets.UTF_8)
|
||||
}
|
||||
@@ -78,8 +78,8 @@ class Encryptor(private var secretKey: SecretKey) : DisposableHandle {
|
||||
}
|
||||
|
||||
companion object {
|
||||
public const val IV_LEN = 16
|
||||
public const val AES_SETTINGS = "AES/CBC/PKCS5Padding"
|
||||
const val IV_LEN = 16
|
||||
const val AES_SETTINGS = "AES/CBC/PKCS5Padding"
|
||||
private const val TEST_DATA_LEN = 512
|
||||
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
@@ -88,7 +88,7 @@ class Encryptor(private var secretKey: SecretKey) : DisposableHandle {
|
||||
val testData = ByteArray(TEST_DATA_LEN)
|
||||
val encryptedData = encryptor.encryptBytes(testData)
|
||||
return StorageEncryptionInfo(
|
||||
encryptedTestData = Base64.Default.encode(encryptedData),
|
||||
encryptedTestData = Base64.encode(encryptedData),
|
||||
pathIv = if(encryptPath) Random.nextBytes(IV_LEN) else null
|
||||
)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class Encryptor(private var secretKey: SecretKey) : DisposableHandle {
|
||||
fun checkKey(key: EncryptKey, encInfo: StorageEncryptionInfo): Boolean {
|
||||
val encryptor = Encryptor(key.toAesKey())
|
||||
try {
|
||||
val encData = Base64.Default.decode(encInfo.encryptedTestData)
|
||||
val encData = Base64.decode(encInfo.encryptedTestData)
|
||||
val testData = encryptor.decryptBytes(encData)
|
||||
return testData.all { it == 0.toByte() } && testData.size == TEST_DATA_LEN
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ class EncryptorWithStaticIv(private var secretKey: SecretKey, iv: ByteArray) : D
|
||||
fun encryptString(str: String): String {
|
||||
val bytesToEncrypt = str.toByteArray(Charsets.UTF_8)
|
||||
val encryptedBytes = encryptBytes(bytesToEncrypt)
|
||||
return Base64.Default.encode(encryptedBytes).replace("/", ".")
|
||||
return Base64.encode(encryptedBytes).replace("/", ".")
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
fun decryptString(str: String): String {
|
||||
val bytesToDecrypt = Base64.Default.decode(str.replace(".", "/"))
|
||||
val bytesToDecrypt = Base64.decode(str.replace(".", "/"))
|
||||
val decryptedBytes = decryptBytes(bytesToDecrypt)
|
||||
return String(decryptedBytes, Charsets.UTF_8)
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@ interface IUnlockManager {
|
||||
|
||||
suspend fun open(storage: IStorage, key: EncryptKey, rememberPassword: Boolean = true): IStorage
|
||||
suspend fun close(storage: IStorage)
|
||||
suspend fun close(uuid: UUID): Unit
|
||||
suspend fun close(uuid: UUID)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class EncryptorTest {
|
||||
|
||||
val newEncryptor = Encryptor(key2.toAesKey())
|
||||
try {
|
||||
val decryptedText = newEncryptor.decryptString(encryptedText)
|
||||
newEncryptor.decryptString(encryptedText)
|
||||
fail("There is not exception on decrypt with wrong key")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
@@ -84,7 +84,7 @@ class EncryptorTest {
|
||||
|
||||
val newEncryptor = Encryptor(key2.toAesKey())
|
||||
try {
|
||||
val decryptedBytes = newEncryptor.decryptBytes(encryptedBytes)
|
||||
newEncryptor.decryptBytes(encryptedBytes)
|
||||
fail("There is not exception on decrypt with wrong key")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
@@ -130,7 +130,7 @@ class EncryptorTest {
|
||||
try {
|
||||
val streamForDecrypt = ByteArrayInputStream(encryptedData)
|
||||
val decryptedStream = newEncryptor.decryptStream(streamForDecrypt)
|
||||
val decryptedData = decryptedStream.readAllBytes()
|
||||
decryptedStream.readAllBytes()
|
||||
fail("There is not exception on decrypt with wrong key")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
|
||||
@@ -4,4 +4,4 @@ import android.os.Parcelable
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
abstract class ScreenRoute() : Parcelable
|
||||
abstract class ScreenRoute : Parcelable
|
||||
@@ -98,7 +98,6 @@ fun MainScreen(
|
||||
}, exitTransition = {
|
||||
fadeOut(tween(200))
|
||||
}) {
|
||||
val route: LocalVaultRoute = it.toRoute()
|
||||
LocalVaultScreen(
|
||||
modifier = Modifier.padding(innerPaddings),
|
||||
viewModel = localVaultViewModel,
|
||||
|
||||
@@ -6,6 +6,4 @@ import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class RemoteVaultsViewModel @Inject constructor() :
|
||||
ViewModelBase<RemoteVaultsScreenState>(RemoteVaultsScreenState()) {
|
||||
|
||||
}
|
||||
ViewModelBase<RemoteVaultsScreenState>(RemoteVaultsScreenState())
|
||||
@@ -5,5 +5,4 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
||||
@HiltViewModel
|
||||
class SettingsViewModel @javax.inject.Inject constructor() :
|
||||
ViewModelBase<SettingsScreenState>(SettingsScreenState()) {
|
||||
}
|
||||
ViewModelBase<SettingsScreenState>(SettingsScreenState())
|
||||
Reference in New Issue
Block a user