diff --git a/Cargo.lock b/Cargo.lock index 1c82c9102..14cf33f92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -889,7 +889,7 @@ dependencies = [ "async-smtp", "async_zip", "backtrace", - "base64 0.20.0", + "base64 0.21.0", "bitflags", "chrono", "criterion", diff --git a/Cargo.toml b/Cargo.toml index 4e0273627..6a8fd9872 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ trust-dns-resolver = "0.22" tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] } tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar backtrace = "0.3" -base64 = "0.20" +base64 = "0.21" bitflags = "1.3" chrono = { version = "0.4", default-features=false, features = ["clock", "std"] } dirs = { version = "4", optional=true } diff --git a/src/html.rs b/src/html.rs index 7593f16d4..20bb046c9 100644 --- a/src/html.rs +++ b/src/html.rs @@ -11,6 +11,7 @@ use std::future::Future; use std::pin::Pin; use anyhow::{Context as _, Result}; +use base64::Engine as _; use futures::future::FutureExt; use lettre_email::mime::{self, Mime}; use lettre_email::PartBuilder; @@ -234,7 +235,7 @@ impl HtmlMsgParser { /// Convert a mime part to a data: url as defined in [RFC 2397](https://tools.ietf.org/html/rfc2397). fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result { let data = mail.get_body_raw()?; - let data = base64::encode(data); + let data = base64::engine::general_purpose::STANDARD.encode(data); Ok(format!("data:{};base64,{}", mail.ctype.mimetype, data)) } diff --git a/src/key.rs b/src/key.rs index c32aa098a..bee59c60b 100644 --- a/src/key.rs +++ b/src/key.rs @@ -6,6 +6,7 @@ use std::io::Cursor; use std::pin::Pin; use anyhow::{ensure, Context as _, Result}; +use base64::Engine as _; use futures::Future; use num_traits::FromPrimitive; use pgp::composed::Deserializable; @@ -36,7 +37,7 @@ pub trait DcKey: Serialize + Deserializable + KeyTrait + Clone { fn from_base64(data: &str) -> Result { // strip newlines and other whitespace let cleaned: String = data.split_whitespace().collect(); - let bytes = base64::decode(cleaned.as_bytes())?; + let bytes = base64::engine::general_purpose::STANDARD.decode(cleaned.as_bytes())?; Self::from_slice(&bytes) } @@ -67,7 +68,7 @@ pub trait DcKey: Serialize + Deserializable + KeyTrait + Clone { /// Serialise the key to a base64 string. fn to_base64(&self) -> String { - base64::encode(DcKey::to_bytes(self)) + base64::engine::general_purpose::STANDARD.encode(DcKey::to_bytes(self)) } /// Serialise the key to ASCII-armored representation. diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 7f12f8776..ea8eea85f 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -3,6 +3,7 @@ use std::convert::TryInto; use anyhow::{bail, ensure, Context as _, Result}; +use base64::Engine as _; use chrono::TimeZone; use format_flowed::{format_flowed, format_flowed_quote}; use lettre_email::{mime, Address, Header, MimeMultipartType, PartBuilder}; @@ -1341,7 +1342,7 @@ impl<'a> MimeFactory<'a> { /// This line length limit is an /// [RFC5322 requirement](https://tools.ietf.org/html/rfc5322#section-2.1.1). fn wrapped_base64_encode(buf: &[u8]) -> String { - let base64 = base64::encode(buf); + let base64 = base64::engine::general_purpose::STANDARD.encode(buf); let mut chars = base64.chars(); std::iter::repeat_with(|| chars.by_ref().take(78).collect::()) .take_while(|s| !s.is_empty()) diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 5cb2adb56..5742e4cb1 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -8,6 +8,7 @@ use std::pin::Pin; use std::str; use anyhow::{bail, Context as _, Result}; +use base64::Engine as _; use deltachat_derive::{FromSql, ToSql}; use format_flowed::unformat_flowed; use lettre_email::mime::{self, Mime}; @@ -663,7 +664,7 @@ impl MimeMessage { .split_ascii_whitespace() .collect::() .strip_prefix("base64:") - .map(base64::decode) + .map(|x| base64::engine::general_purpose::STANDARD.decode(x)) { // Avatar sent directly in the header as base64. if let Ok(decoded_data) = avatar { diff --git a/src/qr_code_generator.rs b/src/qr_code_generator.rs index 2da50cf14..bbd2031ea 100644 --- a/src/qr_code_generator.rs +++ b/src/qr_code_generator.rs @@ -1,6 +1,7 @@ #![allow(missing_docs)] use anyhow::Result; +use base64::Engine as _; use qrcodegen::{QrCode, QrCodeEcc}; use crate::{ @@ -211,7 +212,10 @@ fn inner_generate_secure_join_qr_code( d.attr("clip-path", "url(#avatar-cut)")?; d.attr( "href", /*might need xlink:href instead if it doesn't work on older devices?*/ - format!("data:image/jpeg;base64,{}", base64::encode(img)), + format!( + "data:image/jpeg;base64,{}", + base64::engine::general_purpose::STANDARD.encode(img) + ), ) })?; } else { diff --git a/src/tools.rs b/src/tools.rs index 63cfb6f34..a547f6042 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -12,6 +12,7 @@ use std::str::from_utf8; use std::time::{Duration, SystemTime}; use anyhow::{bail, Context as _, Result}; +use base64::Engine as _; use chrono::{Local, TimeZone}; use futures::{StreamExt, TryStreamExt}; use mailparse::dateparse; @@ -276,12 +277,6 @@ async fn maybe_warn_on_outdated(context: &Context, now: i64, approx_compile_time /// - for INCOMING messages, the ID is taken from the Chat-Group-ID-header or from the Message-ID in the In-Reply-To: or References:-Header /// - the group-id should be a string with the characters [a-zA-Z0-9\-_] pub(crate) fn create_id() -> String { - const URL_SAFE_ENGINE: base64::engine::fast_portable::FastPortable = - base64::engine::fast_portable::FastPortable::from( - &base64::alphabet::URL_SAFE, - base64::engine::fast_portable::NO_PAD, - ); - // ThreadRng implements CryptoRng trait and is supposed to be cryptographically secure. let mut rng = thread_rng(); @@ -290,7 +285,8 @@ pub(crate) fn create_id() -> String { rng.fill(&mut arr[..]); // Take 11 base64 characters containing 66 random bits. - base64::encode_engine(arr, &URL_SAFE_ENGINE) + base64::engine::general_purpose::URL_SAFE + .encode(arr) .chars() .take(11) .collect()