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

Add trussed-core crate #178

Merged
merged 5 commits into from
Dec 12, 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
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ jobs:
run: cargo build --workspace --target ${{ matrix.target }}

- name: Check all targets without default features
run: cargo check --workspace --all-targets --no-default-features
run: |
cargo check --workspace --all-targets --no-default-features
cargo check --package trussed-core --all-targets --no-default-features
if: matrix.target == 'x86_64-unknown-linux-gnu'

- name: Check all targets with default features
run: cargo check --workspace --all-targets
run: |
cargo check --workspace --all-targets
cargo check --package trussed-core --all-targets
if: matrix.target == 'x86_64-unknown-linux-gnu'

- name: Check all features and targets
run: cargo check --workspace --all-features --all-targets
run: |
cargo check --workspace --all-features --all-targets
cargo check --package trussed-core --all-targets --all-features
if: matrix.target == 'x86_64-unknown-linux-gnu'

- name: Run tests
Expand All @@ -61,5 +67,8 @@ jobs:
if: matrix.target == 'x86_64-unknown-linux-gnu'

- name: Check documentation
run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --features serde-extensions,virt
run: |
export RUSTDOCFLAGS="-D warnings"
cargo doc --no-deps --features serde-extensions,virt
cargo doc --no-deps --package trussed-core --all-features
if: matrix.target == 'x86_64-unknown-linux-gnu'
33 changes: 21 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
[workspace]
members = ["derive"]
members = ["core", "derive"]

[workspace.package]
authors = ["Nicolas Stalder <[email protected]>", "Nitrokey GmbH"]
authors = ["The Trussed developers", "Nicolas Stalder <[email protected]>", "Nitrokey GmbH"]
edition = "2021"
homepage = "https://trussed.dev"
license = "Apache-2.0 OR MIT"

[workspace.dependencies]
heapless = "0.7"
heapless-bytes = "0.3"
littlefs2-core = { version = "0.1", features = ["serde"] }
postcard = "0.7.0"
rand_core = "0.6"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[package]
name = "trussed"
version = "0.1.0"
Expand All @@ -20,19 +28,21 @@ homepage.workspace = true
license.workspace = true

[dependencies]
trussed-core = { version = "0.1", path = "core" }

# general
bitflags = { version = "2.1" }
# const-oid = "0.4.5"
cfg-if = "1.0"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
flexiber = { version = "0.1.0", features = ["derive", "heapless"] }
generic-array = "0.14.4"
heapless = { version = "0.7", features = ["serde"] }
heapless = { workspace = true, features = ["serde"] }
hex-literal = "0.4.1"
nb = "1"
postcard = "0.7.0"
rand_core = "0.6"
serde = { version = "1.0", default-features = false }
postcard.workspace = true
rand_core.workspace = true
serde.workspace = true
zeroize = { version = "1.2", default-features = false, features = ["zeroize_derive"] }
rand_chacha = { version = "0.3.1", default-features = false }

Expand All @@ -51,13 +61,12 @@ sha2 = { version = "0.10", default-features = false }
cosey = "0.3"
delog = "0.1.0"
cbor-smol = { version = "0.5", features = ["heapless-bytes-v0-3"] }
heapless-bytes = { version = "0.3.0" }
heapless-bytes.workspace = true
interchange = "0.3.0"
littlefs2 = "0.5.0"
littlefs2-core = { version = "0.1", features = ["heapless-bytes03"] }
littlefs2-core = { workspace = true, features = ["heapless-bytes03"] }
p256-cortex-m4 = { version = "0.1.0-alpha.6", features = ["prehash", "sec1-signatures"] }
salty = { version = "0.3.0", features = ["cose"] }
serde-indexed = "0.1.0"
p384 = { version = "0.13.0", optional = true, default-features = false, features = ["sha384", "ecdh", "ecdsa"] }
p521 = { version = "0.13.3", optional = true, default-features = false, features = ["sha512", "ecdh", "ecdsa"] }
ecdsa = { version = "0.16.9", optional = true, default-features = false }
Expand All @@ -74,7 +83,7 @@ trussed-derive = { path = "derive" }

[features]
default = ["default-mechanisms", "default-syscalls", "clients-5"]
serde-extensions = []
serde-extensions = ["trussed-core/serde-extensions"]
std = []
verbose-tests = ["littlefs2/ll-assertions"]
verbose-lfs = ["littlefs2/ll-assertions", "littlefs2/ll-trace"]
Expand Down Expand Up @@ -123,8 +132,8 @@ trng = ["sha-1"]

# syscalls
default-syscalls = ["counter-client", "crypto-client-attest"]
counter-client = []
crypto-client-attest = []
counter-client = ["trussed-core/counter-client"]
crypto-client-attest = ["trussed-core/crypto-client-attest"]

clients-1 = []
clients-2 = []
Expand Down
23 changes: 23 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "trussed-core"
version = "0.1.0"

authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true

[dependencies]
heapless.workspace = true
heapless-bytes.workspace = true
littlefs2-core.workspace = true
postcard.workspace = true
rand_core.workspace = true
serde.workspace = true

serde-indexed = "0.1"

[features]
crypto-client-attest = []
counter-client = []
serde-extensions = []
7 changes: 4 additions & 3 deletions src/api.rs → core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
//! [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 core::time::Duration;

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]
mod macros;
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 = crate::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 = crate::error::Error> {
type Request: RequestVariant<Reply = Self>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/macros.rs → core/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(Self::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(Self::Error::InternalError),
}
}
}
Expand Down
Loading
Loading