Исправлено множество предупреждений
This commit is contained in:
@@ -2,11 +2,7 @@ package com.github.nullptroma.wallenc.domain.encrypt
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.encrypt.Encryptor.Companion.AES_SETTINGS
|
||||
import kotlinx.coroutines.DisposableHandle
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.CipherInputStream
|
||||
import javax.crypto.CipherOutputStream
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import kotlin.io.encoding.Base64
|
||||
@@ -47,22 +43,6 @@ class EncryptorWithStaticIv(private var secretKey: SecretKey, iv: ByteArray) : D
|
||||
return decryptedBytes
|
||||
}
|
||||
|
||||
fun encryptStream(stream: OutputStream): OutputStream {
|
||||
if(secretKey.isDestroyed)
|
||||
throw Exception("Object was destroyed")
|
||||
val cipher = Cipher.getInstance(AES_SETTINGS)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec) // инициализация шифратора
|
||||
return CipherOutputStream(stream, cipher)
|
||||
}
|
||||
|
||||
fun decryptStream(stream: InputStream): InputStream {
|
||||
if(secretKey.isDestroyed)
|
||||
throw Exception("Object was destroyed")
|
||||
val cipher = Cipher.getInstance(AES_SETTINGS)
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec)
|
||||
return CipherInputStream(stream, cipher)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
secretKey.destroy()
|
||||
}
|
||||
|
||||
@@ -10,45 +10,44 @@ sealed class WallencException(
|
||||
) : Exception(message, cause) {
|
||||
|
||||
sealed class Feature : WallencException() {
|
||||
data object StorageNotFound : Feature()
|
||||
data object NeedsDecryptedView : Feature()
|
||||
data object SecretNotFound : Feature()
|
||||
data object StorageNotWritable : Feature()
|
||||
class StorageNotFound : Feature()
|
||||
class NeedsDecryptedView : Feature()
|
||||
class SecretNotFound : Feature()
|
||||
class StorageNotWritable : Feature()
|
||||
}
|
||||
|
||||
sealed class Storage(cause: Throwable? = null) : WallencException(cause = cause) {
|
||||
data object NotAvailable : Storage()
|
||||
data object FileNotFound : Storage()
|
||||
data object IncorrectKey : Storage()
|
||||
class NotAvailable : Storage()
|
||||
class FileNotFound : Storage()
|
||||
class IncorrectKey : Storage()
|
||||
class EncInfoMissing : Storage()
|
||||
class NotEncrypted : Storage()
|
||||
class NotWritable : Storage()
|
||||
class NotAFile : Storage()
|
||||
class NotADirectory : Storage()
|
||||
class PathIsFile : Storage()
|
||||
class CannotWriteOverDirectory : Storage()
|
||||
class DeleteRootForbidden : Storage()
|
||||
class UnexpectedState : Storage()
|
||||
data class IoFailed(override val cause: Throwable) : Storage(cause)
|
||||
data object EncInfoMissing : Storage()
|
||||
data object NotEncrypted : Storage()
|
||||
data object NotWritable : Storage()
|
||||
data object NotAFile : Storage()
|
||||
data object NotADirectory : Storage()
|
||||
data object PathIsFile : Storage()
|
||||
data object CannotWriteOverDirectory : Storage()
|
||||
data object DeleteRootForbidden : Storage()
|
||||
data object UnexpectedState : Storage()
|
||||
}
|
||||
|
||||
/** Ошибки аутентификации (OAuth, токен), без привязки к провайдеру. */
|
||||
sealed class Auth : WallencException() {
|
||||
data object Failed : Auth()
|
||||
data object TokenMissing : Auth()
|
||||
class Failed : Auth()
|
||||
class TokenMissing : Auth()
|
||||
}
|
||||
|
||||
/** Сетевые и удалённые операции (HTTP, блокировки, таймауты). */
|
||||
sealed class Network(cause: Throwable? = null) : WallencException(cause = cause) {
|
||||
data class HttpFailed(
|
||||
val operation: String,
|
||||
val statusCode: Int,
|
||||
override val cause: Throwable? = null,
|
||||
) : Network(cause)
|
||||
|
||||
data class IoFailed(override val cause: Throwable) : Network(cause)
|
||||
data object ResourceLocked : Network()
|
||||
data object OperationFailed : Network()
|
||||
data object OperationTimedOut : Network()
|
||||
class ResourceLocked : Network()
|
||||
class OperationFailed : Network()
|
||||
class OperationTimedOut : Network()
|
||||
}
|
||||
|
||||
data class Unknown(override val cause: Throwable?) : WallencException(cause = cause)
|
||||
|
||||
@@ -5,9 +5,7 @@ import java.io.IOException
|
||||
|
||||
fun Throwable.toWallencException(): WallencException = when (this) {
|
||||
is WallencException -> this
|
||||
is FileNotFoundException -> WallencException.Storage.FileNotFound
|
||||
is FileNotFoundException -> WallencException.Storage.FileNotFound()
|
||||
is IOException -> WallencException.Network.IoFailed(this)
|
||||
else -> WallencException.Unknown(this)
|
||||
}
|
||||
|
||||
fun Throwable.rethrowAsWallencException(): Nothing = throw toWallencException()
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.github.nullptroma.wallenc.domain.interfaces
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface IStorageExplorer {
|
||||
val currentPath: StateFlow<String>
|
||||
|
||||
// TODO
|
||||
// пока бесполезный интерфейс
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.github.nullptroma.wallenc.domain.errors
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
@@ -11,14 +10,14 @@ class WallencExceptionMappingTest {
|
||||
|
||||
@Test
|
||||
fun preservesWallencException() {
|
||||
val original = WallencException.Feature.StorageNotFound
|
||||
val original = WallencException.Feature.StorageNotFound()
|
||||
assertSame(original, original.toWallencException())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mapsFileNotFoundException() {
|
||||
val mapped = FileNotFoundException("missing").toWallencException()
|
||||
assertEquals(WallencException.Storage.FileNotFound, mapped)
|
||||
assertTrue(mapped is WallencException.Storage.FileNotFound)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user