diff --git a/api/src/action/download.rs b/api/src/action/download.rs index 09e560b..e5a436f 100644 --- a/api/src/action/download.rs +++ b/api/src/action/download.rs @@ -76,7 +76,7 @@ impl<'a> Download<'a> { // Get the authentication nonce // TODO: don't unwrap here, return an error - let nonce = b64::decode_standard( + let nonce = b64::decode( response.headers() .get_raw(HEADER_AUTH_NONCE) .expect("missing authenticate header") @@ -115,7 +115,7 @@ impl<'a> Download<'a> { // Get the metadata nonce // TODO: don't unwrap here, return an error - let nonce = b64::decode_standard( + let nonce = b64::decode( response.headers() .get_raw(HEADER_AUTH_NONCE) .expect("missing authenticate header") @@ -380,7 +380,7 @@ impl MetadataResponse { // TODO: do not unwrap, return a proper error pub fn decrypt_metadata(&self, key_set: &KeySet) -> Result { // Decode the metadata - let raw = b64::decode_url(&self.meta) + let raw = b64::decode(&self.meta) .expect("failed to decode metadata from server"); // Get the encrypted metadata, and it's tag diff --git a/api/src/crypto/b64.rs b/api/src/crypto/b64.rs index 8a4bb16..75a62a1 100644 --- a/api/src/crypto/b64.rs +++ b/api/src/crypto/b64.rs @@ -13,17 +13,14 @@ pub fn encode(input: &[u8]) -> String { base64::encode_config(input, base64::URL_SAFE_NO_PAD) } -/// Decode the given string as base64, with the given configuration. -pub fn decode(input: &str, config: Config) -> Result, DecodeError> { - base64::decode_config(input, config) -} - -/// Decode the given string as base64, in an URL-safe manner. -pub fn decode_url(input: &str) -> Result, DecodeError> { - decode(input, base64::URL_SAFE_NO_PAD) -} - -/// Decode the given string as base64, with the standaard character set. -pub fn decode_standard(input: &str) -> Result, DecodeError> { - decode(input, base64::STANDARD) +/// Decode the given string as base64. +/// Standard and URL-safe character sets are both supported, +/// padding is optional. +pub fn decode(input: &str) -> Result, DecodeError> { + base64::decode_config( + input.replace('+', "-") + .replace('/', "_") + .trim_right_matches('='), + base64::URL_SAFE_NO_PAD, + ) } diff --git a/api/src/file/file.rs b/api/src/file/file.rs index d0dd9f7..b35852f 100644 --- a/api/src/file/file.rs +++ b/api/src/file/file.rs @@ -181,7 +181,7 @@ impl DownloadFile { .ok_or(FileParseError::InvalidSecret)? .get(1) { - secret = b64::decode_url(raw.as_str().trim()) + secret = b64::decode(raw.as_str().trim()) .map_err(|_| FileParseError::InvalidSecret)? } } diff --git a/api/src/file/metadata.rs b/api/src/file/metadata.rs index efe6bd2..1d77628 100644 --- a/api/src/file/metadata.rs +++ b/api/src/file/metadata.rs @@ -51,7 +51,7 @@ impl Metadata { // TODO: use an input vector length from a constant pub fn iv(&self) -> [u8; 12] { // Decode the input vector - let decoded = b64::decode_url(&self.iv).unwrap(); + let decoded = b64::decode(&self.iv).unwrap(); // Create a sized array *array_ref!(decoded, 0, 12)