Create BackupRecoveryKey wrapper class (to avoid directly expose uniffi generated classes)

This commit is contained in:
ganfra 2022-05-25 14:45:16 +02:00
parent b57dfee77e
commit 7c76ba8184

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.session.crypto.keysbackup
import uniffi.olm.BackupRecoveryKey as InnerBackupRecoveryKey
class BackupRecoveryKey internal constructor(internal val inner: InnerBackupRecoveryKey) {
constructor() : this(InnerBackupRecoveryKey())
companion object {
fun fromBase58(key: String): BackupRecoveryKey {
val inner = InnerBackupRecoveryKey.fromBase58(key)
return BackupRecoveryKey(inner)
}
fun fromBase64(key: String): BackupRecoveryKey {
val inner = InnerBackupRecoveryKey.fromBase64(key)
return BackupRecoveryKey(inner)
}
fun fromPassphrase(passphrase: String, salt: String, rounds: Int): BackupRecoveryKey {
val inner = InnerBackupRecoveryKey.fromPassphrase(passphrase, salt, rounds)
return BackupRecoveryKey(inner)
}
fun newFromPassphrase(passphrase: String): BackupRecoveryKey {
val inner = InnerBackupRecoveryKey.newFromPassphrase(passphrase)
return BackupRecoveryKey(inner)
}
}
override fun equals(other: Any?): Boolean {
if (other !is BackupRecoveryKey) return false
return this.toBase58() == other.toBase58()
}
fun toBase58() = inner.toBase58()
fun toBase64() = inner.toBase64()
fun decryptV1(ephemeralKey: String, mac: String, ciphertext: String) = inner.decryptV1(ephemeralKey, mac, ciphertext)
fun megolmV1PublicKey() = inner.megolmV1PublicKey()
}