opgpcard: Restrict values of id of set-identity
This commit is contained in:
parent
a7731ec467
commit
e81ebd21a0
2 changed files with 24 additions and 5 deletions
|
@ -146,8 +146,8 @@ pub enum Command {
|
||||||
#[clap(name = "card ident", short = 'c', long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
ident: String,
|
||||||
|
|
||||||
#[clap(name = "identity")]
|
#[clap(name = "identity", value_enum)]
|
||||||
id: u8,
|
id: SetIdentityId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,3 +358,23 @@ impl From<TouchPolicy> for openpgp_card_sequoia::types::TouchPolicy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Debug, Clone)]
|
||||||
|
pub enum SetIdentityId {
|
||||||
|
#[clap(name = "0")]
|
||||||
|
Zero,
|
||||||
|
#[clap(name = "1")]
|
||||||
|
One,
|
||||||
|
#[clap(name = "2")]
|
||||||
|
Two,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SetIdentityId> for u8 {
|
||||||
|
fn from(id: SetIdentityId) -> Self {
|
||||||
|
match id {
|
||||||
|
SetIdentityId::Zero => 0,
|
||||||
|
SetIdentityId::One => 1,
|
||||||
|
SetIdentityId::Two => 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -579,13 +579,12 @@ fn list_cards(format: OutputFormat, output_version: OutputVersion) -> Result<()>
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_identity(ident: &str, id: u8) -> Result<(), Box<dyn std::error::Error>> {
|
fn set_identity(ident: &str, id: cli::SetIdentityId) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let backend = util::open_card(ident)?;
|
let backend = util::open_card(ident)?;
|
||||||
let mut card = Card::new(backend);
|
let mut card = Card::new(backend);
|
||||||
let mut open = card.transaction()?;
|
let mut open = card.transaction()?;
|
||||||
|
|
||||||
open.set_identity(id)?;
|
open.set_identity(u8::from(id))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue