Skip to content

Commit

Permalink
Remove internal re-exports
Browse files Browse the repository at this point in the history
As discussed in trussed-dev#155, this patch removes re-exports from types that are
defined inside the crate.  This means that all types that are defined in
this crate are now only visible under one path.

trussed-dev#155
  • Loading branch information
robin-nitrokey committed Apr 3, 2024
1 parent 9d2456b commit 2e4e15a
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use nonce as IV for Aes256Cbc mechanism.
- Reduce re-exports ([#155][]):
- Remove most re-exports of external types
- Remove all re-exports of internal types

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions derive/src/extension_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl ExtensionId {
}

impl #impl_generics ::core::convert::TryFrom<u8> for #name #ty_generics #where_clause {
type Error = ::trussed::Error;
type Error = ::trussed::error::Error;

fn try_from(value: u8) -> ::core::result::Result<Self, Self::Error> {
match value {
#(#try_from)*
_ => Err(::trussed::Error::InternalError),
_ => Err(::trussed::error::Error::InternalError),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! [pkcs11-v3]: https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/pkcs11-base-v3.0.html
//! [pkcs11-headers]: https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/cs01/include/pkcs11-v3.0/

use crate::error::Error;
use crate::types::{
consent, reboot, Bytes, CertId, CounterId, DirEntry, KeyId, KeySerialization, Location,
Mechanism, MediumData, Message, PathBuf, SerializedKey, ShortData, Signature,
Expand Down Expand Up @@ -143,11 +144,11 @@ generate_enums! {
SerdeExtension: 0x5E
}

pub trait RequestVariant: Into<Request> + TryFrom<Request, Error = crate::Error> {
pub trait RequestVariant: Into<Request> + TryFrom<Request, Error = Error> {
type Reply: ReplyVariant<Request = Self>;
}

pub trait ReplyVariant: Into<Reply> + TryFrom<Reply, Error = crate::Error> {
pub trait ReplyVariant: Into<Reply> + TryFrom<Reply, Error = Error> {
type Request: RequestVariant<Reply = Self>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ macro_rules! impl_request {
}
}
impl core::convert::TryFrom<Request> for $request {
type Error = crate::Error;
type Error = crate::error::Error;
fn try_from(request: Request) -> Result<request::$request, Self::Error> {
match request {
Request::$request(request) => Ok(request),
_ => Err(crate::Error::InternalError),
_ => Err(crate::error::Error::InternalError),
}
}
}
Expand Down Expand Up @@ -118,11 +118,11 @@ macro_rules! impl_reply {

$(#[$attr])?
impl core::convert::TryFrom<Reply> for $reply {
type Error = crate::Error;
type Error = crate::error::Error;
fn try_from(reply: Reply) -> Result<reply::$reply, Self::Error> {
match reply {
Reply::$reply(reply) => Ok(reply),
_ => Err(crate::Error::InternalError),
_ => Err(crate::error::Error::InternalError),
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ use crate::backend::{BackendId, CoreOnly, Dispatch};
use crate::error::{Error, Result};
use crate::interrupt::InterruptFlag;
use crate::pipe::{TrussedRequester, TRUSSED_INTERCHANGE};
use crate::platform::{Platform, Syscall};
use crate::service::Service;
use crate::types::{
consent, reboot, Bytes, CertId, CounterId, KeyId, KeySerialization, Location, Mechanism,
MediumData, Message, PathBuf, Platform, SerializedKey, ShortData, Signature,
SignatureSerialization, StorageAttributes, UserAttribute,
MediumData, Message, PathBuf, SerializedKey, ShortData, Signature, SignatureSerialization,
StorageAttributes, UserAttribute,
};

pub use crate::platform::Syscall;

pub mod mechanisms;
pub use mechanisms::*;

// to be fair, this is a programmer error,
// and could also just panic
Expand Down
2 changes: 1 addition & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zeroize::Zeroize;

use crate::{
config::{MAX_KEY_MATERIAL_LENGTH, MAX_SERIALIZED_KEY_LENGTH},
Error,
error::Error,
};

pub type Material = Vec<u8, { MAX_KEY_MATERIAL_LENGTH }>;
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ pub mod types;
#[cfg_attr(docsrs, doc(cfg(feature = "virt")))]
pub mod virt;

pub use api::Reply;
pub use client::{Client, ClientImplementation};
pub use error::Error;
/// The trait that platforms need to implement to use Trussed.
pub use platform::Platform;
pub use service::Service;

pub use cbor_smol::{cbor_deserialize, cbor_serialize_bytes};

pub(crate) use postcard::from_bytes as postcard_deserialize;
Expand Down
5 changes: 2 additions & 3 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

use rand_core::{CryptoRng, RngCore};

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

pub trait UserInterface {
/// Check if the user has indicated their presence so as to give
Expand Down
17 changes: 10 additions & 7 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ use crate::backend::{BackendId, CoreOnly, Dispatch};
use crate::client::{ClientBuilder, ClientImplementation};
use crate::config::{MAX_MESSAGE_LENGTH, MAX_SERVICE_CLIENTS};
use crate::error::{Error, Result};
pub use crate::key;
use crate::key;
use crate::mechanisms;
pub use crate::pipe::ServiceEndpoint;
use crate::pipe::ServiceEndpoint;
use crate::pipe::TrussedResponder;
use crate::platform::{consent, ui, Platform, Store, Syscall, UserInterface};
pub use crate::store::{
self,
use crate::platform::{Platform, Syscall, UserInterface};
use crate::store::{
certstore::{Certstore as _, ClientCertstore},
counterstore::{ClientCounterstore, Counterstore as _},
filestore::{ClientFilestore, Filestore, ReadDirFilesState, ReadDirState},
filestore::{ClientFilestore, Filestore},
keystore::{ClientKeystore, Keystore},
Store,
};
use crate::types::{
consent,
ui::{self, Status},
};
use crate::types::ui::Status;
use crate::types::{Bytes, Context, CoreContext, Location, Mechanism, MediumData, Message};
use crate::{
api::{reply, request, Reply, Request},
Expand Down
7 changes: 4 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use littlefs2::io::Result as LfsResult;
use rand_core::{CryptoRng, RngCore};

use crate::client::{CryptoClient as _, FilesystemClient as _};
use crate::error::Error;
use crate::types::{consent, reboot, ui, Bytes, Location, PathBuf};
use crate::{api, block, platform, store, Error};
use crate::{api, block, platform, store};

pub struct MockRng(ChaCha20);

Expand Down Expand Up @@ -181,7 +182,7 @@ macro_rules! setup {
let pc_interface: UserInterface = Default::default();

let platform = $platform::new(rng, store, pc_interface);
let mut trussed: crate::Service<$platform> = crate::service::Service::new(platform);
let mut trussed: crate::service::Service<$platform> = crate::service::Service::new(platform);

let (test_trussed_requester, test_trussed_responder) = crate::pipe::TRUSSED_INTERCHANGE
.claim()
Expand All @@ -195,7 +196,7 @@ macro_rules! setup {
trussed.set_seed_if_uninitialized(&$seed);
let mut $client = {
pub type TestClient<'a> =
crate::ClientImplementation<&'a mut crate::Service<$platform>>;
crate::client::ClientImplementation<&'a mut crate::service::Service<$platform>>;
TestClient::new(test_trussed_requester, &mut trussed, None)
};
};
Expand Down
3 changes: 0 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use crate::config::*;
use crate::store::filestore::{ReadDirFilesState, ReadDirState};
use crate::{interrupt::InterruptFlag, key::Secrecy};

pub use crate::client::FutureResult;
pub use crate::platform::Platform;

/// An empty struct not storing any data.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NoData;
Expand Down
3 changes: 1 addition & 2 deletions src/virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use rand_core::SeedableRng as _;

use crate::{
backend::{BackendId, CoreOnly, Dispatch},
client::ClientBuilder,
client::{ClientBuilder, ClientImplementation},
platform::{self, Syscall},
service::Service,
ClientImplementation,
};

pub use store::{Filesystem, Ram, StoreProvider};
Expand Down
5 changes: 4 additions & 1 deletion src/virt/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::platform::{self, consent::Level, reboot::To, ui::Status};
use crate::{
platform,
types::{consent::Level, reboot::To, ui::Status},
};
use std::time::{Duration, Instant};

pub struct UserInterface {
Expand Down
3 changes: 1 addition & 2 deletions tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
use trussed::{
api::{reply::ReadFile, Reply, Request},
backend::{self, BackendId},
client::FilesystemClient as _,
client::{ClientImplementation, FilesystemClient as _},
error::Error,
platform,
service::{Service, ServiceResources},
types::{CoreContext, Location, Message, PathBuf},
virt::{self, Ram},
ClientImplementation,
};

type Platform = virt::Platform<Ram>;
Expand Down
2 changes: 1 addition & 1 deletion tests/serde_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

use trussed::{
backend::BackendId,
client::ClientImplementation,
service::Service,
types::ShortData,
virt::{self, Ram},
ClientImplementation,
};

use runner::Backends;
Expand Down

0 comments on commit 2e4e15a

Please sign in to comment.