Refactor: add a set_fingerprint() method to CardApp.
Use that method instead of manually calling the apdu command. Change type of fingerprint in CardUploadableKey to [u8; 20].
This commit is contained in:
parent
260c38ef25
commit
a0d92d2dc4
4 changed files with 24 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
//! sequoia_openpgp data structures.
|
//! sequoia_openpgp data structures.
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
@ -171,8 +172,11 @@ impl CardUploadableKey for SequoiaKey {
|
||||||
ts.into()
|
ts.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fp(&self) -> Vec<u8> {
|
fn get_fp(&self) -> [u8; 20] {
|
||||||
self.key.fingerprint().as_bytes().to_vec()
|
let fp = self.key.fingerprint();
|
||||||
|
assert_eq!(fp.as_bytes().len(), 20);
|
||||||
|
|
||||||
|
fp.as_bytes().try_into().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -546,6 +546,19 @@ impl CardApp {
|
||||||
apdu::send_command(&mut self.card_client, time_cmd, false)
|
apdu::send_command(&mut self.card_client, time_cmd, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_fingerprint(
|
||||||
|
&mut self,
|
||||||
|
fp: [u8; 20],
|
||||||
|
key_type: KeyType,
|
||||||
|
) -> Result<Response, OpenpgpCardError> {
|
||||||
|
let fp_cmd = commands::put_data(
|
||||||
|
&[key_type.get_fingerprint_put_tag()],
|
||||||
|
fp.to_vec(),
|
||||||
|
);
|
||||||
|
|
||||||
|
apdu::send_command(self.card(), fp_cmd, true)
|
||||||
|
}
|
||||||
|
|
||||||
/// Set algorithm attributes [4.4.3.9 Algorithm Attributes]
|
/// Set algorithm attributes [4.4.3.9 Algorithm Attributes]
|
||||||
pub fn set_algorithm_attributes(
|
pub fn set_algorithm_attributes(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -40,10 +40,7 @@ pub(crate) fn gen_key_with_metadata(
|
||||||
|
|
||||||
// calculate/store fingerprint
|
// calculate/store fingerprint
|
||||||
let fp = fp_from_pub(&pubkey, time)?;
|
let fp = fp_from_pub(&pubkey, time)?;
|
||||||
let fp_cmd =
|
card_app.set_fingerprint(fp, key_type)?.check_ok()?;
|
||||||
commands::put_data(&[key_type.get_fingerprint_put_tag()], fp.to_vec());
|
|
||||||
|
|
||||||
apdu::send_command(card_app.card(), fp_cmd, true)?.check_ok()?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -442,12 +439,10 @@ fn copy_key_to_card(
|
||||||
card_app: &mut CardApp,
|
card_app: &mut CardApp,
|
||||||
key_type: KeyType,
|
key_type: KeyType,
|
||||||
ts: u32,
|
ts: u32,
|
||||||
fp: Vec<u8>,
|
fp: [u8; 20],
|
||||||
algo: &Algo,
|
algo: &Algo,
|
||||||
key_cmd: Command,
|
key_cmd: Command,
|
||||||
) -> Result<(), OpenpgpCardError> {
|
) -> Result<(), OpenpgpCardError> {
|
||||||
let fp_cmd = commands::put_data(&[key_type.get_fingerprint_put_tag()], fp);
|
|
||||||
|
|
||||||
// Send all the commands
|
// Send all the commands
|
||||||
|
|
||||||
// FIXME: Only write algo attributes to the card if "extended
|
// FIXME: Only write algo attributes to the card if "extended
|
||||||
|
@ -457,7 +452,8 @@ fn copy_key_to_card(
|
||||||
.check_ok()?;
|
.check_ok()?;
|
||||||
|
|
||||||
apdu::send_command(card_app.card(), key_cmd, false)?.check_ok()?;
|
apdu::send_command(card_app.card(), key_cmd, false)?.check_ok()?;
|
||||||
apdu::send_command(card_app.card(), fp_cmd, false)?.check_ok()?;
|
|
||||||
|
card_app.set_fingerprint(fp, key_type)?.check_ok()?;
|
||||||
|
|
||||||
card_app.set_creation_time(ts, key_type)?.check_ok()?;
|
card_app.set_creation_time(ts, key_type)?.check_ok()?;
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ pub trait CardUploadableKey {
|
||||||
fn get_ts(&self) -> u32;
|
fn get_ts(&self) -> u32;
|
||||||
|
|
||||||
/// fingerprint
|
/// fingerprint
|
||||||
fn get_fp(&self) -> Vec<u8>;
|
fn get_fp(&self) -> [u8; 20];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Algorithm-independent container for public key material retrieved from
|
/// Algorithm-independent container for public key material retrieved from
|
||||||
|
|
Loading…
Reference in a new issue