~vpzom/hancock

89dc2bc04a0b331077f4a383b21df5120fa2c17d — Colin Reeder 1 year, 5 months ago 0871c8a
rustfmt
1 files changed, 30 insertions(+), 15 deletions(-)

M src/lib.rs
M src/lib.rs => src/lib.rs +30 -15
@@ 212,7 212,11 @@ impl<'a> Signature<'a> {
        let mut key_id = None;
        let mut signature = None;

        for field_src in value.to_str().map_err(|_| ParseError::InvalidCharacters)?.split(',') {
        for field_src in value
            .to_str()
            .map_err(|_| ParseError::InvalidCharacters)?
            .split(',')
        {
            let eqidx = field_src.find('=').ok_or(ParseError::MissingEquals)?;

            let key = &field_src[..eqidx];


@@ 221,23 225,28 @@ impl<'a> Signature<'a> {
            match key {
                "algorithm" => {
                    algorithm = Some(value.parse().map_err(|_| ParseError::InvalidCharacters)?);
                },
                }
                "created" => {
                    created = Some(value.parse().map_err(ParseError::Number)?);
                },
                }
                "expires" => {
                    expires = Some(value.parse().map_err(ParseError::Number)?);
                },
                }
                "headers" => {
                    headers = Some(value.split(' ').map(|x| x.parse().map_err(|_| ParseError::InvalidCharacters)).collect::<Result<Vec<_>, _>>()?);
                },
                    headers = Some(
                        value
                            .split(' ')
                            .map(|x| x.parse().map_err(|_| ParseError::InvalidCharacters))
                            .collect::<Result<Vec<_>, _>>()?,
                    );
                }
                "key_id" => {
                    key_id = Some(value);
                },
                }
                "signature" => {
                    signature = Some(base64::decode(value).map_err(ParseError::Base64)?);
                },
                _ => {},
                }
                _ => {}
            }
        }



@@ 297,7 306,8 @@ impl<'a> Signature<'a> {
    ) -> Result<bool, VerifyError<E>> {
        use std::io::Write;

        let now = std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH)
        let now = std::time::SystemTime::now()
            .duration_since(std::time::SystemTime::UNIX_EPOCH)
            .expect("Timestamp is wildly inaccurate")
            .as_secs();



@@ 315,22 325,27 @@ impl<'a> Signature<'a> {
                }
                match name {
                    SignatureHeaderName::RequestTarget => {
                        write!(body, "(request-target): {} {}", request_method.as_str().to_lowercase(), request_path_and_query)?;
                    },
                        write!(
                            body,
                            "(request-target): {} {}",
                            request_method.as_str().to_lowercase(),
                            request_path_and_query
                        )?;
                    }
                    SignatureHeaderName::Created => {
                        if let Some(created) = self.created {
                            write!(body, "(created): {}", created)?;
                        } else {
                            return Ok(false);
                        }
                    },
                    }
                    SignatureHeaderName::Expires => {
                        if let Some(expires) = self.expires {
                            write!(body, "(expires): {}", expires)?;
                        } else {
                            return Ok(false);
                        }
                    },
                    }
                    SignatureHeaderName::NormalHeader(name) => {
                        write!(body, "{}: ", name)?;



@@ 344,7 359,7 @@ impl<'a> Signature<'a> {

                            body.extend(value.as_bytes());
                        }
                    },
                    }
                }
            }
        } else {