Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize imports #160

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
//! [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::types::*;
use crate::types::{
consent, reboot, Bytes, CertId, CounterId, DirEntry, KeyId, KeySerialization, Location,
Mechanism, MediumData, Message, PathBuf, SerializedKey, ShortData, Signature,
SignatureSerialization, StorageAttributes, UserAttribute,
};
use core::time::Duration;

#[macro_use]
Expand Down Expand Up @@ -366,7 +370,7 @@ pub mod request {
Uptime:

Wink:
- duration: core::time::Duration
- duration: Duration

SetCustomStatus:
- status: u8
Expand Down
10 changes: 7 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@
//!
use core::{marker::PhantomData, task::Poll};

use crate::api::*;
use crate::api::{reply, request, NotBefore, Reply, ReplyVariant, RequestVariant};
use crate::backend::{BackendId, CoreOnly, Dispatch};
use crate::error::*;
use crate::error::{Error, Result};
use crate::interrupt::InterruptFlag;
use crate::pipe::{TrussedRequester, TRUSSED_INTERCHANGE};
use crate::service::Service;
use crate::types::*;
use crate::types::{
consent, reboot, Bytes, CertId, CounterId, KeyId, KeySerialization, Location, Mechanism,
MediumData, Message, PathBuf, Platform, SerializedKey, ShortData, Signature,
SignatureSerialization, StorageAttributes, UserAttribute,
};

pub use crate::platform::Syscall;

Expand Down
8 changes: 7 additions & 1 deletion src/client/mechanisms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use super::*;
use super::{ClientError, ClientImplementation, ClientResult, CryptoClient};
use crate::api::reply;
use crate::platform::Syscall;
use crate::types::{
KeyId, KeySerialization, Location, Mechanism, MediumData, Message, ShortData,
SignatureSerialization, StorageAttributes,
};

#[cfg(feature = "aes256-cbc")]
impl<S: Syscall, E> Aes256Cbc for ClientImplementation<S, E> {}
Expand Down
9 changes: 5 additions & 4 deletions src/mechanisms/aes256cbc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::api::*;
// use crate::config::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{Decrypt, Encrypt, UnsafeInjectKey, WrapKey};
use crate::store::keystore::Keystore;
use crate::types::{Mechanism, Message, ShortData};

const AES256_KEY_SIZE: usize = 32;

Expand Down
11 changes: 7 additions & 4 deletions src/mechanisms/chacha8poly1305.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::api::*;
// use crate::config::*;
use generic_array::GenericArray;
use rand_core::RngCore;

use crate::api::{reply, request};
use crate::error::Error;
use crate::key;
use crate::service::*;
use crate::types::*;
use crate::service::{Decrypt, Encrypt, GenerateKey, UnwrapKey, WrapKey};
use crate::store::keystore::Keystore;
use crate::types::{Mechanism, Message, ShortData};

// TODO: The non-detached versions seem better.
// This needs a bit of additional type gymnastics.
Expand Down
16 changes: 10 additions & 6 deletions src/mechanisms/ed255.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use core::convert::{TryFrom, TryInto};
use rand_core::RngCore;

use crate::api::*;
// use crate::config::*;
// use crate::debug;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{
DeriveKey, DeserializeKey, Exists, GenerateKey, SerializeKey, Sign, UnsafeInjectKey, Verify,
};
use crate::store::keystore::Keystore;
use crate::types::{
Bytes, KeyId, KeySerialization, SerializedKey, Signature, SignatureSerialization,
};

