Добавлено StorageEncryptionInfo для локальных хранилищ

This commit is contained in:
Roman Pytkov
2025-01-05 02:39:26 +03:00
parent f0f0c0f195
commit 407530e9bb
12 changed files with 194 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
package com.github.nullptroma.wallenc.domain.common.impl
import com.github.nullptroma.wallenc.domain.interfaces.IFile
import com.github.nullptroma.wallenc.domain.interfaces.IMetaInfo
data class CommonFile(override val metaInfo: CommonMetaInfo) : IFile
data class CommonFile(override val metaInfo: IMetaInfo) : IFile

View File

@@ -0,0 +1,6 @@
package com.github.nullptroma.wallenc.domain.datatypes
data class StorageEncryptionInfo(
val isEncrypted: Boolean,
val encryptedTestData: String?
)

View File

@@ -1,6 +1,7 @@
package com.github.nullptroma.wallenc.domain.encrypt
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
import com.github.nullptroma.wallenc.domain.interfaces.ILogger
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
import com.github.nullptroma.wallenc.domain.interfaces.IStorageAccessor
@@ -13,7 +14,6 @@ class EncryptedStorage(
key: EncryptKey,
logger: ILogger,
ioDispatcher: CoroutineDispatcher,
override val isEncrypted: Boolean
) : IStorage {
override val size: StateFlow<Long?>
get() = TODO("Not yet implemented")
@@ -25,6 +25,8 @@ class EncryptedStorage(
get() = TODO("Not yet implemented")
override val isAvailable: StateFlow<Boolean>
get() = TODO("Not yet implemented")
override val encInfo: StateFlow<StorageEncryptionInfo>
get() = TODO("Not yet implemented")
override val accessor: IStorageAccessor =
EncryptedStorageAccessor(source.accessor, key, logger, ioDispatcher)

View File

@@ -191,6 +191,22 @@ class EncryptedStorageAccessor(
return flow
}
override suspend fun getFileInfo(path: String): IFile {
val file = source.getFileInfo(encryptPath(path))
val meta = decryptMeta(file.metaInfo)
return CommonFile(meta)
}
override suspend fun getDirInfo(path: String): IDirectory {
val dir = source.getDirInfo(encryptPath(path))
val meta = decryptMeta(dir.metaInfo)
return CommonDirectory(meta, dir.elementsCount)
}
override suspend fun setHidden(path: String, hidden: Boolean) {
source.setHidden(encryptPath(path), hidden)
}
override suspend fun touchFile(path: String) {
source.touchFile(encryptPath(path))
}

View File

@@ -31,7 +31,9 @@ interface IStorageAccessor {
* @return Поток директорий
*/
fun getDirsFlow(path: String): Flow<DataPackage<List<IDirectory>>>
suspend fun getFileInfo(path: String): IFile
suspend fun getDirInfo(path: String): IDirectory
suspend fun setHidden(path: String, hidden: Boolean)
suspend fun touchFile(path: String)
suspend fun touchDir(path: String)
suspend fun delete(path: String)

View File

@@ -1,13 +1,14 @@
package com.github.nullptroma.wallenc.domain.interfaces
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
import kotlinx.coroutines.flow.StateFlow
import java.util.UUID
sealed interface IStorageInfo {
val uuid: UUID
val isAvailable: StateFlow<Boolean>
val size: StateFlow<Long?>
val numberOfFiles: StateFlow<Int?>
val uuid: UUID
val isEncrypted: Boolean
val name: StateFlow<String>
val isAvailable: StateFlow<Boolean>
val encInfo: StateFlow<StorageEncryptionInfo?>
val name: StateFlow<String?>
}

View File

@@ -1,14 +1,12 @@
package com.github.nullptroma.wallenc.domain.interfaces
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
import kotlinx.coroutines.flow.StateFlow
import java.util.UUID
interface IVault : IVaultInfo {
override val storages: StateFlow<List<IStorage>>
suspend fun createStorage(): IStorage
suspend fun createStorage(key: EncryptKey): IStorage
suspend fun createStorage(key: EncryptKey, uuid: UUID): IStorage
suspend fun createStorage(enc: StorageEncryptionInfo): IStorage
suspend fun remove(storage: IStorage)
}