use config.salt instead of something hard coded

master
rasul 5 years ago
parent 48784e9620
commit 96f22159be

@ -30,9 +30,9 @@ impl Paste {
Ok(paste) Ok(paste)
} }
pub fn from_text(text: String) -> Result<Self> { pub fn from_text(text: String, salt: String) -> Result<Self> {
let dt = Utc::now(); 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]); let encoded = harsh.encode(&[dt.timestamp_millis() as u64]);
if let Some(id) = encoded { if let Some(id) = encoded {
@ -48,9 +48,9 @@ impl Paste {
} }
pub fn from_form(form: HashMap<String, String>) -> Result<Self> { pub fn from_form(form: HashMap<String, String>, salt: String) -> Result<Self> {
let dt = Utc::now(); 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]); let encoded = harsh.encode(&[dt.timestamp_millis() as u64]);
if let Some(id) = encoded { if let Some(id) = encoded {

@ -25,7 +25,7 @@ pub fn put(mut state: State) -> Box<HandlerFuture> {
let body_content = b.into_bytes(); let body_content = b.into_bytes();
let text = String::from_utf8(body_content.as_ref().to_vec()).unwrap(); 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) => { Ok(paste) => {
let mut path = config.data_directory.clone(); let mut path = config.data_directory.clone();
path.push(paste.id.clone()); path.push(paste.id.clone());
@ -69,7 +69,7 @@ pub fn post(mut state: State) -> Box<HandlerFuture> {
.map(|x| x) .map(|x| x)
.collect(); .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; let mut path = config.data_directory;
path.push(paste.id.clone()); path.push(paste.id.clone());

Loading…
Cancel
Save