extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; extern crate urlencoding; #[derive(Serialize, Deserialize)] pub struct OTP { secret: String, label: String, digits: i64, #[serde(rename = "type")] otp_type: String, algorithm: String, thumbnail: String, last_used: i64, period: i64, tags: Vec, } fn main() { let otp_array_json = match std::env::args().nth(1) { Some(otp_array) => otp_array, None => { eprintln!("Could not get json containing OTPs."); return; } }; let otp_array: Vec = match serde_json::from_str(&otp_array_json) { Ok(otp_array) => otp_array, Err(err) => { eprintln!("Could not deserialize OTPs: {}", err); return; } }; for otp in otp_array { println!( "otpauth://{}/{}?secret={}&algorithm={}&digits={}&period={}", otp.otp_type.to_ascii_lowercase(), urlencoding::encode(&otp.label), otp.secret, otp.algorithm, otp.digits, otp.period ); } }