Loading crates/s3s/Cargo.toml +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ pin-project-lite = "0.2.9" quick-xml = { version = "0.27.1", features = ["serialize"] } serde = { version = "1.0.152", features = ["derive"] } serde_urlencoded = "0.7.1" sha1 = "0.10.5" sha2 = "0.10.6" smallvec = "1.10.0" thiserror = "1.0.38" Loading crates/s3s/src/http/ordered_headers.rs +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ use smallvec::SmallVec; use crate::utils::stable_sort_by_first; /// Immutable http header container #[derive(Debug)] #[derive(Debug, Default)] pub struct OrderedHeaders<'a> { /// Ascending headers (header names are lowercase) headers: SmallVec<[(&'a str, &'a str); 16]>, Loading crates/s3s/src/http/ordered_qs.rs +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ use crate::utils::stable_sort_by_first; /// Immutable query string container #[derive(Debug, Clone)] #[derive(Debug, Default, Clone)] pub struct OrderedQs { /// Ascending query strings qs: Vec<(String, String)>, Loading crates/s3s/src/lib.rs +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ mod header; mod http; mod ops; mod s3_trait; mod sig_v2; mod sig_v4; mod xml; Loading crates/s3s/src/sig_v2/authorization_v2.rs 0 → 100644 +53 −0 Original line number Diff line number Diff line //! Authorization V2 //! //! <https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#ConstructingTheAuthenticationHeader> //! use crate::utils::parser; use nom::bytes::complete::{tag, take, take_till}; use nom::combinator::{all_consuming, rest}; use nom::sequence::terminated; pub struct AuthorizationV2<'a> { pub access_key: &'a str, pub signature: &'a str, } /// [`AuthorizationV2`] #[derive(Debug, thiserror::Error)] #[error("ParseAuthorizationError")] pub struct ParseAuthorizationV2Error { /// priv place holder _priv: (), } impl<'a> AuthorizationV2<'a> { pub fn parse(input: &'a str) -> Result<Self, ParseAuthorizationV2Error> { let error = |_| ParseAuthorizationV2Error { _priv: () }; let colon_tail0 = terminated(take_till(|c| c == ':'), take(1_usize)); parser::parse(input, |p| { p.nom(tag("AWS "))?; let access_key = p.nom(colon_tail0)?; let signature = p.nom(all_consuming(rest))?; Ok(Self { access_key, signature }) }) .map_err(error) } } #[cfg(test)] mod tests { use super::*; #[test] fn example() { let input = "AWS AKIAIOSFODNN7EXAMPLE:qgk2+6Sv9/oM7G3qLEjTH1a1l1g="; let ans = AuthorizationV2::parse(input).unwrap(); assert_eq!(ans.access_key, "AKIAIOSFODNN7EXAMPLE"); assert_eq!(ans.signature, "qgk2+6Sv9/oM7G3qLEjTH1a1l1g="); } } Loading
crates/s3s/Cargo.toml +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ pin-project-lite = "0.2.9" quick-xml = { version = "0.27.1", features = ["serialize"] } serde = { version = "1.0.152", features = ["derive"] } serde_urlencoded = "0.7.1" sha1 = "0.10.5" sha2 = "0.10.6" smallvec = "1.10.0" thiserror = "1.0.38" Loading
crates/s3s/src/http/ordered_headers.rs +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ use smallvec::SmallVec; use crate::utils::stable_sort_by_first; /// Immutable http header container #[derive(Debug)] #[derive(Debug, Default)] pub struct OrderedHeaders<'a> { /// Ascending headers (header names are lowercase) headers: SmallVec<[(&'a str, &'a str); 16]>, Loading
crates/s3s/src/http/ordered_qs.rs +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ use crate::utils::stable_sort_by_first; /// Immutable query string container #[derive(Debug, Clone)] #[derive(Debug, Default, Clone)] pub struct OrderedQs { /// Ascending query strings qs: Vec<(String, String)>, Loading
crates/s3s/src/lib.rs +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ mod header; mod http; mod ops; mod s3_trait; mod sig_v2; mod sig_v4; mod xml; Loading
crates/s3s/src/sig_v2/authorization_v2.rs 0 → 100644 +53 −0 Original line number Diff line number Diff line //! Authorization V2 //! //! <https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#ConstructingTheAuthenticationHeader> //! use crate::utils::parser; use nom::bytes::complete::{tag, take, take_till}; use nom::combinator::{all_consuming, rest}; use nom::sequence::terminated; pub struct AuthorizationV2<'a> { pub access_key: &'a str, pub signature: &'a str, } /// [`AuthorizationV2`] #[derive(Debug, thiserror::Error)] #[error("ParseAuthorizationError")] pub struct ParseAuthorizationV2Error { /// priv place holder _priv: (), } impl<'a> AuthorizationV2<'a> { pub fn parse(input: &'a str) -> Result<Self, ParseAuthorizationV2Error> { let error = |_| ParseAuthorizationV2Error { _priv: () }; let colon_tail0 = terminated(take_till(|c| c == ':'), take(1_usize)); parser::parse(input, |p| { p.nom(tag("AWS "))?; let access_key = p.nom(colon_tail0)?; let signature = p.nom(all_consuming(rest))?; Ok(Self { access_key, signature }) }) .map_err(error) } } #[cfg(test)] mod tests { use super::*; #[test] fn example() { let input = "AWS AKIAIOSFODNN7EXAMPLE:qgk2+6Sv9/oM7G3qLEjTH1a1l1g="; let ans = AuthorizationV2::parse(input).unwrap(); assert_eq!(ans.access_key, "AKIAIOSFODNN7EXAMPLE"); assert_eq!(ans.signature, "qgk2+6Sv9/oM7G3qLEjTH1a1l1g="); } }