diff --git a/api/src/action/delete.rs b/api/src/action/delete.rs index 1900a28..715bca6 100644 --- a/api/src/action/delete.rs +++ b/api/src/action/delete.rs @@ -4,7 +4,7 @@ use api::data::{ Error as DataError, OwnedData, }; -use api::nonce::{NonceError, request_auth_nonce}; +use api::nonce::{NonceError, request_nonce}; use ext::status_code::StatusCodeExt; use file::remote_file::RemoteFile; @@ -46,7 +46,7 @@ impl<'a> Delete<'a> { fn fetch_auth_nonce(&self, client: &Client) -> Result, PrepareError> { - request_auth_nonce( + request_nonce( client, self.file.download_url(false), ).map_err(|err| PrepareError::Auth(err)) diff --git a/api/src/action/info.rs b/api/src/action/info.rs index 6c3c148..8f33ea0 100644 --- a/api/src/action/info.rs +++ b/api/src/action/info.rs @@ -10,7 +10,7 @@ use api::data::{ Error as DataError, OwnedData, }; -use api::nonce::{NonceError, request_auth_nonce}; +use api::nonce::{NonceError, request_nonce}; use ext::status_code::StatusCodeExt; use file::remote_file::RemoteFile; @@ -52,7 +52,7 @@ impl<'a> Info<'a> { fn fetch_auth_nonce(&self, client: &Client) -> Result, PrepareError> { - request_auth_nonce( + request_nonce( client, self.file.download_url(false), ).map_err(|err| PrepareError::Auth(err)) diff --git a/api/src/action/metadata.rs b/api/src/action/metadata.rs index 7c16576..b0ab5c5 100644 --- a/api/src/action/metadata.rs +++ b/api/src/action/metadata.rs @@ -4,12 +4,7 @@ use reqwest::{Client, StatusCode}; use reqwest::header::Authorization; use serde_json; -use api::nonce::{ - HEADER_NONCE, - header_nonce, - NonceError, - request_auth_nonce, -}; +use api::nonce::{header_nonce, NonceError, request_nonce}; use crypto::b64; use crypto::key_set::KeySet; use crypto::sig::signature_encoded; @@ -55,7 +50,7 @@ impl<'a> Metadata<'a> { fn fetch_auth_nonce(&self, client: &Client) -> Result, RequestError> { - request_auth_nonce( + request_nonce( client, self.file.download_url(false), ).map_err(|err| RequestError::Auth(err)) @@ -92,7 +87,7 @@ impl<'a> Metadata<'a> { } // Get the metadata nonce - let nonce = header_nonce(HEADER_NONCE, &response) + let nonce = header_nonce(&response) .map_err(|err| MetaError::Nonce(err))?; // Parse the metadata response, and decrypt it diff --git a/api/src/action/params.rs b/api/src/action/params.rs index 653f919..937d657 100644 --- a/api/src/action/params.rs +++ b/api/src/action/params.rs @@ -4,7 +4,7 @@ use api::data::{ Error as DataError, OwnedData, }; -use api::nonce::{NonceError, request_auth_nonce}; +use api::nonce::{NonceError, request_nonce}; use ext::status_code::StatusCodeExt; use file::remote_file::RemoteFile; @@ -68,7 +68,7 @@ impl<'a> Params<'a> { fn fetch_auth_nonce(&self, client: &Client) -> Result, PrepareError> { - request_auth_nonce( + request_nonce( client, self.file.download_url(false), ).map_err(|err| PrepareError::Auth(err)) diff --git a/api/src/action/password.rs b/api/src/action/password.rs index b1e6f0e..bcb3aa6 100644 --- a/api/src/action/password.rs +++ b/api/src/action/password.rs @@ -4,7 +4,7 @@ use api::data::{ Error as DataError, OwnedData, }; -use api::nonce::{NonceError, request_auth_nonce}; +use api::nonce::{NonceError, request_nonce}; use crypto::key_set::KeySet; use ext::status_code::StatusCodeExt; use file::remote_file::RemoteFile; @@ -62,7 +62,7 @@ impl<'a> Password<'a> { fn fetch_auth_nonce(&self, client: &Client) -> Result, PrepareError> { - request_auth_nonce( + request_nonce( client, self.file.download_url(false), ).map_err(|err| PrepareError::Auth(err)) diff --git a/api/src/action/upload.rs b/api/src/action/upload.rs index 463405a..db03ca6 100644 --- a/api/src/action/upload.rs +++ b/api/src/action/upload.rs @@ -22,7 +22,7 @@ use url::{ Url, }; -use api::nonce::{HEADER_NONCE, header_nonce}; +use api::nonce::header_nonce; use crypto::key_set::KeySet; use ext::status_code::StatusCodeExt; use file::remote_file::RemoteFile; @@ -259,7 +259,7 @@ impl Upload { } // Try to get the nonce, don't error on failure - let nonce = header_nonce(HEADER_NONCE, &response).ok(); + let nonce = header_nonce(&response).ok(); // Decode the response let response: UploadResponse = match response.json() { diff --git a/api/src/api/nonce.rs b/api/src/api/nonce.rs index 761009a..412e071 100644 --- a/api/src/api/nonce.rs +++ b/api/src/api/nonce.rs @@ -5,10 +5,11 @@ use crypto::b64; use ext::status_code::StatusCodeExt; /// The name of the header the nonce is delivered in. -pub const HEADER_NONCE: &'static str = "WWW-Authenticate"; +const HEADER_NONCE: &'static str = "WWW-Authenticate"; -/// Do a new request, and fetch the nonce from the header with the given name. -pub fn request_nonce(client: &Client, url: Url, header: &str) +/// Do a new request, and extract the nonce from a header in the given +/// response. +pub fn request_nonce(client: &Client, url: Url) -> Result, NonceError> { // Make the request @@ -28,26 +29,18 @@ pub fn request_nonce(client: &Client, url: Url, header: &str) // } } - // Fetch the nonce - header_nonce(header, &response) + // Extract the nonce + header_nonce(&response) } -/// Do a new request, and fetch the authentication nonce from the header with -/// the given name. -pub fn request_auth_nonce(client: &Client, url: Url) - -> Result, NonceError> -{ - request_nonce(client, url, HEADER_NONCE) -} - -/// Get a nonce from a header in the given response. -pub fn header_nonce(header: &str, response: &Response) +/// Extract the nonce from a header in the given response. +pub fn header_nonce(response: &Response) -> Result, NonceError> { // Get the authentication nonce b64::decode( response.headers() - .get_raw(header) + .get_raw(HEADER_NONCE) .ok_or(NonceError::NoNonceHeader)? .one() .ok_or(NonceError::MalformedNonce)