aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-11 03:33:47 +0000
committerRobin Krahl <me@robin-krahl.de>2019-01-11 04:37:07 +0100
commit20be1c3ff7127f8bff5899c716b3445eaff4c74c (patch)
tree149202e61cee5eeb931a6018404c3d2f2f449366 /src
parentfa2dfee36238fad8951217d258ce8b7360f3539f (diff)
downloadnitrocli-otp-qr-master.tar.gz
nitrocli-otp-qr-master.tar.bz2
Store the parsed data on a Nitrokey deviceHEADmaster
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)?;
}