aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index ba5298d..bcd6db1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -188,6 +188,27 @@ fn query_name(label: &str, issuer: Option<&str>) -> Result<String, Error> {
}
}
+fn store_data(slot: u8, name: &str, data: &UrlData) -> Result<(), Error> {
+ let slot = slot.to_string();
+ let mut args = vec!["otp", "set", slot.as_ref(), name, data.secret.as_ref()];
+ args.append(&mut vec!["--algorithm", data.otp_type.as_ref()]);
+ args.append(&mut vec!["--format", "base32"]);
+ // TODO: parse digits
+ if let Some(ref counter) = data.counter {
+ args.append(&mut vec!["--counter", counter]);
+ }
+ if let Some(ref period) = data.period {
+ args.append(&mut vec!["--time-window", period]);
+ }
+
+ let status = process::Command::new("nitrocli").args(args).status()?;
+ if status.success() {
+ Ok(())
+ } else {
+ Err(Error::from("Could not set OTP data using nitrocli"))
+ }
+}
+
fn run(options: Options) -> Result<(), Error> {
let path = match options.file {
Some(ref file) => path::PathBuf::from(file),
@@ -199,7 +220,7 @@ fn run(options: Options) -> Result<(), Error> {
Some(name) => name,
None => query_name(&url_data.label, url_data.issuer.as_ref().map(|x| &**x))?,
};
- println!("{}: {:?}", name, url_data);
+ store_data(options.slot, &name, &url_data)?;
if options.file.is_none() {
fs::remove_file(&path)?;
}