Doc improvements and minor cleanups (#281)

This commit is contained in:
Tony Arcieri (iqlusion)
2021-07-12 11:57:42 -07:00
committed by GitHub
parent 47776ebf0b
commit 5f418bbd1d
8 changed files with 20 additions and 12 deletions
+4 -4
View File
@@ -33,6 +33,7 @@
use crate::{Error, Result, YubiKey}; use crate::{Error, Result, YubiKey};
use rand_core::{OsRng, RngCore}; use rand_core::{OsRng, RngCore};
use std::{ use std::{
convert::TryInto,
fmt::{self, Debug, Display}, fmt::{self, Debug, Display},
str, str,
}; };
@@ -99,13 +100,12 @@ impl Ccc {
return Err(Error::GenericError); return Err(Error::GenericError);
} }
let mut ccc = [0u8; Self::BYTE_SIZE]; Ok(Self(response[..Self::BYTE_SIZE].try_into().unwrap()))
ccc.copy_from_slice(&response[0..Self::BYTE_SIZE]);
Ok(Self(ccc))
} }
/// Set Cardholder Capability Container (CCC) ID /// Set Cardholder Capability Container (CCC) ID
#[cfg(feature = "untested")] #[cfg(feature = "untested")]
#[cfg_attr(docsrs, doc(cfg(feature = "untested")))]
pub fn set(&self, yubikey: &mut YubiKey) -> Result<()> { pub fn set(&self, yubikey: &mut YubiKey) -> Result<()> {
let mut buf = CCC_TMPL.to_vec(); let mut buf = CCC_TMPL.to_vec();
buf[0..self.0.len()].copy_from_slice(&self.0); buf[0..self.0.len()].copy_from_slice(&self.0);
@@ -117,6 +117,6 @@ impl Ccc {
impl Display for Ccc { impl Display for Ccc {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", str::from_utf8(&hex::encode(&self.0[..])).unwrap()) f.write_str(str::from_utf8(&hex::encode(&self.0[..])).unwrap())
} }
} }
+1
View File
@@ -472,6 +472,7 @@ impl Certificate {
/// Delete a certificate located at the given slot of the given YubiKey /// Delete a certificate located at the given slot of the given YubiKey
#[cfg(feature = "untested")] #[cfg(feature = "untested")]
#[cfg_attr(docsrs, doc(cfg(feature = "untested")))]
pub fn delete(yubikey: &mut YubiKey, slot: SlotId) -> Result<()> { pub fn delete(yubikey: &mut YubiKey, slot: SlotId) -> Result<()> {
let txn = yubikey.begin_transaction()?; let txn = yubikey.begin_transaction()?;
write_certificate(&txn, slot, None, CertInfo::Uncompressed) write_certificate(&txn, slot, None, CertInfo::Uncompressed)
+1 -1
View File
@@ -133,6 +133,6 @@ impl ChuId {
impl Display for ChuId { impl Display for ChuId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", str::from_utf8(&hex::encode(&self.0[..])).unwrap()) f.write_str(str::from_utf8(&hex::encode(&self.0[..])).unwrap())
} }
} }
+9 -3
View File
@@ -33,10 +33,12 @@
//! # Supported Algorithms //! # Supported Algorithms
//! //!
//! - **Authentication**: `3DES` //! - **Authentication**: `3DES`
//! - **Encryption**: `RSA1024`, `RSA2048`, `ECCP256`, `ECCP384` //! - **Encryption**:
//! - RSA: `RSA1024`, `RSA2048`
//! - ECC: `ECCP256`, `ECCP384` (NIST curves: P-256, P-384)
//! - **Signatures**: //! - **Signatures**:
//! - RSASSA-PKCS#1v1.5: `RSA1024`, `RSA2048` //! - RSASSA-PKCS#1v1.5: `RSA1024`, `RSA2048`
//! - ECDSA: `ECCP256`, `ECCP384` //! - ECDSA: `ECCP256`, `ECCP384` (NIST curves: P-256, P-384)
//! //!
//! NOTE: RSASSA-PSS signatures and RSA-OAEP encryption may be supportable (TBD) //! NOTE: RSASSA-PSS signatures and RSA-OAEP encryption may be supportable (TBD)
//! //!
@@ -47,7 +49,9 @@
//! Any functionality which is gated on the `untested` feature has not been //! Any functionality which is gated on the `untested` feature has not been
//! properly tested and is not known to function correctly. //! properly tested and is not known to function correctly.
//! //!
//! If //! Please see the [`untested` functionality tracking issue] for current status.
//! We would appreciate any help testing this functionality and removing the
//! `untested` gating as well as writing more automated tests.
//! //!
//! # History //! # History
//! //!
@@ -91,6 +95,7 @@
//! [YubiKey NEO]: https://support.yubico.com/support/solutions/articles/15000006494-yubikey-neo //! [YubiKey NEO]: https://support.yubico.com/support/solutions/articles/15000006494-yubikey-neo
//! [YubiKey 4]: https://support.yubico.com/support/solutions/articles/15000006486-yubikey-4 //! [YubiKey 4]: https://support.yubico.com/support/solutions/articles/15000006486-yubikey-4
//! [YubiKey 5]: https://www.yubico.com/products/yubikey-5-overview/ //! [YubiKey 5]: https://www.yubico.com/products/yubikey-5-overview/
//! [`untested` functionality tracking issue]: https://github.com/iqlusioninc/yubikey.rs/issues/280
//! [yubico-piv-tool]: https://github.com/Yubico/yubico-piv-tool/ //! [yubico-piv-tool]: https://github.com/Yubico/yubico-piv-tool/
//! [Corrode]: https://github.com/jameysharp/corrode //! [Corrode]: https://github.com/jameysharp/corrode
//! [piv-tool-guide]: https://www.yubico.com/wp-content/uploads/2016/05/Yubico_PIV_Tool_Command_Line_Guide_en.pdf //! [piv-tool-guide]: https://www.yubico.com/wp-content/uploads/2016/05/Yubico_PIV_Tool_Command_Line_Guide_en.pdf
@@ -158,6 +163,7 @@ mod yubikey;
pub use crate::{ pub use crate::{
cccid::{CardId, Ccc}, cccid::{CardId, Ccc},
certificate::Certificate,
chuid::ChuId, chuid::ChuId,
config::Config, config::Config,
error::{Error, Result}, error::{Error, Result},
+3
View File
@@ -88,6 +88,7 @@ impl<T: MetadataType> Metadata<T> {
/// Write metadata /// Write metadata
#[cfg(feature = "untested")] #[cfg(feature = "untested")]
#[cfg_attr(docsrs, doc(cfg(feature = "untested")))]
pub(crate) fn write(&self, txn: &Transaction<'_>) -> Result<()> { pub(crate) fn write(&self, txn: &Transaction<'_>) -> Result<()> {
if self.inner.len() > CB_OBJ_MAX - CB_OBJ_TAG_MAX { if self.inner.len() > CB_OBJ_MAX - CB_OBJ_TAG_MAX {
return Err(Error::GenericError); return Err(Error::GenericError);
@@ -105,6 +106,7 @@ impl<T: MetadataType> Metadata<T> {
/// Delete metadata /// Delete metadata
#[cfg(feature = "untested")] #[cfg(feature = "untested")]
#[cfg_attr(docsrs, doc(cfg(feature = "untested")))]
pub(crate) fn delete(txn: &Transaction<'_>) -> Result<()> { pub(crate) fn delete(txn: &Transaction<'_>) -> Result<()> {
txn.save_object(T::obj_id(), &[]) txn.save_object(T::obj_id(), &[])
} }
@@ -128,6 +130,7 @@ impl<T: MetadataType> Metadata<T> {
/// Set metadata item /// Set metadata item
#[cfg(feature = "untested")] #[cfg(feature = "untested")]
#[cfg_attr(docsrs, doc(cfg(feature = "untested")))]
pub(crate) fn set_item(&mut self, tag: u8, item: &[u8]) -> Result<()> { pub(crate) fn set_item(&mut self, tag: u8, item: &[u8]) -> Result<()> {
let mut cb_temp: usize = 0; let mut cb_temp: usize = 0;
let mut tag_temp: u8 = 0; let mut tag_temp: u8 = 0;
-2
View File
@@ -325,7 +325,6 @@ impl MgmKey {
} }
/// Encrypt with 3DES key /// Encrypt with 3DES key
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(crate) fn encrypt(&self, input: &[u8; DES_LEN_DES]) -> [u8; DES_LEN_DES] { pub(crate) fn encrypt(&self, input: &[u8; DES_LEN_DES]) -> [u8; DES_LEN_DES] {
let mut output = input.to_owned(); let mut output = input.to_owned();
TdesEde3::new(GenericArray::from_slice(&self.0)) TdesEde3::new(GenericArray::from_slice(&self.0))
@@ -334,7 +333,6 @@ impl MgmKey {
} }
/// Decrypt with 3DES key /// Decrypt with 3DES key
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(crate) fn decrypt(&self, input: &[u8; DES_LEN_DES]) -> [u8; DES_LEN_DES] { pub(crate) fn decrypt(&self, input: &[u8; DES_LEN_DES]) -> [u8; DES_LEN_DES] {
let mut output = input.to_owned(); let mut output = input.to_owned();
TdesEde3::new(GenericArray::from_slice(&self.0)) TdesEde3::new(GenericArray::from_slice(&self.0))
+1 -1
View File
@@ -7,7 +7,7 @@
//! //!
//! - **Encryption**: //! - **Encryption**:
//! - RSA: `RSA1024`, `RSA2048` //! - RSA: `RSA1024`, `RSA2048`
//! - ECC: `ECCP256`, `ECCP384` (i.e. NIST curves: P-256, P-384) //! - ECC: `ECCP256`, `ECCP384` (NIST curves: P-256, P-384)
//! - **Signatures**: //! - **Signatures**:
//! - RSASSA-PKCS#1v1.5: `RSA1024`, `RSA2048` //! - RSASSA-PKCS#1v1.5: `RSA1024`, `RSA2048`
//! - ECDSA: `ECCP256`, `ECCP384` (NIST curves: P-256, P-384) //! - ECDSA: `ECCP256`, `ECCP384` (NIST curves: P-256, P-384)
+1 -1
View File
@@ -94,7 +94,7 @@ impl FromStr for Serial {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
u32::from_str(s).map(Serial).map_err(|_| Error::ParseError) s.parse().map(Serial).map_err(|_| Error::ParseError)
} }
} }