1
0
mirror of https://github.com/timvisee/ffsend.git synced 2025-02-01 04:01:36 +01:00

Use URL-safe base64 encoding

This commit is contained in:
timvisee 2018-03-05 20:21:57 +01:00
parent 46d591fd27
commit 43f54d9332
No known key found for this signature in database
GPG Key ID: 109CBA0BF74036C2

View File

@ -107,7 +107,7 @@ fn main() {
// Make the request // Make the request
let mut res = client.post("http://localhost:8080/api/upload") let mut res = client.post("http://localhost:8080/api/upload")
.header(Authorization(format!("send-v1 {}", base64::encode(&auth_key)))) .header(Authorization(format!("send-v1 {}", base64_encode(&auth_key))))
.header(XFileMetadata::from(&metadata_encrypted)) .header(XFileMetadata::from(&metadata_encrypted))
.multipart(form) .multipart(form)
.send() .send()
@ -117,9 +117,10 @@ fn main() {
let upload_res: UploadResponse = res.json().unwrap(); let upload_res: UploadResponse = res.json().unwrap();
// Print the response // Print the response
let url = upload_res.download_url(&secret);
println!("Response: {:#?}", upload_res); println!("Response: {:#?}", upload_res);
println!("Secret key: {}", base64::encode(&secret)); println!("Secret key: {}", base64_encode(&secret));
println!("Download URL: {}", upload_res.download_url(&secret)); println!("Download URL: {}", url);
} }
fn hkdf<'a>( fn hkdf<'a>(
@ -183,7 +184,7 @@ impl Metadata {
/// * mime: file mimetype /// * mime: file mimetype
pub fn from(iv: &[u8], name: String, mime: Mime) -> Self { pub fn from(iv: &[u8], name: String, mime: Mime) -> Self {
Metadata { Metadata {
iv: base64::encode(iv), iv: base64_encode(iv),
name, name,
mime: mime.to_string(), mime: mime.to_string(),
} }
@ -209,7 +210,7 @@ impl XFileMetadata {
} }
pub fn from(bytes: &[u8]) -> Self { pub fn from(bytes: &[u8]) -> Self {
XFileMetadata::new(base64::encode(bytes)) XFileMetadata::new(base64_encode(bytes))
} }
} }
@ -309,6 +310,11 @@ impl UploadResponse {
/// ///
/// The secret bytes must be passed to `secret`. /// The secret bytes must be passed to `secret`.
pub fn download_url(&self, secret: &[u8]) -> String { pub fn download_url(&self, secret: &[u8]) -> String {
format!("{}#{}", self.url, base64::encode(secret)) format!("{}#{}", self.url, base64_encode(secret))
} }
} }
/// Encode the given byte slice using base64, in an URL-safe manner.
fn base64_encode(input: &[u8]) -> String {
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
}