mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-25 17:49:58 -04:00
chore: Upgrade base64
This commit is contained in:
committed by
Jonas Platte
parent
2e30e11101
commit
f4bfbdf97d
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -2672,7 +2672,7 @@ dependencies = [
|
||||
"assert_matches",
|
||||
"async-trait",
|
||||
"atomic",
|
||||
"base64 0.13.1",
|
||||
"base64 0.20.0",
|
||||
"bs58",
|
||||
"byteorder",
|
||||
"cfg-if",
|
||||
@@ -2709,7 +2709,7 @@ name = "matrix-sdk-crypto-ffi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.13.1",
|
||||
"base64 0.20.0",
|
||||
"futures-util",
|
||||
"hmac",
|
||||
"http",
|
||||
@@ -2807,7 +2807,7 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"base64 0.13.1",
|
||||
"base64 0.20.0",
|
||||
"dashmap",
|
||||
"derive_builder",
|
||||
"getrandom 0.2.8",
|
||||
@@ -2849,7 +2849,7 @@ dependencies = [
|
||||
name = "matrix-sdk-qrcode"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"base64 0.20.0",
|
||||
"byteorder",
|
||||
"image 0.23.14",
|
||||
"qrcode",
|
||||
|
||||
@@ -22,7 +22,7 @@ rust-version = "1.65"
|
||||
anyhow = "1.0.68"
|
||||
async-stream = "0.3.3"
|
||||
async-trait = "0.1.60"
|
||||
base64 = "0.13.0"
|
||||
base64 = "0.20.0"
|
||||
byteorder = "1.4.3"
|
||||
ctor = "0.1.26"
|
||||
dashmap = "5.2.0"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use base64::{decode_config, encode_config, STANDARD_NO_PAD};
|
||||
use base64::{
|
||||
alphabet, decode_engine, encode_engine,
|
||||
engine::fast_portable::{self, FastPortable},
|
||||
};
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use matrix_sdk_crypto::{
|
||||
matrix_sdk_qrcode::QrVerificationData, CancelInfo as RustCancelInfo, QrVerification as InnerQr,
|
||||
@@ -13,6 +16,9 @@ use tokio::runtime::Handle;
|
||||
|
||||
use crate::{CryptoStoreError, OutgoingVerificationRequest, SignatureUploadRequest};
|
||||
|
||||
const STANDARD_NO_PAD: FastPortable =
|
||||
FastPortable::from(&alphabet::STANDARD, fast_portable::NO_PAD);
|
||||
|
||||
/// Listener that will be passed over the FFI to report changes to a SAS
|
||||
/// verification.
|
||||
pub trait SasListener: Send {
|
||||
@@ -401,7 +407,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| encode_config(data, STANDARD_NO_PAD)).ok()
|
||||
self.inner.to_bytes().map(|data| encode_engine(data, &STANDARD_NO_PAD)).ok()
|
||||
}
|
||||
|
||||
/// Set a listener for changes in the QrCode verification process.
|
||||
@@ -703,7 +709,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: &str) -> Option<ScanResult> {
|
||||
let data = decode_config(data, STANDARD_NO_PAD).ok()?;
|
||||
let data = decode_engine(data, &STANDARD_NO_PAD).ok()?;
|
||||
let data = QrVerificationData::from_bytes(data).ok()?;
|
||||
|
||||
if let Some(qr) = self.runtime.block_on(self.inner.scan_qr_code(data)).ok()? {
|
||||
|
||||
@@ -13,16 +13,22 @@
|
||||
// limitations under the License.
|
||||
|
||||
pub use base64::DecodeError;
|
||||
use base64::{decode_config, encode_config, STANDARD_NO_PAD};
|
||||
use base64::{
|
||||
alphabet, decode_engine, encode_engine,
|
||||
engine::fast_portable::{self, FastPortable},
|
||||
};
|
||||
|
||||
const STANDARD_NO_PAD: FastPortable =
|
||||
FastPortable::from(&alphabet::STANDARD, fast_portable::NO_PAD);
|
||||
|
||||
/// Decode the input as base64 with no padding.
|
||||
pub fn decode(input: impl AsRef<[u8]>) -> Result<Vec<u8>, DecodeError> {
|
||||
decode_config(input, STANDARD_NO_PAD)
|
||||
decode_engine(input, &STANDARD_NO_PAD)
|
||||
}
|
||||
|
||||
/// Encode the input as base64 with no padding.
|
||||
pub fn encode(input: impl AsRef<[u8]>) -> String {
|
||||
encode_config(input, STANDARD_NO_PAD)
|
||||
encode_engine(input, &STANDARD_NO_PAD)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#![allow(dead_code)]
|
||||
use base64::{encode_config as base64_encode, STANDARD_NO_PAD};
|
||||
use base64::{
|
||||
alphabet, encode_engine as base64_encode,
|
||||
engine::fast_portable::{self, FastPortable},
|
||||
};
|
||||
use matrix_sdk_store_encryption::StoreCipher;
|
||||
use ruma::{
|
||||
events::{
|
||||
@@ -22,6 +25,9 @@ pub const RANGE_END: &str = "\u{001E}";
|
||||
/// (though super unlikely)
|
||||
pub const ESCAPED: &str = "\u{001E}\u{001D}";
|
||||
|
||||
const STANDARD_NO_PAD: FastPortable =
|
||||
FastPortable::from(&alphabet::STANDARD, fast_portable::NO_PAD);
|
||||
|
||||
/// Encode value as String/JsValue/IdbKeyRange for the JS APIs in a
|
||||
/// safe, escaped manner.
|
||||
///
|
||||
@@ -54,7 +60,7 @@ pub trait SafeEncode {
|
||||
fn as_secure_string(&self, table_name: &str, store_cipher: &StoreCipher) -> String {
|
||||
base64_encode(
|
||||
store_cipher.hash_key(table_name, self.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -116,12 +122,12 @@ where
|
||||
[
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.0.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.1.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
]
|
||||
.concat()
|
||||
@@ -151,17 +157,17 @@ where
|
||||
[
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.0.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.1.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.2.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
]
|
||||
.concat()
|
||||
@@ -194,22 +200,22 @@ where
|
||||
[
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.0.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.1.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.2.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
KEY_SEPARATOR,
|
||||
&base64_encode(
|
||||
store_cipher.hash_key(table_name, self.3.as_encoded_string().as_bytes()),
|
||||
STANDARD_NO_PAD,
|
||||
&STANDARD_NO_PAD,
|
||||
),
|
||||
]
|
||||
.concat()
|
||||
|
||||
Reference in New Issue
Block a user