Use the base64 encoding/decoding methods from vodozemac in the bindings

This commit is contained in:
Damir Jelić
2023-09-08 11:02:16 +02:00
parent 72e3079aab
commit c32f2444fc
3 changed files with 3 additions and 12 deletions

1
Cargo.lock generated
View File

@@ -3195,7 +3195,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"assert_matches",
"base64 0.21.2",
"futures-util",
"hmac",
"http",

View File

@@ -18,7 +18,6 @@ bundled-sqlite = ["matrix-sdk-sqlite/bundled"]
[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
futures-util = "0.3.25"
hmac = "0.12.1"
http = { workspace = true }

View File

@@ -1,10 +1,5 @@
use std::sync::Arc;
use base64::{
alphabet,
engine::{general_purpose, GeneralPurpose},
Engine,
};
use futures_util::{Stream, StreamExt};
use matrix_sdk_crypto::{
matrix_sdk_qrcode::QrVerificationData, CancelInfo as RustCancelInfo, QrVerification as InnerQr,
@@ -14,12 +9,10 @@ use matrix_sdk_crypto::{
};
use ruma::events::key::verification::VerificationMethod;
use tokio::runtime::Handle;
use vodozemac::{base64_decode, base64_encode};
use crate::{CryptoStoreError, OutgoingVerificationRequest, SignatureUploadRequest};
const STANDARD_NO_PAD: GeneralPurpose =
GeneralPurpose::new(&alphabet::STANDARD, general_purpose::NO_PAD);
/// Listener that will be passed over the FFI to report changes to a SAS
/// verification.
#[uniffi::export(callback_interface)]
@@ -420,7 +413,7 @@ impl QrCode {
/// decoded on the other side before it can be put through a QR code
/// generator.
pub fn generate_qr_code(&self) -> Option<String> {
self.inner.to_bytes().map(|data| STANDARD_NO_PAD.encode(data)).ok()
self.inner.to_bytes().map(base64_encode).ok()
}
/// Set a listener for changes in the QrCode verification process.
@@ -713,7 +706,7 @@ impl VerificationRequest {
/// * `data` - The data that was extracted from the scanned QR code as an
/// base64 encoded string, without padding.
pub fn scan_qr_code(&self, data: String) -> Option<ScanResult> {
let data = STANDARD_NO_PAD.decode(data).ok()?;
let data = base64_decode(data).ok()?;
let data = QrVerificationData::from_bytes(data).ok()?;
if let Some(qr) = self.runtime.block_on(self.inner.scan_qr_code(data)).ok()? {