From 5127783eae519e46d832e318f10d179a9cd22078 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Fri, 11 Sep 2020 15:21:39 +0200 Subject: [PATCH] Replace x-www-form-url encoding with percent encoding in blob/container signature generation (#318) * replace form url encoding with percent encoding * fixed example missing a dependency * less verbose code * less verbose code (forgot some :) --- azure_sdk_storage_blob/Cargo.toml | 5 ++-- azure_sdk_storage_blob/src/blob/mod.rs | 27 ++++++++++----------- azure_sdk_storage_blob/src/container/mod.rs | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/azure_sdk_storage_blob/Cargo.toml b/azure_sdk_storage_blob/Cargo.toml index 1f80b3488..717bf1fdb 100644 --- a/azure_sdk_storage_blob/Cargo.toml +++ b/azure_sdk_storage_blob/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "azure_sdk_storage_blob" -version = "0.45.2" +version = "0.45.3" description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage crate" readme = "README.md" authors = ["Francesco Cogno ", "Max Gortman ", "Dong Liu "] @@ -28,13 +28,14 @@ log = "0.4" serde = "1.0" serde_derive = "1.0" serde-xml-rs = "0.4" -url = "2.1" uuid = { version = "0.8", features = ["v4"] } +percent-encoding = "2.1" [dev-dependencies] env_logger = "0.7" tokio = { version = "0.2", features = ["macros"] } azure_sdk_auth_aad = { path = "../azure_sdk_auth_aad" } +url = "2.1" [features] default = [ "azure_sdk_core" ] diff --git a/azure_sdk_storage_blob/src/blob/mod.rs b/azure_sdk_storage_blob/src/blob/mod.rs index f8b9d2395..0889cd12c 100644 --- a/azure_sdk_storage_blob/src/blob/mod.rs +++ b/azure_sdk_storage_blob/src/blob/mod.rs @@ -21,16 +21,6 @@ use azure_sdk_core::headers::{ COPY_SOURCE, COPY_STATUS, COPY_STATUS_DESCRIPTION, CREATION_TIME, LEASE_DURATION, LEASE_STATE, LEASE_STATUS, SERVER_ENCRYPTED, }; -use azure_sdk_storage_core::Client; -use chrono::{DateTime, Utc}; -use hyper::header; -use std::borrow::Borrow; -use std::collections::HashMap; -use std::str::FromStr; -use url::form_urlencoded; -use xml::Element; -use xml::Xml::ElementNode; - use azure_sdk_core::{ errors::{AzureError, TraversingError}, incompletevector::IncompleteVector, @@ -39,6 +29,15 @@ use azure_sdk_core::{ range::Range, util::HeaderMapExt, }; +use azure_sdk_storage_core::Client; +use chrono::{DateTime, Utc}; +use hyper::header; +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; +use std::borrow::Borrow; +use std::collections::HashMap; +use std::str::FromStr; +use xml::Element; +use xml::Xml::ElementNode; #[cfg(feature = "azurite_workaround")] fn get_creation_time(h: &header::HeaderMap) -> Result>, AzureError> { @@ -464,15 +463,15 @@ where Some(ref params) => format!( "{}/{}/{}?{}", t.blob_uri(), - form_urlencoded::byte_serialize(container_name.as_bytes()).collect::(), - form_urlencoded::byte_serialize(blob_name.as_bytes()).collect::(), + utf8_percent_encode(container_name, NON_ALPHANUMERIC), + utf8_percent_encode(blob_name, NON_ALPHANUMERIC), params ), None => format!( "{}/{}/{}", t.blob_uri(), - form_urlencoded::byte_serialize(container_name.as_bytes()).collect::(), - form_urlencoded::byte_serialize(blob_name.as_bytes()).collect::(), + utf8_percent_encode(container_name, NON_ALPHANUMERIC), + utf8_percent_encode(blob_name, NON_ALPHANUMERIC), ), } } diff --git a/azure_sdk_storage_blob/src/container/mod.rs b/azure_sdk_storage_blob/src/container/mod.rs index 2a49b3e5e..1423aa321 100644 --- a/azure_sdk_storage_blob/src/container/mod.rs +++ b/azure_sdk_storage_blob/src/container/mod.rs @@ -18,9 +18,9 @@ use http::request::Builder; use http::HeaderMap; use hyper::header; use hyper::header::HeaderName; +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use std::collections::HashMap; use std::str::FromStr; -use url::form_urlencoded; use xml::{Element, Xml}; create_enum!( @@ -285,13 +285,13 @@ where Some(ref params) => format!( "{}/{}?{}", c.blob_uri(), - form_urlencoded::byte_serialize(container_name.as_bytes()).collect::(), + utf8_percent_encode(container_name, NON_ALPHANUMERIC), params ), None => format!( "{}/{}", c.blob_uri(), - form_urlencoded::byte_serialize(container_name.as_bytes()).collect::(), + utf8_percent_encode(container_name, NON_ALPHANUMERIC), ), } }