Skip to content

Commit

Permalink
detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jan 22, 2025
1 parent 4a4e20d commit 7820b6e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ class BackupScope internal constructor(
restoreWeb
)


@DelicateKaliumApi("this is NOT a backup feature, but a feature to create an unencrypted and obfuscated copy of the database")
val createUnEncryptedCopy: CreateUnEncryptedCopyUseCase
get() = CreateUnEncryptedCopyUseCase(
val createUnEncryptedCopy: CreateObfuscatedCopyUseCase
get() = CreateObfuscatedCopyUseCase(
userId,
clientIdProvider,
userRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ import okio.Source
import okio.buffer
import okio.use

/**
* Creates an obfuscated copy of the user's data.
* TO BE USED FOR DEBUGGING PURPOSES ONLY.
*/
@DelicateKaliumApi("This class is used for debugging purposes only")
class CreateUnEncryptedCopyUseCase internal constructor(
@Suppress("LongParameterList")
class CreateObfuscatedCopyUseCase internal constructor(
private val userId: UserId,
private val clientIdProvider: CurrentClientIdProvider,
private val userRepository: UserRepository,
Expand All @@ -75,13 +80,21 @@ class CreateUnEncryptedCopyUseCase internal constructor(
?: return@withContext CreateBackupResult.Failure(StorageFailure.DataNotFound)

try {
createBackupFile(userId, plainDBPath, backupFilePath).fold(
createBackupFile(
userId,
plainDBPath,
backupFilePath
).fold(
{ error -> CreateBackupResult.Failure(error) },
{ (backupFilePath, backupSize) ->
if (password != null) {
encryptAndCompressFile(backupFilePath, password)
} else CreateBackupResult.Success(backupFilePath, backupSize, backupFilePath.name)
})
} else {
CreateBackupResult.Success(backupFilePath, backupSize, backupFilePath.name)
}
}

)
} finally {
obfuscatedCopyExporter.deleteCopyFile()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.wire.kalium.persistence.UserDatabase
import com.wire.kalium.persistence.dao.UserIDEntity
import com.wire.kalium.persistence.db.support.SupportOpenHelperFactory
import com.wire.kalium.persistence.util.FileNameUtil
import com.wire.kalium.util.FileUtil
import kotlinx.coroutines.CoroutineDispatcher
import net.zetetic.database.sqlcipher.SQLiteDatabase
import java.io.File
Expand Down Expand Up @@ -137,4 +136,3 @@ internal actual fun createEmptyDatabaseFile(
it.absolutePath
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ObfuscatedCopyExporter internal constructor(
)
}

@Suppress("TooGenericExceptionCaught", "ReturnCount")
@Suppress("TooGenericExceptionCaught", "LongMethod")
private suspend fun obfuscatePlainCopy(
plainDBPath: String,
): Boolean = withContext(kaliumDispatcher.io) {
Expand All @@ -96,13 +96,15 @@ class ObfuscatedCopyExporter internal constructor(

try {
plainDBDriver.execute(
null, "UPDATE MessageTextContent " +
null,
"UPDATE MessageTextContent " +
"SET text_body = CASE " +
" WHEN text_body IS NOT NULL " +
" THEN substr(hex(randomblob(length(text_body))), 1, length(text_body)) " +
" ELSE NULL " +
"END " +
"WHERE text_body IS NOT NULL;", 0
"WHERE text_body IS NOT NULL;",
0
)

plainDBDriver.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ internal actual fun createEmptyDatabaseFile(
userId: UserIDEntity,
): String? = TODO()


/**
* Creates an in-memory user database,
* or returns an existing one if it already exists.
Expand Down

0 comments on commit 7820b6e

Please sign in to comment.