-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c4eec0
commit 216c72d
Showing
10 changed files
with
190 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
use crate::cli::{GenerateArgs, SignArgs}; | ||
use crate::cli::{DistributeArgs, GenerateArgs, SignArgs}; | ||
|
||
pub trait GetPassword { | ||
fn get_password(&self) -> anyhow::Result<String>; | ||
} | ||
|
||
impl GetPassword for GenerateArgs { | ||
fn get_password(&self) -> anyhow::Result<String> { | ||
#[cfg(not(any(windows, unix)))] | ||
return Ok(self.password); | ||
#[cfg(any(windows, unix))] | ||
return Ok(rpassword::prompt_password("New password: ")?); | ||
get_password_common(self.password.as_ref(), "New password: ") | ||
} | ||
} | ||
|
||
impl GetPassword for SignArgs { | ||
fn get_password(&self) -> anyhow::Result<String> { | ||
#[cfg(not(any(windows, unix)))] | ||
return Ok(self.password); | ||
#[cfg(any(windows, unix))] | ||
return Ok(rpassword::prompt_password(format!( | ||
"Password for '{}': ", | ||
self.name | ||
))?); | ||
get_password_common( | ||
self.password.as_ref(), | ||
format!("Password for '{}': ", self.name), | ||
) | ||
} | ||
} | ||
|
||
impl GetPassword for DistributeArgs { | ||
fn get_password(&self) -> anyhow::Result<String> { | ||
get_password_common( | ||
self.password.as_ref(), | ||
format!("Password for '{}': ", self.name), | ||
) | ||
} | ||
} | ||
|
||
fn get_password_common( | ||
maybe_password: Option<&String>, | ||
prompt: impl ToString, | ||
) -> anyhow::Result<String> { | ||
match maybe_password { | ||
Some(password) => Ok(password.clone()), | ||
None => Ok(rpassword::prompt_password(prompt)?), | ||
} | ||
} |
Oops, something went wrong.