1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 05:58:09 +00:00
trezor-firmware/rust/trezor-client/examples/change_pin.rs
2023-07-11 13:50:33 +02:00

32 lines
755 B
Rust

use std::io;
fn read_pin() -> String {
println!("Enter PIN");
let mut pin = String::new();
if io::stdin().read_line(&mut pin).unwrap() != 5 {
println!("must enter pin, received: {}", pin);
}
// trim newline
pin[..4].to_owned()
}
fn do_main() -> Result<(), trezor_client::Error> {
// init with debugging
let mut trezor = trezor_client::unique(true)?;
trezor.init_device(None)?;
let old_pin = trezor.change_pin(false)?.button_request()?.ack()?.pin_matrix_request()?;
let new_pin1 = old_pin.ack_pin(read_pin())?.pin_matrix_request()?;
let new_pin2 = new_pin1.ack_pin(read_pin())?.pin_matrix_request()?;
new_pin2.ack_pin(read_pin())?.ok()?;
Ok(())
}
fn main() {
do_main().unwrap()
}