Skip to content

Commit 34d982b

Browse files
robin-nitrokeysosthene-nitrokey
authored andcommitted
Move types into trussed-rsa-types crate and release v0.1.0
This means that applications no longer need to depend on the backend.
1 parent 053d3b5 commit 34d982b

File tree

11 files changed

+104
-47
lines changed

11 files changed

+104
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SPDX-License-Identifier: CC0-1.0
99

1010
[Unreleased]: https://github.com/trussed-dev/trussed-rsa-backend/compare/v0.3.0...HEAD
1111

12-
-
12+
- Move `RsaImportFormat` and `RsaPublicParts` to the `trussed-rsa-types` crate.
1313

1414
## [v0.3.0][] (2025-07-31)
1515

Cargo.toml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
# Copyright (C) Nitrokey GmbH
22
# SPDX-License-Identifier: CC0-1.0
33

4+
[workspace]
5+
members = ["types"]
6+
7+
[workspace.package]
8+
authors = ["Nitrokey GmbH <[email protected]>"]
9+
edition = "2021"
10+
license = "Apache-2.0 OR MIT"
11+
repository = "https://github.com/trussed-dev/trussed-rsa-backend"
12+
13+
[workspace.dependencies]
14+
heapless-bytes = "0.5"
15+
trussed-core = "0.1"
16+
417
[package]
518
name = "trussed-rsa-alloc"
619
version = "0.3.0"
7-
edition = "2021"
820
description = "Trussed backend adding support for the RSA algorithm using an allocator"
9-
authors = ["Nitrokey GmbH <[email protected]>"]
10-
license = "Apache-2.0 OR MIT"
21+
edition.workspace = true
22+
authors.workspace = true
23+
license.workspace = true
24+
repository.workspace = true
1125
rust-version = "1.66"
1226
keywords = ["trussed", "rsa", "no-std"]
1327

1428
[dependencies]
29+
heapless-bytes.workspace = true
1530
delog = "0.1.6"
16-
heapless-bytes = "0.3.0"
1731
num-bigint-dig = { version = "0.8.2", default-features = false }
18-
postcard = { version = "0.7", default-features = false, features = ["heapless"] }
1932
rsa = { version = "0.9", default-features = false, features = ["sha2"]}
20-
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
2133

2234
trussed = { version = "0.1", default-features = false }
23-
trussed-core = { version = "0.1.0-rc.1", features = ["crypto-client", "rsa2048", "rsa3072", "rsa4096"] }
35+
trussed-core = { workspace = true, features = ["crypto-client", "rsa2048", "rsa3072", "rsa4096"] }
36+
trussed-rsa-types = "0.1"
2437

2538
[dev-dependencies]
2639
hex-literal = "0.3.4"
@@ -29,10 +42,10 @@ delog = { version = "0.1.6", features = ["std-log"] }
2942
test-log = "0.2.11"
3043
env_logger = "0.10.0"
3144
rand = "0.8.5"
32-
trussed = { version = "0.1", default-features = false, features = ["certificate-client", "clients-1", "crypto-client"] }
45+
trussed = { version = "0.1", default-features = false, features = ["certificate-client", "crypto-client"] }
3346

3447
[features]
35-
48+
default = ["virt"]
3649
virt = ["std", "trussed/virt"]
3750
std = []
3851

@@ -48,7 +61,12 @@ log-warn = []
4861
log-error = []
4962

5063
[patch.crates-io]
51-
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "6bba8fde36d05c0227769eb63345744e87d84b2b" }
64+
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "1e7b09a983dc8ae64a7ad8401ce541a9a77e5939" }
65+
trussed-core = { git = "https://github.com/trussed-dev/trussed.git", rev = "1e7b09a983dc8ae64a7ad8401ce541a9a77e5939" }
66+
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "e9d3a1ca98f80e92cd20ee9b94707067810b9036" }
67+
littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "e9d3a1ca98f80e92cd20ee9b94707067810b9036" }
68+
littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys", rev = "v0.3.1-nitrokey.1" }
69+
trussed-rsa-types.path = "types"
5270

5371
[profile.dev.package.rsa]
5472
opt-level = 2

src/crypto_traits.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ use trussed_core::{
99
types::{
1010
KeyId, KeySerialization, Location, Mechanism, SignatureSerialization, StorageAttributes,
1111
},
12-
ClientError, ClientResult, CryptoClient,
12+
{ClientError, ClientResult, CryptoClient},
1313
};
14-
15-
use crate::{RsaImportFormat, RsaPublicParts};
14+
use trussed_rsa_types::{RsaImportFormat, RsaPublicParts};
1615