#[inline(never)]
fn load_public_key(
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/hmacblake2s.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{DeriveKey, Sign};
use crate::store::keystore::Keystore;
use crate::types::Signature;

#[cfg(feature = "hmac-blake2s")]
impl DeriveKey for super::HmacBlake2s {
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/hmacsha1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{DeriveKey, Sign};
use crate::store::keystore::Keystore;
use crate::types::Signature;

#[cfg(feature = "hmac-sha1")]
impl DeriveKey for super::HmacSha1 {
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/hmacsha256.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{DeriveKey, Sign};
use crate::store::keystore::Keystore;
use crate::types::Signature;

#[cfg(feature = "hmac-sha256")]
impl DeriveKey for super::HmacSha256 {
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/hmacsha512.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{DeriveKey, Sign};
use crate::store::keystore::Keystore;
use crate::types::Signature;

#[cfg(feature = "hmac-sha512")]
impl DeriveKey for super::HmacSha512 {
Expand Down
15 changes: 10 additions & 5 deletions src/mechanisms/p256.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// use core::convert::{TryFrom, TryInto};

use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{
Agree, DeriveKey, DeserializeKey, Exists, GenerateKey, SerializeKey, Sign, UnsafeInjectKey,
Verify,
};
use crate::store::keystore::Keystore;
use crate::types::{
Bytes, KeyId, KeySerialization, SerializedKey, Signature, SignatureSerialization,
};

#[inline(never)]
fn load_secret_key(
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/sha256.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{DeriveKey, Hash};
use crate::store::keystore::Keystore;
use crate::types::ShortData;

#[cfg(feature = "sha256")]
impl DeriveKey for super::Sha256 {
Expand Down
7 changes: 4 additions & 3 deletions src/mechanisms/shared_secret.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::key;
use crate::service::*;
use crate::types::*;
use crate::service::{SerializeKey, UnsafeInjectKey};
use crate::store::keystore::Keystore;
use crate::types::{KeySerialization, SerializedKey};

impl SerializeKey for super::SharedSecret {
#[inline(never)]
Expand Down
8 changes: 5 additions & 3 deletions src/mechanisms/tdes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
// needed to even get ::new() from des...
#[cfg(feature = "tdes")]
use des::cipher::{BlockDecrypt, BlockEncrypt, KeyInit};
use generic_array::GenericArray;

use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;
use crate::key;
use crate::service::{Decrypt, Encrypt, UnsafeInjectKey};
use crate::store::keystore::Keystore;

const TDES_KEY_SIZE: usize = 24;

Expand Down
6 changes: 4 additions & 2 deletions src/mechanisms/totp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::api::*;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::key;
use crate::service::{Exists, Sign};
use crate::store::keystore::Keystore;

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

Expand Down
8 changes: 6 additions & 2 deletions src/mechanisms/trng.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::api::*;
use rand_core::RngCore;

use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::key;
use crate::service::GenerateKey;
use crate::store::keystore::Keystore;

#[cfg(feature = "trng")]
impl GenerateKey for super::Trng {
Expand Down
17 changes: 9 additions & 8 deletions src/mechanisms/x255.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use core::convert::TryInto;
use rand_core::RngCore;
use salty::agreement;

use crate::api::*;
// use crate::config::*;
// use crate::debug;
use crate::api::{reply, request};
use crate::error::Error;
use crate::service::*;
use crate::types::*;

use salty::agreement;
use crate::key;
use crate::service::{
Agree, DeriveKey, DeserializeKey, Exists, GenerateKey, SerializeKey, UnsafeInjectKey,
};
use crate::store::keystore::Keystore;
use crate::types::{KeyId, KeySerialization, SerializedKey};

fn load_public_key(
keystore: &mut impl Keystore,
Expand Down
17 changes: 10 additions & 7 deletions src/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use littlefs2::{
object_safe::DynFilesystem,
path,
path::{Path, PathBuf},
};
Expand All @@ -7,25 +8,27 @@ pub use rand_core::{RngCore, SeedableRng};

use crate::backend::{BackendId, CoreOnly, Dispatch};
use crate::client::{ClientBuilder, ClientImplementation};
use crate::config::*;
use crate::config::{MAX_MESSAGE_LENGTH, MAX_SERVICE_CLIENTS};
use crate::error::{Error, Result};
pub use crate::key;
use crate::mechanisms;
pub use crate::pipe::ServiceEndpoint;
use crate::pipe::TrussedResponder;
use crate::platform::*;
use crate::platform::{consent, ui, Platform, Store, Syscall, UserInterface};
pub use crate::store::{
self,
certstore::{Certstore as _, ClientCertstore},
counterstore::{ClientCounterstore, Counterstore as _},
filestore::{ClientFilestore, Filestore, ReadDirFilesState, ReadDirState},
keystore::{ClientKeystore, Keystore},
DynFilesystem,
};
use crate::types::ui::Status;
use crate::types::*;
use crate::types::{Context, CoreContext, Location, Mechanism, MediumData, Message, Vec};
use crate::Bytes;
use crate::{api::*, interrupt::InterruptFlag};
use crate::{
api::{reply, request, Reply, Request},
interrupt::InterruptFlag,
};

pub mod attest;

Expand Down Expand Up @@ -954,7 +957,7 @@ impl<P: Platform, D: Dispatch> Service<P, D> {
}
}

impl<P, D> crate::client::Syscall for &mut Service<P, D>
impl<P, D> Syscall for &mut Service<P, D>
where
P: Platform,
D: Dispatch,
Expand All @@ -964,7 +967,7 @@ where
}
}

impl<P, D> crate::client::Syscall for Service<P, D>
impl<P, D> Syscall for Service<P, D>
where
P: Platform,
D: Dispatch,
Expand Down
16 changes: 9 additions & 7 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
//! - Alternative: subdirectory <==> RP hash, everything else in flat files
//! - In any case need to "list dirs excluding . and .." or similar

use littlefs2::{driver::Storage, fs::Filesystem};

use crate::error::Error;
use crate::types::*;
use crate::types::{Bytes, Location, PathBuf};
#[allow(unused_imports)]
#[cfg(feature = "semihosting")]
use cortex_m_semihosting::hprintln;
Expand Down Expand Up @@ -127,9 +129,9 @@ pub mod keystore;
//
// This makes everything using it *much* more ergonomic.
pub unsafe trait Store: Copy {
type I: 'static + LfsStorage;
type E: 'static + LfsStorage;
type V: 'static + LfsStorage;
type I: 'static + Storage;
type E: 'static + Storage;
type V: 'static + Storage;
fn ifs(self) -> &'static Fs<Self::I>;
fn efs(self) -> &'static Fs<Self::E>;
fn vfs(self) -> &'static Fs<Self::V>;
Expand All @@ -142,18 +144,18 @@ pub unsafe trait Store: Copy {
}
}

pub struct Fs<S: 'static + LfsStorage> {
pub struct Fs<S: 'static + Storage> {
fs: &'static Filesystem<'static, S>,
}

impl<S: 'static + LfsStorage> core::ops::Deref for Fs<S> {
impl<S: 'static + Storage> core::ops::Deref for Fs<S> {
type Target = Filesystem<'static, S>;
fn deref(&self) -> &Self::Target {
self.fs
}
}

impl<S: 'static + LfsStorage> Fs<S> {
impl<S: 'static + Storage> Fs<S> {
pub fn new(fs: &'static Filesystem<'static, S>) -> Self {
Self { fs }
}
Expand Down
Loading
Loading