From abe6a1689678e65e08c9abb768941210f454834f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 17 Nov 2023 15:26:07 +0000 Subject: [PATCH] changed base64 encoding to hex --- nym-wallet/Cargo.lock | 34 +++++++++++++------- tools/nymvisor/Cargo.toml | 2 +- tools/nymvisor/src/helpers.rs | 5 ++- tools/nymvisor/src/upgrades/download.rs | 6 ++-- tools/nymvisor/src/upgrades/serde_helpers.rs | 7 ++-- tools/nymvisor/src/upgrades/types.rs | 6 ++-- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/nym-wallet/Cargo.lock b/nym-wallet/Cargo.lock index 472be6cf1a..c7dea1c888 100644 --- a/nym-wallet/Cargo.lock +++ b/nym-wallet/Cargo.lock @@ -1261,9 +1261,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] [[package]] name = "derivative" @@ -4138,6 +4141,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -4812,9 +4821,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.183" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] @@ -4839,9 +4848,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", @@ -5742,14 +5751,15 @@ dependencies = [ [[package]] name = "time" -version = "0.3.25" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", "itoa 1.0.9", "libc", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -5757,15 +5767,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] diff --git a/tools/nymvisor/Cargo.toml b/tools/nymvisor/Cargo.toml index d60067a6a7..211f27f18d 100644 --- a/tools/nymvisor/Cargo.toml +++ b/tools/nymvisor/Cargo.toml @@ -12,12 +12,12 @@ license.workspace = true [dependencies] anyhow = { workspace = true } -base64 = "0.21.5" bytes = { version = "1.5.0", features = ["std"]} clap = { workspace = true, features = ["derive"] } dotenvy = { workspace = true } flate2 = "1.0.28" futures = { workspace = true } +hex = "0.4.3" humantime = "2.1.0" humantime-serde = "1.1.1" lazy_static = { workspace = true } diff --git a/tools/nymvisor/src/helpers.rs b/tools/nymvisor/src/helpers.rs index 15ea01a82f..184243a9fa 100644 --- a/tools/nymvisor/src/helpers.rs +++ b/tools/nymvisor/src/helpers.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 use crate::error::NymvisorError; -use base64::{engine::general_purpose::STANDARD, Engine as _}; use sha2::Digest; use std::fs::File; use std::io::{BufReader, Read}; @@ -39,6 +38,6 @@ pub fn calculate_file_checksum>( Ok(hasher.finalize().to_vec()) } -pub fn to_base64_string>(input: T) -> String { - STANDARD.encode(input) +pub fn to_hex_string>(input: T) -> String { + hex::encode(input) } diff --git a/tools/nymvisor/src/upgrades/download.rs b/tools/nymvisor/src/upgrades/download.rs index 651780eb17..1f71a4d722 100644 --- a/tools/nymvisor/src/upgrades/download.rs +++ b/tools/nymvisor/src/upgrades/download.rs @@ -3,7 +3,7 @@ use crate::config::Config; use crate::error::NymvisorError; -use crate::helpers::{init_path, to_base64_string}; +use crate::helpers::{init_path, to_hex_string}; use crate::upgrades::types::{DownloadUrl, UpgradeInfo}; use bytes::Buf; use futures::stream::StreamExt; @@ -97,8 +97,8 @@ fn maybe_verify_checksum( if checksum != download_url.checksum { return Err(NymvisorError::DownloadChecksumFailure { upgrade_name, - encoded_checksum: to_base64_string(&checksum), - expected_checksum: to_base64_string(&download_url.checksum), + encoded_checksum: to_hex_string(&checksum), + expected_checksum: to_hex_string(&download_url.checksum), algorithm: download_url.checksum_algorithm, }); } diff --git a/tools/nymvisor/src/upgrades/serde_helpers.rs b/tools/nymvisor/src/upgrades/serde_helpers.rs index 3a57152297..574ae0e9ac 100644 --- a/tools/nymvisor/src/upgrades/serde_helpers.rs +++ b/tools/nymvisor/src/upgrades/serde_helpers.rs @@ -1,17 +1,16 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -pub(super) mod base64 { - use base64::{engine::general_purpose::STANDARD, Engine as _}; +pub(super) mod hex { use serde::{Deserialize, Deserializer, Serializer}; pub fn serialize(bytes: &[u8], serializer: S) -> Result { - serializer.serialize_str(&STANDARD.encode(bytes)) + serializer.serialize_str(&hex::encode(bytes)) } pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D::Error> { let s = ::deserialize(deserializer)?; - STANDARD.decode(s).map_err(serde::de::Error::custom) + hex::decode(s).map_err(serde::de::Error::custom) } } diff --git a/tools/nymvisor/src/upgrades/types.rs b/tools/nymvisor/src/upgrades/types.rs index 99f8ef5bd8..d7c1d29ff9 100644 --- a/tools/nymvisor/src/upgrades/types.rs +++ b/tools/nymvisor/src/upgrades/types.rs @@ -1,7 +1,7 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use super::serde_helpers::{base64, option_offsetdatetime}; +use super::serde_helpers::{hex, option_offsetdatetime}; use crate::error::NymvisorError; use crate::helpers::{calculate_file_checksum, init_path}; use crate::upgrades::download::os_arch; @@ -200,8 +200,8 @@ impl DigestAlgorithm { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "lowercase")] pub struct DownloadUrl { - /// The base64-encoded checksum of the file behind the download url. - #[serde(with = "base64")] + /// The hex-encoded checksum of the file behind the download url. + #[serde(with = "hex")] pub checksum: Vec, /// The algorithm used for computing the checksum