1716
impl<C: CryptoClient> Rsa2048Pkcs1v15 for C {}
1817

@@ -46,11 +45,12 @@ pub trait Rsa2048Pkcs1v15: CryptoClient {
4645
/// Serializes an RSA 2048 bit key.
4746
///
4847
/// The resulting [`serialized_key`](trussed_core::api::reply::SerializeKey::serialized_key) contains a buffer of the parts of the key
49-
/// as a serialized [`RsaPublicParts`](crate::RsaPublicParts):
48+
/// as a serialized [`RsaPublicParts`](trussed_rsa_types::RsaPublicParts):
5049
/// ```
5150
///# #[cfg(feature = "virt")]
5251
///# {
5352
///# use trussed_rsa_alloc::*;
53+
///# use trussed_rsa_types::*;
5454
///# use trussed_core::{syscall,types::Location::{Volatile,Internal}};
5555
///# virt::with_ram_client("rsa tests", |mut client| {
5656
///# let sk = syscall!(client.generate_rsa2048pkcs_private_key(Internal)).key;
@@ -189,11 +189,12 @@ pub trait Rsa3072Pkcs1v15: CryptoClient {
189189
/// Serializes an RSA 3072 bit key.
190190
///
191191
/// The resulting [`serialized_key`](trussed_core::api::reply::SerializeKey::serialized_key) contains a buffer of the parts of the key
192-
/// as a serialized [`RsaPublicParts`](crate::RsaPublicParts):
192+
/// as a serialized [`RsaPublicParts`](trussed_rsa_types::RsaPublicParts):
193193
/// ```
194194
///# #[cfg(feature = "virt")]
195195
///# {
196196
///# use trussed_rsa_alloc::*;
197+
///# use trussed_rsa_types::*;
197198
///# use trussed_core::{syscall,types::Location::{Volatile,Internal}};
198199
///# virt::with_ram_client("rsa tests", |mut client| {
199200
///# let sk = syscall!(client.generate_rsa3072pkcs_private_key(Internal)).key;
@@ -332,11 +333,12 @@ pub trait Rsa4096Pkcs1v15: CryptoClient {
332333
/// Serializes an RSA 4096 bit key.
333334
///
334335
/// The resulting [`serialized_key`](trussed_core::api::reply::SerializeKey::serialized_key) contains a buffer of the parts of the key
335-
/// as a serialized [`RsaPublicParts`](crate::RsaPublicParts):
336+
/// as a serialized [`RsaPublicParts`](trussed_rsa_types::RsaPublicParts):
336337
/// ```
337338
///# #[cfg(feature = "virt")]
338339
///# {
339340
///# use trussed_rsa_alloc::*;
341+
///# use trussed_rsa_types::*;
340342
///# use trussed_core::{syscall,types::Location::{Volatile,Internal}};
341343
///# virt::with_ram_client("rsa tests", |mut client| {
342344
///# let sk = syscall!(client.generate_rsa4096pkcs_private_key(Internal)).key;

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use trussed::{
2727
},
2828
Error,
2929
};
30+
use trussed_rsa_types::{RsaImportFormat, RsaPublicParts};
3031

3132
#[cfg(feature = "virt")]
3233
pub mod virt;
@@ -38,8 +39,6 @@ generate_macros!();
3839
#[macro_use]
3940
extern crate alloc;
4041

41-
mod types;
42-
pub use types::{RsaImportFormat, RsaPublicParts};
4342
mod crypto_traits;
4443
pub use crypto_traits::{Rsa2048Pkcs1v15, Rsa3072Pkcs1v15, Rsa4096Pkcs1v15};
4544

@@ -271,7 +270,7 @@ fn sign(
271270
Error::InternalError
272271
})?;
273272
let our_signature =
274-
Signature::from_slice(&native_signature.to_bytes()).unwrap_or_else(|_| panic!());
273+
Signature::try_from(&*native_signature.to_bytes()).unwrap_or_else(|_| panic!());
275274

276275
Ok(reply::Sign {
277276
signature: our_signature,
@@ -338,7 +337,7 @@ fn decrypt(
338337
})?;
339338

340339
Ok(reply::Decrypt {
341-
plaintext: Some(Bytes::from_slice(&res).map_err(|_| {
340+
plaintext: Some(Bytes::try_from(&*res).map_err(|_| {
342341
error!("Failed type conversion");
343342
Error::InternalError
344343
})?),

src/virt.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ impl Dispatch for Dispatcher {
2323
}
2424
}
2525

26-
use std::path::PathBuf;
2726
use trussed::{
2827
backend::{Backend, BackendId, Dispatch},
29-
virt::{self, Filesystem, Ram, StoreProvider},
28+
virt::{self, StoreConfig},
3029
Platform,
3130
};
3231

33-
pub type Client<S, D = Dispatcher> = virt::Client<S, D>;
32+
pub type Client<'a, D = Dispatcher> = virt::Client<'a, D>;
3433

35-
pub fn with_client<S, R, F>(store: S, client_id: &str, f: F) -> R
34+
pub fn with_client<R, F>(store: StoreConfig, client_id: &str, f: F) -> R
3635
where
37-
F: FnOnce(Client<S>) -> R,
38-
S: StoreProvider,
36+
F: FnOnce(Client) -> R,
3937
{
4038
virt::with_platform(store, |platform| {
4139
platform.run_client_with_backends(
@@ -47,17 +45,9 @@ where
4745
})
4846
}
4947

50-
pub fn with_fs_client<P, R, F>(internal: P, client_id: &str, f: F) -> R
51-
where
52-
F: FnOnce(Client<Filesystem>) -> R,
53-
P: Into<PathBuf>,
54-
{
55-
with_client(Filesystem::new(internal), client_id, f)
56-
}
57-
5848
pub fn with_ram_client<R, F>(client_id: &str, f: F) -> R
5949
where
60-
F: FnOnce(Client<Ram>) -> R,
50+
F: FnOnce(Client) -> R,
6151
{
62-
with_client(Ram::default(), client_id, f)
52+
with_client(StoreConfig::ram(), client_id, f)
6353
}

tests/rsa2048.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
use rsa::sha2::Sha256;
77
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
8-
use trussed::client::CryptoClient;
98
use trussed::syscall;
109
use trussed::types::KeyId;
1110
use trussed::types::KeySerialization;
1211
use trussed::types::Location::*;
1312
use trussed::types::Mechanism;
1413
use trussed::types::StorageAttributes;
14+
use trussed_core::CryptoClient;
1515

1616
use trussed_rsa_alloc::*;
17+
use trussed_rsa_types::*;
1718

1819
use hex_literal::hex;
1920
use num_bigint_dig::BigUint;

tests/rsa3072.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use rsa::sha2::Sha384;
77
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
8-
use trussed::client::CryptoClient;
8+
use trussed_core::CryptoClient;
99
use trussed::syscall;
1010
use trussed::types::KeyId;
1111
use trussed::types::KeySerialization;
@@ -14,6 +14,7 @@ use trussed::types::Mechanism;
1414
use trussed::types::StorageAttributes;
1515

1616
use trussed_rsa_alloc::*;
17+
use trussed_rsa_types::*;
1718

1819
use hex_literal::hex;
1920
use num_bigint_dig::BigUint;

tests/rsa4096.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
use rsa::sha2::Sha512;
77
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
8-
use trussed::client::CryptoClient;
98
use trussed::syscall;
109
use trussed::types::KeyId;
1110
use trussed::types::KeySerialization;
1211
use trussed::types::Location::*;
1312
use trussed::types::Mechanism;
1413
use trussed::types::StorageAttributes;
14+
use trussed_core::CryptoClient;
1515

1616
use trussed_rsa_alloc::*;
17+
use trussed_rsa_types::*;
1718

1819
use hex_literal::hex;
1920
use num_bigint_dig::BigUint;

types/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
Copyright (C) Nitrokey GmbH
3+
SPDX-License-Identifier: CC0-1.0
4+
-->
5+
6+
# Changelog
7+
8+
## [Unreleased](https://github.com/trussed-dev/trussed-rsa-backend/compare/types-v0.1.0...HEAD)
9+
10+
-
11+
12+
## [v0.1.0](https://github.com/trussed-dev/trussed-rsa-backend/releases/tag/types-v0.1.0)
13+
14+
- Add `Error`, `ErrorKind`, `RsaImportFormat` and `RsaPublicParts` from `trussed-rsa-alloc` v0.3.0.
15+

types/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) Nitrokey GmbH
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
[package]
5+
name = "trussed-rsa-types"
6+
version = "0.1.0"
7+
description = "Helper types for the trussed-rsa-alloc backend"
8+
edition.workspace = true
9+
authors.workspace = true
10+
license.workspace = true
11+
repository.workspace = true
12+
keywords = ["trussed", "rsa", "no-std"]
13+
14+
[dependencies]
15+
heapless-bytes.workspace = true
16+
postcard = { version = "0.7", default-features = false, features = ["heapless"] }
17+
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
18+
trussed-core.workspace = true

0 commit comments

Comments
 (0)