Skip to content

Commit 855b1ad

Browse files
committed
chore: Update base64
This removes one of cargo's duplicate dependencies
1 parent 80f1a5d commit 855b1ad

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ path = "src/cargo/lib.rs"
1717

1818
[dependencies]
1919
anyhow = "1.0.47"
20-
base64 = "0.13.1"
20+
base64 = "0.21.0"
2121
bytesize = "1.0"
2222
cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
2323
cargo-util = { path = "crates/cargo-util", version = "0.2.3" }

src/cargo/sources/git/known_hosts.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
//! and revoked markers. See "FIXME" comments littered in this file.
2121
2222
use crate::util::config::{Config, Definition, Value};
23+
use base64::engine::general_purpose::STANDARD;
24+
use base64::engine::general_purpose::STANDARD_NO_PAD;
25+
use base64::Engine as _;
2326
use git2::cert::{Cert, SshHostKeyType};
2427
use git2::CertificateCheckStatus;
2528
use hmac::Mac;
@@ -344,7 +347,7 @@ fn check_ssh_known_hosts(
344347
.collect();
345348
for (patterns, key_type, key) in BUNDLED_KEYS {
346349
if !configured_hosts.contains(*patterns) {
347-
let key = base64::decode(key).unwrap();
350+
let key = STANDARD.decode(key).unwrap();
348351
known_hosts.push(KnownHost {
349352
location: KnownHostLocation::Bundled,
350353
patterns: patterns.to_string(),
@@ -382,9 +385,8 @@ fn check_ssh_known_hosts_loaded(
382385
// support SHA256.
383386
let mut remote_fingerprint = cargo_util::Sha256::new();
384387
remote_fingerprint.update(remote_host_key.clone());
385-
let remote_fingerprint =
386-
base64::encode_config(remote_fingerprint.finish(), base64::STANDARD_NO_PAD);
387-
let remote_host_key_encoded = base64::encode(remote_host_key);
388+
let remote_fingerprint = STANDARD_NO_PAD.encode(remote_fingerprint.finish());
389+
let remote_host_key_encoded = STANDARD.encode(remote_host_key);
388390

389391
for known_host in known_hosts {
390392
// The key type from libgit2 needs to match the key type from the host file.
@@ -583,8 +585,8 @@ impl KnownHost {
583585

584586
fn hashed_hostname_matches(host: &str, hashed: &str) -> bool {
585587
let Some((b64_salt, b64_host)) = hashed.split_once('|') else { return false; };
586-
let Ok(salt) = base64::decode(b64_salt) else { return false; };
587-
let Ok(hashed_host) = base64::decode(b64_host) else { return false; };
588+
let Ok(salt) = STANDARD.decode(b64_salt) else { return false; };
589+
let Ok(hashed_host) = STANDARD.decode(b64_host) else { return false; };
588590
let Ok(mut mac) = hmac::Hmac::<sha1::Sha1>::new_from_slice(&salt) else { return false; };
589591
mac.update(host.as_bytes());
590592
let result = mac.finalize().into_bytes();
@@ -636,7 +638,7 @@ fn parse_known_hosts_line(line: &str, location: KnownHostLocation) -> Option<Kno
636638

637639
let patterns = parts.next()?;
638640
let key_type = parts.next()?;
639-
let key = parts.next().map(base64::decode)?.ok()?;
641+
let key = parts.next().map(|p| STANDARD.decode(p))?.ok()?;
640642
Some(KnownHost {
641643
line_type,
642644
location,

0 commit comments

Comments
 (0)