Skip to content

Commit ef1b524

Browse files
committed
Small corrections
1 parent f6dba0a commit ef1b524

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

flealib/src/commandprocessor.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate ftp;
22
extern crate repng;
33
extern crate serde;
44

5-
use serde::{Serialize, Deserialize};
5+
use serde::{Deserialize, Serialize};
66
use std::sync::{Arc, Mutex};
77
use std::{str, env, path::PathBuf};
88
use log::{debug, error};
@@ -46,6 +46,7 @@ pub const RESTART_FILENAME: &str = "flea.rst";
4646
#[cfg(feature = "camera")]
4747
const GET_CAMERA_FRAME_COMMAND: &str = "camera";
4848

49+
const MAX_KEY_LENGTH: usize = 32;
4950

5051
//Enter your data for FTP Server connection
5152
const FTP_USER_NAME: &str = "enter_ftp_user_name";
@@ -629,6 +630,13 @@ impl FleaCommand for CommandProcessor
629630
let mut parts = value.split(';');
630631
if let (Some(key), Some(file_name), None) = (parts.next(), parts.next(), parts.next())
631632
{
633+
if key.len() != MAX_KEY_LENGTH
634+
{
635+
debug!("Invalid key length");
636+
return "Invalid key length".to_string();
637+
}
638+
639+
debug!("Encrypting file: {}", file_name);
632640
let encrypter = FileEncrypter::new(key.to_string());
633641
match encrypter.encrypt_file(file_name)
634642
{
@@ -638,6 +646,7 @@ impl FleaCommand for CommandProcessor
638646
}
639647
else
640648
{
649+
debug!("Invalid input");
641650
"Invalid input".to_string()
642651
}
643652
},
@@ -650,7 +659,14 @@ impl FleaCommand for CommandProcessor
650659
let mut parts = value.split(';');
651660
if let (Some(key), Some(file_name), None) = (parts.next(), parts.next(), parts.next())
652661
{
662+
if key.len() != MAX_KEY_LENGTH
663+
{
664+
debug!("Invalid key length");
665+
return "Invalid key length".to_string();
666+
}
667+
653668
let encrypter = FileEncrypter::new(key.to_string());
669+
debug!("Decrypting file: {}", file_name);
654670
match encrypter.decrypt_file(file_name)
655671
{
656672
Ok(_) => "Ok".to_string(),
@@ -659,6 +675,7 @@ impl FleaCommand for CommandProcessor
659675
}
660676
else
661677
{
678+
debug!("Invalid input");
662679
"Invalid input".to_string()
663680
}
664681

0 commit comments

Comments
 (0)