From 3917c4ac55b2a287fb85135fa69a8d1abce08285 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Mon, 9 Jan 2023 13:15:41 +0100 Subject: [PATCH] Update base64 0.20.0 => 0.21.0 --- Cargo.lock | 4 ++-- packages/hurl/Cargo.toml | 2 +- packages/hurl/src/http/client.rs | 5 ++++- packages/hurl/src/json/value.rs | 4 +++- packages/hurl/src/runner/request.rs | 6 ++++-- packages/hurlfmt/Cargo.toml | 2 +- packages/hurlfmt/src/format/json.rs | 31 ++++++++++++++--------------- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5dabb47e..38f7d85a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,9 +60,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "bit-set" diff --git a/packages/hurl/Cargo.toml b/packages/hurl/Cargo.toml index 589986147..5e7345ab9 100644 --- a/packages/hurl/Cargo.toml +++ b/packages/hurl/Cargo.toml @@ -18,7 +18,7 @@ strict = [] [dependencies] atty = "0.2.14" -base64 = "0.20.0" +base64 = "0.21.0" brotli = "3.3.4" chrono = { version = "0.4.23", default-features = false, features = ["clock"] } clap = { version = "4.0.32", features = ["cargo", "string", "wrap_help"] } diff --git a/packages/hurl/src/http/client.rs b/packages/hurl/src/http/client.rs index f47f1800e..bada4b82c 100644 --- a/packages/hurl/src/http/client.rs +++ b/packages/hurl/src/http/client.rs @@ -31,6 +31,8 @@ use super::response::*; use super::{Header, HttpError, Verbosity}; use crate::cli::Logger; use crate::http::ContextDir; +use base64::engine::general_purpose; +use base64::Engine; use curl::easy::List; use std::str::FromStr; use url::Url; @@ -423,7 +425,8 @@ impl Client { } if let Some(ref user) = options.user { - let authorization = base64::encode(user.as_bytes()); + let user = user.as_bytes(); + let authorization = general_purpose::STANDARD.encode(user); if request.get_header_values("Authorization").is_empty() { list.append(format!("Authorization: Basic {}", authorization).as_str()) .unwrap(); diff --git a/packages/hurl/src/json/value.rs b/packages/hurl/src/json/value.rs index 850cbee14..35128181e 100644 --- a/packages/hurl/src/json/value.rs +++ b/packages/hurl/src/json/value.rs @@ -17,6 +17,8 @@ */ use crate::runner::Value; +use base64::engine::general_purpose; +use base64::Engine; impl Value { pub fn to_json(&self) -> serde_json::Value { @@ -47,7 +49,7 @@ impl Value { serde_json::Value::Object(map) } Value::Bytes(v) => { - let encoded = base64::encode(v); + let encoded = general_purpose::STANDARD.encode(v); serde_json::Value::String(encoded) } Value::Null => serde_json::Value::Null, diff --git a/packages/hurl/src/runner/request.rs b/packages/hurl/src/runner/request.rs index 947074f20..0a8f1c3b8 100644 --- a/packages/hurl/src/runner/request.rs +++ b/packages/hurl/src/runner/request.rs @@ -16,6 +16,8 @@ * */ +use base64::engine::general_purpose; +use base64::Engine; use std::collections::HashMap; #[allow(unused)] use std::io::prelude::*; @@ -52,8 +54,8 @@ pub fn eval_request( if let Some(kv) = &request.basic_auth() { let value = eval_template(&kv.value, variables)?; let user_password = format!("{}:{}", kv.key.value, value); - let authorization = base64::encode(user_password.as_bytes()); - + let user_password = user_password.as_bytes(); + let authorization = general_purpose::STANDARD.encode(user_password); let name = "Authorization".to_string(); let value = format!("Basic {}", authorization); let header = http::Header { name, value }; diff --git a/packages/hurlfmt/Cargo.toml b/packages/hurlfmt/Cargo.toml index c8de2d1be..d85b3af69 100644 --- a/packages/hurlfmt/Cargo.toml +++ b/packages/hurlfmt/Cargo.toml @@ -15,7 +15,7 @@ strict = [] [dependencies] atty = "0.2.14" -base64 = "0.20.0" +base64 = "0.21.0" clap = { version = "4.0.32", features = ["cargo", "wrap_help"] } colored = "2.0.0" hurl_core = { version = "2.0.0-SNAPSHOT", path = "../hurl_core" } diff --git a/packages/hurlfmt/src/format/json.rs b/packages/hurlfmt/src/format/json.rs index b38a80553..6d0e9f55c 100644 --- a/packages/hurlfmt/src/format/json.rs +++ b/packages/hurlfmt/src/format/json.rs @@ -16,6 +16,9 @@ * */ +use base64::engine::general_purpose; +use base64::Engine; + use hurl_core::ast::*; use super::serialize_json::*; @@ -179,24 +182,20 @@ impl ToJson for Bytes { impl ToJson for Base64 { fn to_json(&self) -> JValue { + let value = general_purpose::STANDARD.encode(&self.value); JValue::Object(vec![ ("encoding".to_string(), JValue::String("base64".to_string())), - ( - "value".to_string(), - JValue::String(base64::encode(&self.value)), - ), + ("value".to_string(), JValue::String(value)), ]) } } impl ToJson for Hex { fn to_json(&self) -> JValue { + let value = general_purpose::STANDARD.encode(&self.value); JValue::Object(vec![ ("encoding".to_string(), JValue::String("base64".to_string())), - ( - "value".to_string(), - JValue::String(base64::encode(&self.value)), - ), + ("value".to_string(), JValue::String(value)), ]) } } @@ -475,14 +474,14 @@ fn json_predicate_value(predicate_value: PredicateValue) -> (JValue, Option (JValue::Number(value.to_string()), None), PredicateValue::Bool(value) => (JValue::Boolean(value), None), PredicateValue::Null {} => (JValue::Null, None), - PredicateValue::Hex(value) => ( - JValue::String(base64::encode(value.value)), - Some("base64".to_string()), - ), - PredicateValue::Base64(value) => ( - JValue::String(base64::encode(value.value)), - Some("base64".to_string()), - ), + PredicateValue::Hex(value) => { + let base64_string = general_purpose::STANDARD.encode(value.value); + (JValue::String(base64_string), Some("base64".to_string())) + } + PredicateValue::Base64(value) => { + let base64_string = general_purpose::STANDARD.encode(value.value); + (JValue::String(base64_string), Some("base64".to_string())) + } PredicateValue::Expression(value) => (JValue::String(value.to_string()), None), PredicateValue::Regex(value) => { (JValue::String(value.to_string()), Some("regex".to_string()))