Skip to content
Snippets Groups Projects
Commit 72da3ab3 authored by Taras's avatar Taras
Browse files

Add restoreBcryptKeyBackupWithPassword

parent c537971d
No related branches found
No related tags found
No related merge requests found
......@@ -907,6 +907,43 @@ internal class DefaultKeysBackupService @Inject constructor(
}
}
override fun restoreBcryptKeyBackupWithPassword(keysBackupVersion: KeysVersionResult,
password: String,
roomId: String?,
sessionId: String?,
stepProgressListener: StepProgressListener?,
callback: MatrixCallback<ImportRoomKeysResult>) {
Timber.v("[MXKeyBackup] restoreKeyBackup with password: From backup version: ${keysBackupVersion.version}")
cryptoCoroutineScope.launch(coroutineDispatchers.io) {
runCatching {
val recoveryKey = withContext(coroutineDispatchers.crypto) {
recoveryBcryptKeyFromPassword(password, keysBackupVersion)
}
if (recoveryKey == null) {
Timber.v("backupKeys: Invalid configuration")
throw IllegalStateException("Invalid configuration")
} else {
awaitCallback<ImportRoomKeysResult> {
restoreBcryptKeysWithRecoveryKey(keysBackupVersion, recoveryKey, roomId, sessionId, stepProgressListener, it)
}
}
}.foldToCallback(object : MatrixCallback<ImportRoomKeysResult> {
override fun onSuccess(data: ImportRoomKeysResult) {
uiHandler.post {
callback.onSuccess(data)
}
}
override fun onFailure(failure: Throwable) {
uiHandler.post {
callback.onFailure(failure)
}
}
})
}
}
/**
* Same method as [RoomKeysRestClient.getRoomKey] except that it accepts nullable
* parameters and always returns a KeysBackupData object through the Callback.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment