diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-11 03:33:47 +0000 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2019-01-11 04:37:07 +0100 |
commit | 20be1c3ff7127f8bff5899c716b3445eaff4c74c (patch) | |
tree | 149202e61cee5eeb931a6018404c3d2f2f449366 /src | |
parent | fa2dfee36238fad8951217d258ce8b7360f3539f (diff) | |
download | nitrocli-otp-qr-master.tar.gz nitrocli-otp-qr-master.tar.bz2 |
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 23 |
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)?; } |