Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Aug 13, 2024
1 parent 7b065dd commit a566b63
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 197 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
27 changes: 0 additions & 27 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// use core::task::Poll;

// use crate::api::Reply;
// use crate::client::RawClient;

pub type Result<T, E = Error> = core::result::Result<T, E>;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
Expand Down Expand Up @@ -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<core::result::Result<Reply, Error>> {
// // 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
// }
// }
// }
161 changes: 1 addition & 160 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Self, ()> {
// // 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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<MAX_APPLICATION_NAME_LENGTH>,
// 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<Mechanism>,

// 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<ShortData> for Letters {
type Error = crate::error::Error;

fn try_from(bytes: ShortData) -> Result<Self, Self::Error> {
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -610,7 +452,6 @@ pub enum Mechanism {
Rsa4096Pkcs1v15,
}

pub type LongData = Bytes<MAX_LONG_DATA_LENGTH>;
pub type MediumData = Bytes<MAX_MEDIUM_DATA_LENGTH>;
pub type ShortData = Bytes<MAX_SHORT_DATA_LENGTH>;

Expand Down

0 comments on commit a566b63

Please sign in to comment.