1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-29 21:44:24 +03:00

update base64, work around another batch of breaking API changes

closes: https://github.com/wez/wezterm/pull/2931
This commit is contained in:
Wez Furlong 2023-01-08 18:49:45 -07:00
parent c9a0537b7b
commit d34297cd2c
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
7 changed files with 48 additions and 33 deletions

14
Cargo.lock generated
View File

@ -294,9 +294,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.20.0" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]] [[package]]
name = "base91" name = "base91"
@ -2304,9 +2304,9 @@ dependencies = [
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.7.0" version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
@ -2906,7 +2906,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"base64 0.20.0", "base64 0.21.0",
"bintree", "bintree",
"bitflags", "bitflags",
"chrono", "chrono",
@ -4993,7 +4993,7 @@ name = "termwiz"
version = "0.19.0" version = "0.19.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.20.0", "base64 0.21.0",
"bitflags", "bitflags",
"cassowary", "cassowary",
"criterion", "criterion",
@ -6048,7 +6048,7 @@ dependencies = [
"anyhow", "anyhow",
"assert_fs", "assert_fs",
"async_ossl", "async_ossl",
"base64 0.20.0", "base64 0.21.0",
"bitflags", "bitflags",
"camino", "camino",
"clap 4.0.32", "clap 4.0.32",

View File

@ -9,7 +9,7 @@ edition = "2018"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
async-trait = "0.1" async-trait = "0.1"
base64 = "0.20" base64 = "0.21"
bintree = { path = "../bintree" } bintree = { path = "../bintree" }
bitflags = "1.3" bitflags = "1.3"
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }

View File

@ -12,7 +12,7 @@ readme = "README.md"
[dependencies] [dependencies]
# backtrace = "0.3" # backtrace = "0.3"
base64 = "0.20" base64 = "0.21"
bitflags = "1.3" bitflags = "1.3"
cassowary = {version="0.3", optional=true} cassowary = {version="0.3", optional=true}
anyhow = "1.0" anyhow = "1.0"

View File

@ -1,3 +1,4 @@
use crate::escape::osc::{base64_decode, base64_encode};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fmt::{Display, Error as FmtError, Formatter}; use std::fmt::{Display, Error as FmtError, Formatter};
use std::io::{Read, Seek}; use std::io::{Read, Seek};
@ -112,17 +113,17 @@ impl KittyImageData {
match t { match t {
"d" => Some(Self::Direct(String::from_utf8(payload.to_vec()).ok()?)), "d" => Some(Self::Direct(String::from_utf8(payload.to_vec()).ok()?)),
"f" => Some(Self::File { "f" => Some(Self::File {
path: String::from_utf8(base64::decode(payload.to_vec()).ok()?).ok()?, path: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
data_size: geti(keys, "S"), data_size: geti(keys, "S"),
data_offset: geti(keys, "O"), data_offset: geti(keys, "O"),
}), }),
"t" => Some(Self::TemporaryFile { "t" => Some(Self::TemporaryFile {
path: String::from_utf8(base64::decode(payload.to_vec()).ok()?).ok()?, path: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
data_size: geti(keys, "S"), data_size: geti(keys, "S"),
data_offset: geti(keys, "O"), data_offset: geti(keys, "O"),
}), }),
"s" => Some(Self::SharedMem { "s" => Some(Self::SharedMem {
name: String::from_utf8(base64::decode(payload.to_vec()).ok()?).ok()?, name: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
data_size: geti(keys, "S"), data_size: geti(keys, "S"),
data_offset: geti(keys, "O"), data_offset: geti(keys, "O"),
}), }),
@ -141,7 +142,7 @@ impl KittyImageData {
data_size, data_size,
} => { } => {
keys.insert("t", "f".to_string()); keys.insert("t", "f".to_string());
keys.insert("payload", base64::encode(&path)); keys.insert("payload", base64_encode(&path));
set(keys, "S", data_size); set(keys, "S", data_size);
set(keys, "S", data_offset); set(keys, "S", data_offset);
} }
@ -151,7 +152,7 @@ impl KittyImageData {
data_size, data_size,
} => { } => {
keys.insert("t", "t".to_string()); keys.insert("t", "t".to_string());
keys.insert("payload", base64::encode(&path)); keys.insert("payload", base64_encode(&path));
set(keys, "S", data_size); set(keys, "S", data_size);
set(keys, "S", data_offset); set(keys, "S", data_offset);
} }
@ -161,7 +162,7 @@ impl KittyImageData {
data_size, data_size,
} => { } => {
keys.insert("t", "s".to_string()); keys.insert("t", "s".to_string());
keys.insert("payload", base64::encode(&name)); keys.insert("payload", base64_encode(&name));
set(keys, "S", data_size); set(keys, "S", data_size);
set(keys, "S", data_offset); set(keys, "S", data_offset);
} }
@ -195,7 +196,7 @@ impl KittyImageData {
match self { match self {
Self::Direct(data) => { Self::Direct(data) => {
base64::decode(data).or_else(|_| Err(std::io::ErrorKind::InvalidInput.into())) base64_decode(data).or_else(|_| Err(std::io::ErrorKind::InvalidInput.into()))
} }
Self::File { Self::File {
path, path,

View File

@ -1,6 +1,7 @@
use crate::color::SrgbaTuple; use crate::color::SrgbaTuple;
pub use crate::hyperlink::Hyperlink; pub use crate::hyperlink::Hyperlink;
use crate::{bail, ensure, Result}; use crate::{bail, ensure, Result};
use base64::Engine;
use bitflags::bitflags; use bitflags::bitflags;
use num_derive::*; use num_derive::*;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
@ -168,7 +169,7 @@ impl OperatingSystemCommand {
Selection::try_parse(osc[1]).map(OperatingSystemCommand::QuerySelection) Selection::try_parse(osc[1]).map(OperatingSystemCommand::QuerySelection)
} else if osc.len() == 3 { } else if osc.len() == 3 {
let sel = Selection::try_parse(osc[1])?; let sel = Selection::try_parse(osc[1])?;
let bytes = base64::decode(osc[2])?; let bytes = base64_decode(osc[2])?;
let s = String::from_utf8(bytes)?; let s = String::from_utf8(bytes)?;
Ok(OperatingSystemCommand::SetSelection(sel, s)) Ok(OperatingSystemCommand::SetSelection(sel, s))
} else { } else {
@ -505,7 +506,7 @@ impl Display for OperatingSystemCommand {
} }
ClearSelection(s) => write!(f, "52;{}", s)?, ClearSelection(s) => write!(f, "52;{}", s)?,
QuerySelection(s) => write!(f, "52;{};?", s)?, QuerySelection(s) => write!(f, "52;{};?", s)?,
SetSelection(s, val) => write!(f, "52;{};{}", s, base64::encode(val))?, SetSelection(s, val) => write!(f, "52;{};{}", s, base64_encode(val))?,
SystemNotification(s) => write!(f, "9;{}", s)?, SystemNotification(s) => write!(f, "9;{}", s)?,
ITermProprietary(i) => i.fmt(f)?, ITermProprietary(i) => i.fmt(f)?,
FinalTermSemanticPrompt(i) => i.fmt(f)?, FinalTermSemanticPrompt(i) => i.fmt(f)?,
@ -907,7 +908,7 @@ impl ITermFileData {
let param = if idx == last { let param = if idx == last {
// The final argument contains `:base64`, so look for that // The final argument contains `:base64`, so look for that
if let Some(colon) = param.iter().position(|c| *c == b':') { if let Some(colon) = param.iter().position(|c| *c == b':') {
data = Some(base64::decode(&param[colon + 1..])?); data = Some(base64_decode(&param[colon + 1..])?);
&param[..colon] &param[..colon]
} else { } else {
// If we don't find the colon in the last piece, we've // If we don't find the colon in the last piece, we've
@ -935,7 +936,7 @@ impl ITermFileData {
let name = params let name = params
.get("name") .get("name")
.and_then(|s| base64::decode(s).ok()) .and_then(|s| base64_decode(s).ok())
.and_then(|b| String::from_utf8(b).ok()); .and_then(|b| String::from_utf8(b).ok());
let size = params.get("size").and_then(|s| s.parse().ok()); let size = params.get("size").and_then(|s| s.parse().ok());
let width = params let width = params
@ -983,7 +984,7 @@ impl Display for ITermFileData {
} }
if let Some(ref name) = self.name { if let Some(ref name) = self.name {
sep = emit_sep(sep, f)?; sep = emit_sep(sep, f)?;
write!(f, "name={}", base64::encode(name))?; write!(f, "name={}", base64_encode(name))?;
} }
if self.width != ITermDimension::Automatic { if self.width != ITermDimension::Automatic {
sep = emit_sep(sep, f)?; sep = emit_sep(sep, f)?;
@ -1010,7 +1011,7 @@ impl Display for ITermFileData {
if sep == "=" { if sep == "=" {
write!(f, "=")?; write!(f, "=")?;
} }
write!(f, ":{}", base64::encode(&self.data))?; write!(f, ":{}", base64_encode(&self.data))?;
Ok(()) Ok(())
} }
} }
@ -1145,13 +1146,13 @@ impl ITermProprietary {
}; };
if osc.len() == 3 && keyword == "Copy" && p1_empty { if osc.len() == 3 && keyword == "Copy" && p1_empty {
return Ok(ITermProprietary::Copy(String::from_utf8(base64::decode( return Ok(ITermProprietary::Copy(String::from_utf8(base64_decode(
osc[2], osc[2],
)?)?)); )?)?));
} }
if osc.len() == 3 && keyword == "SetBadgeFormat" && p1_empty { if osc.len() == 3 && keyword == "SetBadgeFormat" && p1_empty {
return Ok(ITermProprietary::SetBadgeFormat(String::from_utf8( return Ok(ITermProprietary::SetBadgeFormat(String::from_utf8(
base64::decode(osc[2])?, base64_decode(osc[2])?,
)?)); )?));
} }
@ -1183,7 +1184,7 @@ impl ITermProprietary {
if let (Some(k), Some(v)) = (p1, p2) { if let (Some(k), Some(v)) = (p1, p2) {
return Ok(ITermProprietary::SetUserVar { return Ok(ITermProprietary::SetUserVar {
name: k.to_string(), name: k.to_string(),
value: String::from_utf8(base64::decode(v)?)?, value: String::from_utf8(base64_decode(v)?)?,
}); });
} }
} }
@ -1222,6 +1223,18 @@ impl ITermProprietary {
} }
} }
/// base64::encode is deprecated, so make a less frustrating helper
pub(crate) fn base64_encode<T: AsRef<[u8]>>(s: T) -> String {
base64::engine::general_purpose::STANDARD.encode(s)
}
/// base64::decode is deprecated, so make a less frustrating helper
pub(crate) fn base64_decode<T: AsRef<[u8]>>(
s: T,
) -> std::result::Result<Vec<u8>, base64::DecodeError> {
base64::engine::general_purpose::STANDARD.decode(s)
}
impl Display for ITermProprietary { impl Display for ITermProprietary {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "1337;")?; write!(f, "1337;")?;
@ -1251,12 +1264,12 @@ impl Display for ITermProprietary {
f, f,
"ReportCellSize={height_pixels:.1};{width_pixels:.1};{scale:.1}", "ReportCellSize={height_pixels:.1};{width_pixels:.1};{scale:.1}",
)?, )?,
Copy(s) => write!(f, "Copy=;{}", base64::encode(s))?, Copy(s) => write!(f, "Copy=;{}", base64_encode(s))?,
ReportVariable(s) => write!(f, "ReportVariable={}", base64::encode(s))?, ReportVariable(s) => write!(f, "ReportVariable={}", base64_encode(s))?,
SetUserVar { name, value } => { SetUserVar { name, value } => {
write!(f, "SetUserVar={}={}", name, base64::encode(value))? write!(f, "SetUserVar={}={}", name, base64_encode(value))?
} }
SetBadgeFormat(s) => write!(f, "SetBadgeFormat={}", base64::encode(s))?, SetBadgeFormat(s) => write!(f, "SetBadgeFormat={}", base64_encode(s))?,
File(file) => file.fmt(f)?, File(file) => file.fmt(f)?,
UnicodeVersion(ITermUnicodeVersionOp::Set(n)) => write!(f, "UnicodeVersion={}", n)?, UnicodeVersion(ITermUnicodeVersionOp::Set(n)) => write!(f, "UnicodeVersion={}", n)?,
UnicodeVersion(ITermUnicodeVersionOp::Push(Some(label))) => { UnicodeVersion(ITermUnicodeVersionOp::Push(Some(label))) => {

View File

@ -18,7 +18,7 @@ vendored-openssl-libssh-rs = ["libssh-rs/vendored-openssl"]
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
base64 = "0.20" base64 = "0.21"
bitflags = "1.3" bitflags = "1.3"
camino = "1.0" camino = "1.0"
dirs-next = "2.0" dirs-next = "2.0"

View File

@ -115,11 +115,12 @@ impl crate::sessioninner::SessionInner {
let fingerprint = sess let fingerprint = sess
.host_key_hash(ssh2::HashType::Sha256) .host_key_hash(ssh2::HashType::Sha256)
.map(|fingerprint| { .map(|fingerprint| {
let engine = base64::engine::fast_portable::FastPortable::from( use base64::Engine;
let engine = base64::engine::general_purpose::GeneralPurpose::new(
&base64::alphabet::STANDARD, &base64::alphabet::STANDARD,
base64::engine::fast_portable::NO_PAD, base64::engine::general_purpose::NO_PAD,
); );
format!("SHA256:{}", base64::encode_engine(fingerprint, &engine)) format!("SHA256:{}", engine.encode(fingerprint))
}) })
.or_else(|| { .or_else(|| {
// Querying for the Sha256 can fail if for example we were linked // Querying for the Sha256 can fail if for example we were linked