From 96f22159be1a75c69102e3069a4afbcc390ad00d Mon Sep 17 00:00:00 2001 From: rasul Date: Sat, 1 Feb 2020 15:17:48 -0600 Subject: [PATCH] use config.salt instead of something hard coded --- src/paste.rs | 8 ++++---- src/routes/submit.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/paste.rs b/src/paste.rs index 78e6c3c..5fde797 100644 --- a/src/paste.rs +++ b/src/paste.rs @@ -30,9 +30,9 @@ impl Paste { Ok(paste) } - pub fn from_text(text: String) -> Result { + pub fn from_text(text: String, salt: String) -> Result { let dt = Utc::now(); - let harsh = HarshBuilder::new().salt("salt and pepper").init()?; + let harsh = HarshBuilder::new().salt(salt).init()?; let encoded = harsh.encode(&[dt.timestamp_millis() as u64]); if let Some(id) = encoded { @@ -48,9 +48,9 @@ impl Paste { } - pub fn from_form(form: HashMap) -> Result { + pub fn from_form(form: HashMap, salt: String) -> Result { let dt = Utc::now(); - let harsh = HarshBuilder::new().salt("salt and pepper").init()?; + let harsh = HarshBuilder::new().salt(salt).init()?; let encoded = harsh.encode(&[dt.timestamp_millis() as u64]); if let Some(id) = encoded { diff --git a/src/routes/submit.rs b/src/routes/submit.rs index 134bf2d..e357d63 100644 --- a/src/routes/submit.rs +++ b/src/routes/submit.rs @@ -25,7 +25,7 @@ pub fn put(mut state: State) -> Box { let body_content = b.into_bytes(); let text = String::from_utf8(body_content.as_ref().to_vec()).unwrap(); - match Paste::from_text(text) { + match Paste::from_text(text, config.salt) { Ok(paste) => { let mut path = config.data_directory.clone(); path.push(paste.id.clone()); @@ -69,7 +69,7 @@ pub fn post(mut state: State) -> Box { .map(|x| x) .collect(); - if let Ok(paste) = Paste::from_form(form_map) { + if let Ok(paste) = Paste::from_form(form_map, config.salt) { let mut path = config.data_directory; path.push(paste.id.clone());