mirror of
https://github.com/trussed-dev/trussed-rsa-backend.git
synced 2026-06-20 04:16:22 -07:00
Update to heapless-bytes v0.5 and trussed-core v0.2
This commit is contained in:
@@ -10,6 +10,9 @@ SPDX-License-Identifier: CC0-1.0
|
||||
[Unreleased]: https://github.com/trussed-dev/trussed-rsa-backend/compare/v0.3.0...HEAD
|
||||
|
||||
- Move `RsaImportFormat` and `RsaPublicParts` to the `trussed-rsa-types` crate.
|
||||
- Update dependencies:
|
||||
- `heapless-bytes` v0.5
|
||||
- `trussed-core` v0.2
|
||||
|
||||
## [v0.3.0][] (2025-07-31)
|
||||
|
||||
|
||||
+4
-5
@@ -11,8 +11,8 @@ license = "Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/trussed-dev/trussed-rsa-backend"
|
||||
|
||||
[workspace.dependencies]
|
||||
heapless-bytes = "0.3"
|
||||
trussed-core = "0.1"
|
||||
heapless-bytes = "0.5"
|
||||
trussed-core = "0.2"
|
||||
|
||||
[package]
|
||||
name = "trussed-rsa-alloc"
|
||||
@@ -42,10 +42,9 @@ delog = { version = "0.1.6", features = ["std-log"] }
|
||||
test-log = "0.2.11"
|
||||
env_logger = "0.10.0"
|
||||
rand = "0.8.5"
|
||||
trussed = { version = "0.1", default-features = false, features = ["certificate-client", "clients-1", "crypto-client"] }
|
||||
trussed = { version = "0.1", default-features = false, features = ["certificate-client", "crypto-client"] }
|
||||
|
||||
[features]
|
||||
|
||||
virt = ["std", "trussed/virt"]
|
||||
std = []
|
||||
|
||||
@@ -61,7 +60,7 @@ log-warn = []
|
||||
log-error = []
|
||||
|
||||
[patch.crates-io]
|
||||
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "6bba8fde36d05c0227769eb63345744e87d84b2b" }
|
||||
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "0b65280d69be541b8771f7756139826332c7d674" }
|
||||
trussed-rsa-types.path = "types"
|
||||
|
||||
[profile.dev.package.rsa]
|
||||
|
||||
@@ -9,7 +9,7 @@ use trussed_core::{
|
||||
types::{
|
||||
KeyId, KeySerialization, Location, Mechanism, SignatureSerialization, StorageAttributes,
|
||||
},
|
||||
ClientError, ClientResult, CryptoClient,
|
||||
{ClientError, ClientResult, CryptoClient},
|
||||
};
|
||||
use trussed_rsa_types::{RsaImportFormat, RsaPublicParts};
|
||||
|
||||
|
||||
+2
-2
@@ -270,7 +270,7 @@ fn sign(
|
||||
Error::InternalError
|
||||
})?;
|
||||
let our_signature =
|
||||
Signature::from_slice(&native_signature.to_bytes()).unwrap_or_else(|_| panic!());
|
||||
Signature::try_from(&*native_signature.to_bytes()).unwrap_or_else(|_| panic!());
|
||||
|
||||
Ok(reply::Sign {
|
||||
signature: our_signature,
|
||||
@@ -337,7 +337,7 @@ fn decrypt(
|
||||
})?;
|
||||
|
||||
Ok(reply::Decrypt {
|
||||
plaintext: Some(Bytes::from_slice(&res).map_err(|_| {
|
||||
plaintext: Some(Bytes::try_from(&*res).map_err(|_| {
|
||||
error!("Failed type conversion");
|
||||
Error::InternalError
|
||||
})?),
|
||||
|
||||
+6
-16
@@ -23,19 +23,17 @@ impl Dispatch for Dispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
use std::path::PathBuf;
|
||||
use trussed::{
|
||||
backend::{Backend, BackendId, Dispatch},
|
||||
virt::{self, Filesystem, Ram, StoreProvider},
|
||||
virt::{self, StoreConfig},
|
||||
Platform,
|
||||
};
|
||||
|
||||
pub type Client<S, D = Dispatcher> = virt::Client<S, D>;
|
||||
pub type Client<'a, D = Dispatcher> = virt::Client<'a, D>;
|
||||
|
||||
pub fn with_client<S, R, F>(store: S, client_id: &str, f: F) -> R
|
||||
pub fn with_client<R, F>(store: StoreConfig, client_id: &str, f: F) -> R
|
||||
where
|
||||
F: FnOnce(Client<S>) -> R,
|
||||
S: StoreProvider,
|
||||
F: FnOnce(Client) -> R,
|
||||
{
|
||||
virt::with_platform(store, |platform| {
|
||||
platform.run_client_with_backends(
|
||||
@@ -47,17 +45,9 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_fs_client<P, R, F>(internal: P, client_id: &str, f: F) -> R
|
||||
where
|
||||
F: FnOnce(Client<Filesystem>) -> R,
|
||||
P: Into<PathBuf>,
|
||||
{
|
||||
with_client(Filesystem::new(internal), client_id, f)
|
||||
}
|
||||
|
||||
pub fn with_ram_client<R, F>(client_id: &str, f: F) -> R
|
||||
where
|
||||
F: FnOnce(Client<Ram>) -> R,
|
||||
F: FnOnce(Client) -> R,
|
||||
{
|
||||
with_client(Ram::default(), client_id, f)
|
||||
with_client(StoreConfig::ram(), client_id, f)
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,13 +5,13 @@
|
||||
|
||||
use rsa::sha2::Sha256;
|
||||
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
|
||||
use trussed::client::CryptoClient;
|
||||
use trussed::syscall;
|
||||
use trussed::types::KeyId;
|
||||
use trussed::types::KeySerialization;
|
||||
use trussed::types::Location::*;
|
||||
use trussed::types::Mechanism;
|
||||
use trussed::types::StorageAttributes;
|
||||
use trussed_core::CryptoClient;
|
||||
|
||||
use trussed_rsa_alloc::*;
|
||||
use trussed_rsa_types::*;
|
||||
|
||||
+1
-1
@@ -5,13 +5,13 @@
|
||||
|
||||
use rsa::sha2::Sha384;
|
||||
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
|
||||
use trussed::client::CryptoClient;
|
||||
use trussed::syscall;
|
||||
use trussed::types::KeyId;
|
||||
use trussed::types::KeySerialization;
|
||||
use trussed::types::Location::*;
|
||||
use trussed::types::Mechanism;
|
||||
use trussed::types::StorageAttributes;
|
||||
use trussed_core::CryptoClient;
|
||||
|
||||
use trussed_rsa_alloc::*;
|
||||
use trussed_rsa_types::*;
|
||||
|
||||
+1
-1
@@ -5,13 +5,13 @@
|
||||
|
||||
use rsa::sha2::Sha512;
|
||||
use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign};
|
||||
use trussed::client::CryptoClient;
|
||||
use trussed::syscall;
|
||||
use trussed::types::KeyId;
|
||||
use trussed::types::KeySerialization;
|
||||
use trussed::types::Location::*;
|
||||
use trussed::types::Mechanism;
|
||||
use trussed::types::StorageAttributes;
|
||||
use trussed_core::CryptoClient;
|
||||
|
||||
use trussed_rsa_alloc::*;
|
||||
use trussed_rsa_types::*;
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@ SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
## [Unreleased](https://github.com/trussed-dev/trussed-rsa-backend/compare/types-v0.1.0...HEAD)
|
||||
|
||||
-
|
||||
- Update dependencies:
|
||||
- `heapless-bytes` v0.5
|
||||
- `trussed-core` v0.2
|
||||
|
||||
## [v0.1.0](https://github.com/trussed-dev/trussed-rsa-backend/releases/tag/types-v0.1.0)
|
||||
|
||||
|
||||
+16
-6
@@ -1,6 +1,8 @@
|
||||
// Copyright (C) Nitrokey GmbH
|
||||
// SPDX-License-Identifier: Apache-2.0 or MIT
|
||||
|
||||
#![no_std]
|
||||
|
||||
use heapless_bytes::Bytes;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use trussed_core::types::SerializedKey;
|
||||
@@ -25,6 +27,16 @@ pub struct Error {
|
||||
kind: ErrorKind,
|
||||
}
|
||||
|
||||
pub(crate) fn postcard_serialize_bytes<T: serde::Serialize, const N: usize>(
|
||||
object: &T,
|
||||
) -> postcard::Result<Bytes<N>> {
|
||||
let mut vec = Bytes::new();
|
||||
vec.resize_to_capacity();
|
||||
let serialized = postcard::to_slice(object, &mut vec)?.len();
|
||||
vec.resize(serialized, 0).unwrap();
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
/// Structure containing the public part of an RSA key
|
||||
///
|
||||
/// Given how Trussed extensions are implemented, this structure cannot be sent as-is to the backend,
|
||||
@@ -42,15 +54,14 @@ pub struct RsaPublicParts<'d> {
|
||||
impl<'d> RsaPublicParts<'d> {
|
||||
pub fn serialize(&self) -> Result<SerializedKey, Error> {
|
||||
use postcard::Error as PError;
|
||||
let vec = postcard::to_vec(self).map_err(|err| match err {
|
||||
postcard_serialize_bytes(self).map_err(|err| match err {
|
||||
PError::SerializeBufferFull => Error {
|
||||
kind: ErrorKind::SerializeBufferFull,
|
||||
},
|
||||
_ => Error {
|
||||
kind: ErrorKind::SerializeCustom,
|
||||
},
|
||||
})?;
|
||||
Ok(Bytes::from(vec))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deserialize(data: &'d [u8]) -> Result<Self, Error> {
|
||||
@@ -79,15 +90,14 @@ pub struct RsaImportFormat<'d> {
|
||||
impl<'d> RsaImportFormat<'d> {
|
||||
pub fn serialize(&self) -> Result<SerializedKey, Error> {
|
||||
use postcard::Error as PError;
|
||||
let vec = postcard::to_vec(self).map_err(|err| match err {
|
||||
postcard_serialize_bytes(self).map_err(|err| match err {
|
||||
PError::SerializeBufferFull => Error {
|
||||
kind: ErrorKind::SerializeBufferFull,
|
||||
},
|
||||
_ => Error {
|
||||
kind: ErrorKind::SerializeCustom,
|
||||
},
|
||||
})?;
|
||||
Ok(Bytes::from(vec))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deserialize(data: &'d [u8]) -> Result<Self, Error> {
|
||||
|
||||
Reference in New Issue
Block a user