From 79b1142f21f460092ae7ee938c811154c4019897 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 25 Nov 2019 08:49:29 -0800 Subject: [PATCH] Remove usages of YKPIV_OBJ_MAX_SIZE ...replacing them with `CB_BUF_MAX`. Both constants are 3072, however `CB_BUF_MAX` is what the original code was using. See discussion here: https://github.com/tarcieri/yubikey-piv.rs/pull/17#discussion_r350166104 --- src/consts.rs | 2 -- src/mgm.rs | 4 ++-- src/transaction.rs | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index 15ecfc0..39b1c35 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -229,8 +229,6 @@ pub const YKPIV_OBJ_MSROOTS3: u32 = 0x005f_ff13; pub const YKPIV_OBJ_MSROOTS4: u32 = 0x005f_ff14; pub const YKPIV_OBJ_MSROOTS5: u32 = 0x005f_ff15; -pub const YKPIV_OBJ_MAX_SIZE: usize = 3072; - pub const YKPIV_PINPOLICY_TAG: u8 = 0xaa; pub const YKPIV_PINPOLICY_DEFAULT: u8 = 0; pub const YKPIV_PINPOLICY_NEVER: u8 = 1; diff --git a/src/mgm.rs b/src/mgm.rs index ce4f561..bfcca67 100644 --- a/src/mgm.rs +++ b/src/mgm.rs @@ -165,7 +165,7 @@ impl MgmKey { /// Set protected management key (MGM) pub fn set_protected(&self, yubikey: &mut YubiKey) -> Result<(), Error> { - let mut data = Zeroizing::new(vec![0u8; YKPIV_OBJ_MAX_SIZE]); + let mut data = Zeroizing::new(vec![0u8; CB_BUF_MAX]); let max_size = yubikey.obj_size_max(); let txn = yubikey.begin_transaction()?; @@ -207,7 +207,7 @@ impl MgmKey { } // set the protected mgm flag in admin data - cb_data = YKPIV_OBJ_MAX_SIZE; + cb_data = data.len(); let mut flags_1 = [0u8; 1]; diff --git a/src/transaction.rs b/src/transaction.rs index 4b1f134..eda7104 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -455,7 +455,6 @@ impl<'tx> Transaction<'tx> { sw = response.status_words().code(); if sw != StatusWords::Success.code() && (sw >> 8 != 0x61) { - // TODO(tarcieri): is this really OK? return Ok(Response::new(sw.into(), Zeroizing::new(vec![]))); } @@ -484,7 +483,7 @@ impl<'tx> Transaction<'tx> { let indata_remaining = set_object(object_id, &mut indata); inlen -= indata_remaining.len(); - let response = self.transfer_data(&templ, &indata[..inlen], YKPIV_OBJ_MAX_SIZE)?; + let response = self.transfer_data(&templ, &indata[..inlen], CB_BUF_MAX)?; if !response.is_success() { return Err(Error::GenericError); @@ -523,7 +522,7 @@ impl<'tx> Transaction<'tx> { let templ = [0, YKPIV_INS_PUT_DATA, 0x3f, 0xff]; // TODO(tarcieri): replace with vector - let mut data = [0u8; YKPIV_OBJ_MAX_SIZE]; + let mut data = [0u8; CB_BUF_MAX]; if indata.len() > CB_OBJ_MAX { return Err(Error::SizeError);