From a566b63586211b7ee2bab41c7728d32144307298 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 13 Aug 2024 15:44:16 +0200 Subject: [PATCH] Remove unused code --- CHANGELOG.md | 6 ++ src/config.rs | 10 ---- src/error.rs | 27 --------- src/types.rs | 161 +------------------------------------------------- 4 files changed, 7 insertions(+), 197 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec19bcd6f9..c33974c24c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 their namespace ([#65]). - wrap_key: Don't replace associated data with an empty array +### Removed + +- Removed unused items: + - `config`: `MAX_APPLICATION_NAME_LENGTH`, `MAX_LABEL_LENGTH`, `MAX_LONG_DATA_LENGTH`, `MAX_OBJECT_HANDLES`, `MAX_PATH_LENGTH` + - `types`: `Attributes`, `CertificateType` `DataAttributes`, `KeyAttributes`, `Letters`, `LongData`, `ObjectType` + [#64]: https://github.com/trussed-dev/trussed/issues/64 [#65]: https://github.com/trussed-dev/trussed/issues/65 [#99]: https://github.com/trussed-dev/trussed/issues/99 diff --git a/src/config.rs b/src/config.rs index ed40e95579c..d799cff4cd5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,18 +1,8 @@ -#![allow(non_camel_case_types)] -#![allow(clippy::upper_case_acronyms)] - -use littlefs2::consts; - // TODO: this needs to be overridable. // Should we use the "config crate that can have a replacement patched in" idea? -pub type MAX_APPLICATION_NAME_LENGTH = consts::U256; -pub const MAX_LONG_DATA_LENGTH: usize = 1024; pub const MAX_MESSAGE_LENGTH: usize = 1024; -pub type MAX_OBJECT_HANDLES = consts::U16; -pub type MAX_LABEL_LENGTH = consts::U256; pub const MAX_MEDIUM_DATA_LENGTH: usize = 256; -pub type MAX_PATH_LENGTH = consts::U256; cfg_if::cfg_if! { if #[cfg(test)] { pub const MAX_SERVICE_CLIENTS: usize = 6; diff --git a/src/error.rs b/src/error.rs index 1444789aa64..619bf5309fe 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,3 @@ -// use core::task::Poll; - -// use crate::api::Reply; -// use crate::client::RawClient; - pub type Result = core::result::Result; #[derive(Copy, Clone, Eq, PartialEq, Debug)] @@ -47,25 +42,3 @@ pub enum Error { WrongMessageLength, WrongSignatureLength, } - -// pub struct FutureResult<'a, 'c> { -// c: &'c mut RawClient<'a>, -// } - -// impl<'a, 'c> FutureResult<'a, 'c> { -// pub fn new(client: &'c mut RawClient<'a>) -> Self { -// Self { c: client } -// } - -// pub fn poll(&mut self) -> Poll> { -// // pop request in channel -// match self.c.ep.recv.dequeue() { -// Some(reply) => { -// #[cfg(all(test, feature = "verbose-tests"))] -// println!("got a reply"); -// Poll::Ready(reply) -// }, -// _ => Poll::Pending -// } -// } -// } diff --git a/src/types.rs b/src/types.rs index 0d2472965be..a359b630bdc 100644 --- a/src/types.rs +++ b/src/types.rs @@ -18,8 +18,8 @@ use rand_core::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; use crate::config::*; +use crate::interrupt::InterruptFlag; use crate::store::filestore::{ReadDirFilesState, ReadDirState}; -use crate::{interrupt::InterruptFlag, key::Secrecy}; pub use crate::client::FutureResult; pub use crate::platform::Platform; @@ -99,34 +99,6 @@ impl Id { buffer } - - // NOT IMPLEMENTED, as this would allow clients to create non-random (non-special) IDs. - // For testing, can construct directly as the newtypes have pub(crate) access. - // #[allow(clippy::result_unit_err)] - // pub fn try_from_hex(hex: &[u8]) -> core::result::Result { - // // https://stackoverflow.com/a/52992629 - // // (0..hex.len()) - // // use hex::FromHex; - // // let maybe_bytes = <[u8; 16]>::from_hex(hex).map_err(|e| ()); - // // maybe_bytes.map(|bytes| Self(Bytes::from_slice(&bytes).unwrap())) - // if (hex.len() & 1) == 1 { - // // panic!("hex len & 1 = {}", hex.len() & 1); - // return Err(()); - // } - // if hex.len() > 32 { - // // panic!("hex len {}", hex.len()); - // return Err(()); - // } - // // let hex = core::str::from_utf8(hex).map_err(|e| ())?; - // let hex = core::str::from_utf8(hex).unwrap(); - // // let hex = core::str::from_utf8_unchecked(hex); - // let mut bytes = [0u8; 16]; - // for i in 0..(hex.len() >> 1) { - // // bytes[i] = u8::from_str_radix(&hex[i..][..2], 16).map_err(|e| ())?; - // bytes[i] = u8::from_str_radix(&hex[2*i..][..2], 16).unwrap(); - // } - // Ok(Self(u128::from_be_bytes(bytes))) - // } } macro_rules! impl_id { @@ -253,21 +225,6 @@ pub mod consent { pub type Result = core::result::Result<(), Error>; } -// for counters use the pkcs#11 idea of -// a monotonic incrementing counter that -// "increments on each read" --> save +=1 operation - -// #[derive(Copy, Clone, Eq, PartialEq, Debug)] -// pub struct AeadUniqueId { -// unique_id: [u8; 16], -// nonce: [u8; 12], -// tag: [u8; 16], -// } - -// pub type AeadKey = [u8; 32]; -// pub type AeadNonce = [u8; 12]; -// pub type AeadTag = [u8; 16]; - /// The context for a syscall (per client). /// /// The context stores the state used by the standard syscall implementations, see @@ -342,111 +299,6 @@ impl From<&str> for CoreContext { // - Mechanism // - Profiles -#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] -#[allow(clippy::large_enum_variant)] -pub enum Attributes { - Certificate, - Counter, - Data(DataAttributes), - Key(KeyAttributes), -} - -#[derive(Clone, Eq, PartialEq, Debug)] -pub enum CertificateType { - // "identity", issued by certificate authority - // --> authentication - PublicKey, - // issued by attribute authority - // --> authorization - Attribute, -} - -// pub enum CertificateCategory { -// Authority, -// Token, -// Other, -// } - -// #[derive(Clone, Default, Eq, PartialEq, Debug)] -// pub struct CertificateAttributes { -// pub certificate_type CertificateType, -// } - -#[derive(Clone, Default, Eq, PartialEq, Debug, Serialize, Deserialize)] -pub struct DataAttributes { - // application that manages the object - // pub application: String, - // DER-encoding of *type* of data object - // pub object_id: Bytes, - pub kind: ShortData, - pub value: LongData, -} - -// TODO: In PKCS#11v3, this is a map (AttributeType: ulong -> (*void, len)). -// "An array of CK_ATTRIBUTEs is called a “template” and is used for creating, manipulating and searching for objects." -// -// Maybe we should put these attributes in an enum, and pass an `heapless::IndexSet` of attributes. -// How do we handle defaults? -// -// Lookup seems a bit painful, on the other hand a struct of options is wasteful. -#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] -pub struct KeyAttributes { - // secrecy: Secrecy, - // object_id: Bytes, - // derive: bool, // can other keys be derived - // local: bool, // generated on token, or copied from such - // key_gen_mechanism: Mechanism, // only for local, how was key generated - // allowed_mechanisms: Vec, - - // never return naked private key - sensitive: bool, - // always_sensitive: bool, - - // do not even return wrapped private key - extractable: bool, - // never_extractable: bool, - - // do not save to disk - persistent: bool, -} - -impl Default for KeyAttributes { - fn default() -> Self { - Self { - sensitive: true, - // always_sensitive: true, - extractable: false, - // never_extractable: true, - // cryptoki: token (vs session) object - // cryptoki: default false - persistent: false, - } - } -} - -impl KeyAttributes { - pub fn new() -> Self { - Default::default() - } -} - -/// Non-exhaustive to make it unconstructable -/// NB: Better to check in service that nothing snuck through! -#[derive(Clone, Default, Eq, PartialEq, Debug, Deserialize, Serialize)] -#[non_exhaustive] -pub struct Letters(pub ShortData); - -impl TryFrom for Letters { - type Error = crate::error::Error; - - fn try_from(bytes: ShortData) -> Result { - if !&bytes.iter().all(|b| *b >= b'a' && *b <= b'z') { - return Err(Self::Error::NotJustLetters); - } - Ok(Letters(bytes)) - } -} - impl Serialize for Id { fn serialize(&self, serializer: S) -> Result where @@ -485,16 +337,6 @@ impl<'de> Deserialize<'de> for Id { } } -#[derive(Clone, Eq, PartialEq, Debug)] -pub enum ObjectType { - Certificate(CertificateType), - // TODO: maybe group under Feature(FeautureType), with FeatureType = Counter, ... - // But what else?? - Counter, - Data, - Key(Secrecy), -} - #[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] pub enum Location { Volatile, @@ -610,7 +452,6 @@ pub enum Mechanism { Rsa4096Pkcs1v15, } -pub type LongData = Bytes; pub type MediumData = Bytes; pub type ShortData = Bytes;