opgpcard: Extract factory_reset command into module
This commit is contained in:
parent
3615087065
commit
d0ad41c9f5
4 changed files with 29 additions and 15 deletions
|
@ -87,10 +87,7 @@ pub enum Command {
|
|||
},
|
||||
|
||||
/// Completely reset a card (deletes all data, including the keys on the card!)
|
||||
FactoryReset {
|
||||
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||
ident: String,
|
||||
},
|
||||
FactoryReset(commands::factory_reset::FactoryResetCommand),
|
||||
|
||||
/// Change identity (applies only to Nitrokey Start)
|
||||
SetIdentity {
|
||||
|
|
25
tools/src/bin/opgpcard/commands/factory_reset.rs
Normal file
25
tools/src/bin/opgpcard/commands/factory_reset.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
// SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer <heiko@schaefer.name>
|
||||
// SPDX-FileCopyrightText: 2022 Nora Widdecke <mail@nora.pink>
|
||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::Parser;
|
||||
|
||||
use openpgp_card_sequoia::card::Card;
|
||||
|
||||
use crate::util;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct FactoryResetCommand {
|
||||
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||
ident: String,
|
||||
}
|
||||
|
||||
pub fn factory_reset(command: FactoryResetCommand) -> Result<()> {
|
||||
println!("Resetting Card {}", command.ident);
|
||||
let card = util::open_card(&command.ident)?;
|
||||
let mut card = Card::new(card);
|
||||
|
||||
let mut open = card.transaction()?;
|
||||
open.factory_reset().map_err(|e| anyhow!(e))
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
pub mod decrypt;
|
||||
pub mod factory_reset;
|
||||
pub mod info;
|
||||
pub mod pubkey;
|
||||
pub mod sign;
|
||||
|
|
|
@ -147,8 +147,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
}
|
||||
},
|
||||
cli::Command::FactoryReset { ident } => {
|
||||
factory_reset(&ident)?;
|
||||
cli::Command::FactoryReset(cmd) => {
|
||||
commands::factory_reset::factory_reset(cmd)?;
|
||||
}
|
||||
cli::Command::Admin {
|
||||
ident,
|
||||
|
@ -579,15 +579,6 @@ fn pick_card_for_reading(ident: Option<String>) -> Result<Box<dyn CardBackend +
|
|||
}
|
||||
}
|
||||
|
||||
fn factory_reset(ident: &str) -> Result<()> {
|
||||
println!("Resetting Card {}", ident);
|
||||
let card = util::open_card(ident)?;
|
||||
let mut card = Card::new(card);
|
||||
|
||||
let mut open = card.transaction()?;
|
||||
open.factory_reset().map_err(|e| anyhow!(e))
|
||||
}
|
||||
|
||||
fn keys_pick_yolo<'a>(
|
||||
key: &'a Cert,
|
||||
policy: &'a dyn Policy,
|
||||
|
|
Loading…
Reference in a new issue