Skip to content

Commit

Permalink
core: Move api::NotBefore into types
Browse files Browse the repository at this point in the history
All other types that are used in the API are in types, so this patch
also moves api::NotBefore there.
  • Loading branch information
robin-nitrokey committed Dec 19, 2024
1 parent 3261759 commit f6c1ba5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
29 changes: 1 addition & 28 deletions core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ use crate::types::Location;
feature = "filesystem-client"
))]
use crate::types::Message;
use crate::types::PathBuf;
#[cfg(feature = "filesystem-client")]
use crate::types::{DirEntry, UserAttribute};
use crate::types::{DirEntry, NotBefore, PathBuf, UserAttribute};
#[cfg(any(feature = "attestation-client", feature = "crypto-client"))]
use crate::types::{KeyId, Mechanism};
#[cfg(feature = "crypto-client")]
Expand All @@ -51,32 +50,6 @@ mod macros;
//
// At minimum, we don't want to list the indices (may need proc-macro)

#[derive(Clone, Eq, PartialEq, Debug, serde::Serialize, serde::Deserialize)]
pub enum NotBefore {
/// Start iteration at the beginning of the directory
None,
/// Start iteration at an exact match with the provided filename
Filename(PathBuf),
/// Start iteration at the first path that is "after" the provided filename
FilenamePart(PathBuf),
}

impl NotBefore {
pub fn with_filename(value: Option<PathBuf>) -> Self {
match value {
None => Self::None,
Some(p) => Self::Filename(p),
}
}

pub fn with_filename_part(value: Option<PathBuf>) -> Self {
match value {
None => Self::None,
Some(p) => Self::FilenamePart(p),
}
}
}

generate_enums! {

////////////
Expand Down
4 changes: 2 additions & 2 deletions core/src/client/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{ClientResult, PollClient};
use crate::{
api::{reply, request, NotBefore},
types::{Location, Message, PathBuf, UserAttribute},
api::{reply, request},
types::{Location, Message, NotBefore, PathBuf, UserAttribute},
};

/// Read/Write/Delete files, iterate over directories.
Expand Down
27 changes: 27 additions & 0 deletions core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
pub use heapless_bytes::Bytes;
pub use littlefs2_core::{DirEntry, Metadata, PathBuf};

#[cfg(feature = "crypto-client")]
use crate::api::{reply, request};
use crate::config::{
MAX_KEY_MATERIAL_LENGTH, MAX_MEDIUM_DATA_LENGTH, MAX_MESSAGE_LENGTH, MAX_SHORT_DATA_LENGTH,
Expand Down Expand Up @@ -386,6 +387,32 @@ impl Default for StorageAttributes {
}
}

#[derive(Clone, Eq, PartialEq, Debug, serde::Serialize, serde::Deserialize)]
pub enum NotBefore {
/// Start iteration at the beginning of the directory
None,
/// Start iteration at an exact match with the provided filename
Filename(PathBuf),
/// Start iteration at the first path that is "after" the provided filename
FilenamePart(PathBuf),
}

impl NotBefore {
pub fn with_filename(value: Option<PathBuf>) -> Self {
match value {
None => Self::None,
Some(p) => Self::Filename(p),
}
}

pub fn with_filename_part(value: Option<PathBuf>) -> Self {
match value {
None => Self::None,
Some(p) => Self::FilenamePart(p),
}
}
}

/// Available client traits.
///
/// This enum does not provide access to the trait features. It is only intended for backends to
Expand Down
2 changes: 2 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub use trussed_core::api::*;
pub use trussed_core::types::NotBefore;
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ generate_macros!();

pub use interchange::Interchange;

pub mod api;
pub mod backend;
pub mod client;
pub mod config;
Expand Down Expand Up @@ -51,7 +52,7 @@ pub use error::Error;
pub use platform::Platform;
pub use service::Service;

pub use trussed_core::{api, block, error, interrupt, syscall, try_syscall};
pub use trussed_core::{block, error, interrupt, syscall, try_syscall};

pub use cbor_smol::cbor_deserialize;
pub use heapless_bytes::Bytes;
Expand Down

0 comments on commit f6c1ba5

Please sign in to comment.