Skip to content

Commit

Permalink
Modify Service::new() to handle empty password
Browse files Browse the repository at this point in the history
Login password can't be empty. So, included a `panic!` to handle it.

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed May 6, 2024
1 parent 8f5d1d5 commit 9670b42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions server/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,13 @@ impl Service {
}

impl Service {
pub async fn new(password: String) -> Self {
pub async fn new(password: Option<String>) -> Self {
let path = format!("{}/{}", env::var("HOME").unwrap(), LOGIN_KEYRING_PATH);
let secret = Secret::from(password.into_bytes());
let secret = match password {
Some(pwd) => Secret::from(pwd.into_bytes()),
None => panic!("Login password can't be empty."),
};

Self {
collections: Arc::new(RwLock::new(Vec::new())),
keyring: Arc::new(Keyring::load(path, secret).await.unwrap()),
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ struct Args {
#[tokio::main]
async fn main() -> daemon::Result<()> {
let args = Args::parse();
let mut password = String::new();
let mut password = None;
tracing_subscriber::fmt::init();

if args.login {
password = rpassword::prompt_password("Enter the login password: ").unwrap();
password = Some(rpassword::prompt_password("Enter the login password: ").unwrap());
// TODO fix this unwrap
}

tracing::info!("Starting {}", BINARY_NAME);
Expand Down

0 comments on commit 9670b42

Please sign in to comment.