mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-03 17:49:15 +02:00
Generalize base64 decode method, allow all formats for single method
This commit is contained in:
parent
4957c98f6d
commit
a7da14ec2c
4 changed files with 15 additions and 18 deletions
|
@ -76,7 +76,7 @@ impl<'a> Download<'a> {
|
||||||
|
|
||||||
// Get the authentication nonce
|
// Get the authentication nonce
|
||||||
// TODO: don't unwrap here, return an error
|
// TODO: don't unwrap here, return an error
|
||||||
let nonce = b64::decode_standard(
|
let nonce = b64::decode(
|
||||||
response.headers()
|
response.headers()
|
||||||
.get_raw(HEADER_AUTH_NONCE)
|
.get_raw(HEADER_AUTH_NONCE)
|
||||||
.expect("missing authenticate header")
|
.expect("missing authenticate header")
|
||||||
|
@ -115,7 +115,7 @@ impl<'a> Download<'a> {
|
||||||
|
|
||||||
// Get the metadata nonce
|
// Get the metadata nonce
|
||||||
// TODO: don't unwrap here, return an error
|
// TODO: don't unwrap here, return an error
|
||||||
let nonce = b64::decode_standard(
|
let nonce = b64::decode(
|
||||||
response.headers()
|
response.headers()
|
||||||
.get_raw(HEADER_AUTH_NONCE)
|
.get_raw(HEADER_AUTH_NONCE)
|
||||||
.expect("missing authenticate header")
|
.expect("missing authenticate header")
|
||||||
|
@ -380,7 +380,7 @@ impl MetadataResponse {
|
||||||
// TODO: do not unwrap, return a proper error
|
// TODO: do not unwrap, return a proper error
|
||||||
pub fn decrypt_metadata(&self, key_set: &KeySet) -> Result<Metadata> {
|
pub fn decrypt_metadata(&self, key_set: &KeySet) -> Result<Metadata> {
|
||||||
// Decode the metadata
|
// Decode the metadata
|
||||||
let raw = b64::decode_url(&self.meta)
|
let raw = b64::decode(&self.meta)
|
||||||
.expect("failed to decode metadata from server");
|
.expect("failed to decode metadata from server");
|
||||||
|
|
||||||
// Get the encrypted metadata, and it's tag
|
// Get the encrypted metadata, and it's tag
|
||||||
|
|
|
@ -13,17 +13,14 @@ pub fn encode(input: &[u8]) -> String {
|
||||||
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
|
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode the given string as base64, with the given configuration.
|
/// Decode the given string as base64.
|
||||||
pub fn decode(input: &str, config: Config) -> Result<Vec<u8>, DecodeError> {
|
/// Standard and URL-safe character sets are both supported,
|
||||||
base64::decode_config(input, config)
|
/// padding is optional.
|
||||||
}
|
pub fn decode(input: &str) -> Result<Vec<u8>, DecodeError> {
|
||||||
|
base64::decode_config(
|
||||||
/// Decode the given string as base64, in an URL-safe manner.
|
input.replace('+', "-")
|
||||||
pub fn decode_url(input: &str) -> Result<Vec<u8>, DecodeError> {
|
.replace('/', "_")
|
||||||
decode(input, base64::URL_SAFE_NO_PAD)
|
.trim_right_matches('='),
|
||||||
}
|
base64::URL_SAFE_NO_PAD,
|
||||||
|
)
|
||||||
/// Decode the given string as base64, with the standaard character set.
|
|
||||||
pub fn decode_standard(input: &str) -> Result<Vec<u8>, DecodeError> {
|
|
||||||
decode(input, base64::STANDARD)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl DownloadFile {
|
||||||
.ok_or(FileParseError::InvalidSecret)?
|
.ok_or(FileParseError::InvalidSecret)?
|
||||||
.get(1)
|
.get(1)
|
||||||
{
|
{
|
||||||
secret = b64::decode_url(raw.as_str().trim())
|
secret = b64::decode(raw.as_str().trim())
|
||||||
.map_err(|_| FileParseError::InvalidSecret)?
|
.map_err(|_| FileParseError::InvalidSecret)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl Metadata {
|
||||||
// TODO: use an input vector length from a constant
|
// TODO: use an input vector length from a constant
|
||||||
pub fn iv(&self) -> [u8; 12] {
|
pub fn iv(&self) -> [u8; 12] {
|
||||||
// Decode the input vector
|
// Decode the input vector
|
||||||
let decoded = b64::decode_url(&self.iv).unwrap();
|
let decoded = b64::decode(&self.iv).unwrap();
|
||||||
|
|
||||||
// Create a sized array
|
// Create a sized array
|
||||||
*array_ref!(decoded, 0, 12)
|
*array_ref!(decoded, 0, 12)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue