Skip to content

Commit

Permalink
Reduce external re-exports
Browse files Browse the repository at this point in the history
This patch removes all re-exports of external types as discussed
in trussed-dev#155, except for those that are essential for using Trussed:
heapless_bytes::Bytes (only from the types module) and
littlefs2::path::{Path, PathBuf}.

Also, the cbor_smol re-exports in the main module are kept until we have
a better mechanism for that.

trussed-dev#155
  • Loading branch information
robin-nitrokey committed Apr 3, 2024
1 parent 83cf940 commit 9d2456b
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
of being generic over the storage implementation.
- Add `nonce` argument to `wrap_key` and `unwrap_key` syscalls.
- Use nonce as IV for Aes256Cbc mechanism.
- Reduce re-exports ([#155][]):
- Remove most re-exports of external types

### Fixed

Expand All @@ -58,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#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
[#155]: https://github.com/trussed-dev/trussed/issues/155

## [0.1.0] - 2022-01-26

Expand Down
1 change: 0 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use heapless::Vec;
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize};
use zeroize::Zeroize;

pub use crate::Bytes;
use crate::{
config::{MAX_KEY_MATERIAL_LENGTH, MAX_SERIALIZED_KEY_LENGTH},
Error,
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
extern crate delog;
generate_macros!();

pub use interchange::Interchange;

pub mod api;
pub mod backend;
pub mod client;
Expand Down Expand Up @@ -50,15 +48,14 @@ pub use platform::Platform;
pub use service::Service;

pub use cbor_smol::{cbor_deserialize, cbor_serialize_bytes};
pub use heapless_bytes::Bytes;

pub(crate) use postcard::from_bytes as postcard_deserialize;

pub(crate) fn postcard_serialize_bytes<T: serde::Serialize, const N: usize>(
object: &T,
) -> postcard::Result<Bytes<N>> {
) -> postcard::Result<types::Bytes<N>> {
let vec = postcard::to_vec(object)?;
Ok(Bytes::from(vec))
Ok(types::Bytes::from(vec))
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion src/mechanisms/totp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::error::Error;
use crate::key;
use crate::service::{Exists, Sign};
use crate::store::keystore::Keystore;
use crate::types::Bytes;

// code copied from https://github.com/avacariu/rust-oath

Expand Down Expand Up @@ -72,7 +73,7 @@ impl Sign for super::Totp {

// return signature (encode as LE)
Ok(reply::Sign {
signature: crate::Bytes::from_slice(totp_material.to_le_bytes().as_ref()).unwrap(),
signature: Bytes::from_slice(totp_material.to_le_bytes().as_ref()).unwrap(),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//!
//! TODO: Currently, `Platform::R` lacks the `CryptoRng` bound.

// pub use rand_core::{CryptoRng, RngCore};
use rand_core::{CryptoRng, RngCore};

pub use crate::store::Store;
pub use crate::types::consent;
pub use crate::types::{reboot, ui};
pub use rand_core::{CryptoRng, RngCore};

pub trait UserInterface {
/// Check if the user has indicated their presence so as to give
Expand Down
6 changes: 3 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use heapless::Vec;
use littlefs2::{
object_safe::DynFilesystem,
path,
path::{Path, PathBuf},
};
use rand_chacha::ChaCha8Rng;
pub use rand_core::{RngCore, SeedableRng};
use rand_core::{RngCore, SeedableRng};

use crate::backend::{BackendId, CoreOnly, Dispatch};
use crate::client::{ClientBuilder, ClientImplementation};
Expand All @@ -23,8 +24,7 @@ pub use crate::store::{
keystore::{ClientKeystore, Keystore},
};
use crate::types::ui::Status;
use crate::types::{Context, CoreContext, Location, Mechanism, MediumData, Message, Vec};
use crate::Bytes;
use crate::types::{Bytes, Context, CoreContext, Location, Mechanism, MediumData, Message};
use crate::{
api::{reply, request, Reply, Request},
interrupt::InterruptFlag,
Expand Down
3 changes: 1 addition & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ use crate::types::{Bytes, Location, PathBuf};
use cortex_m_semihosting::hprintln;
use littlefs2::{
fs::{DirEntry, Metadata},
object_safe::DynFilesystem,
path::Path,
};

pub use littlefs2::object_safe::{DynFile, DynFilesystem, DynStorage};

pub mod certstore;
pub mod counterstore;
pub mod filestore;
Expand Down
4 changes: 2 additions & 2 deletions src/store/counterstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand_chacha::ChaCha8Rng;
use crate::{
error::{Error, Result},
store::{self, Store},
types::{CounterId, Location},
types::{Bytes, CounterId, Location},
};

pub struct ClientCounterstore<S>
Expand Down Expand Up @@ -37,7 +37,7 @@ impl<S: Store> ClientCounterstore<S> {

fn read_counter(&mut self, location: Location, id: CounterId) -> Result<Counter> {
let path = self.counter_path(id);
let mut bytes: crate::Bytes<16> = store::read(self.store, location, &path)?;
let mut bytes: Bytes<16> = store::read(self.store, location, &path)?;
bytes.resize_default(16).ok();
Ok(u128::from_le_bytes(bytes.as_slice().try_into().unwrap()))
}
Expand Down
3 changes: 1 addition & 2 deletions src/store/filestore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
error::{Error, Result},
// service::ReadDirState,
store::{self, DynFilesystem, Store},
types::{Location, Message, UserAttribute},
Bytes,
types::{Bytes, Location, Message, UserAttribute},
};
use littlefs2::path;

Expand Down
3 changes: 1 addition & 2 deletions src/store/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::{
error::{Error, Result},
key,
store::{self, Store},
types::{KeyId, Location},
Bytes,
types::{Bytes, KeyId, Location},
};

pub type ClientId = PathBuf;
Expand Down
15 changes: 5 additions & 10 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use core::marker::PhantomData;
use core::ops::Deref;

pub use generic_array::GenericArray;

pub use heapless::{String, Vec};
use heapless::String;
use rand_core::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};

pub use crate::Bytes;
pub use heapless_bytes::Bytes;

pub use littlefs2::{
driver::Storage as LfsStorage,
fs::{DirEntry, Filesystem, Metadata},
io::Result as LfsResult,
fs::{DirEntry, Metadata},
path::{Path, PathBuf},
};

use rand_core::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};

use crate::config::*;
use crate::store::filestore::{ReadDirFilesState, ReadDirState};
use crate::{interrupt::InterruptFlag, key::Secrecy};
Expand Down

0 comments on commit 9d2456b

Please sign in to comment.