Skip to content

Commit 6aa9028

Browse files
Update heapless-bytes to 0.5.0
1 parent ff122ad commit 6aa9028

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "README.md"
1111
edition = "2021"
1212

1313
[dependencies]
14-
heapless-bytes = "0.3.0"
14+
heapless-bytes = "0.5.0"
1515
serde_repr = "0.1"
1616

1717
[dependencies.serde]
@@ -20,9 +20,13 @@ default-features = false
2020
features = ["derive"]
2121

2222
[dev-dependencies]
23-
cbor-smol = "0.4"
23+
cbor-smol = { version = "0.5", features = ["heapless-bytes-v0-5"]}
2424
ciborium = "0.2.1"
2525
hex = "0.4.3"
2626
itertools = "0.12.0"
2727
quickcheck = "1.0.3"
2828
serde = "1"
29+
30+
[patch.crates-io]
31+
heapless-bytes = { git = "https://github.com/trussed-dev/heapless-bytes.git", branch = "heapless-0.9"}
32+
cbor-smol = { git = "https://github.com/trussed-dev/cbor-smol.git", branch = "heapless-0.9"}

tests/cose.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
use core::fmt::Debug;
22

3-
use cbor_smol::{cbor_deserialize, cbor_serialize_bytes};
3+
use cbor_smol::{cbor_deserialize, cbor_serialize_to};
44
use ciborium::Value;
55
use cosey::{EcdhEsHkdf256PublicKey, Ed25519PublicKey, P256PublicKey, PublicKey};
66
use heapless_bytes::Bytes;
77
use itertools::Itertools as _;
88
use quickcheck::{Arbitrary, Gen};
99
use serde::{de::DeserializeOwned, Serialize};
1010

11+
pub fn cbor_serialize_bytes<const N: usize, T: ?Sized + serde::Serialize>(
12+
value: &T,
13+
) -> cbor_smol::Result<Bytes<N>> {
14+
let mut writer = Bytes::new();
15+
cbor_serialize_to(value, &mut writer)?;
16+
Ok(writer)
17+
}
18+
1119
#[derive(Clone, Debug)]
1220
struct Input(Bytes<32>);
1321

1422
impl Arbitrary for Input {
1523
fn arbitrary(g: &mut Gen) -> Self {
1624
let mut data = vec![0; 32];
1725
data.fill_with(|| u8::arbitrary(g));
18-
Self(Bytes::from_slice(&data).unwrap())
26+
Self(Bytes::try_from(data.as_slice()).unwrap())
1927
}
2028
}
2129

@@ -147,8 +155,8 @@ fn test_de_order<T: Serialize + DeserializeOwned + Debug + PartialEq>(data: T) -
147155

148156
#[test]
149157
fn de_p256() {
150-
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
151-
let y = Bytes::from_slice(&[0xff; 32]).unwrap();
158+
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
159+
let y = Bytes::try_from([0xff; 32].as_slice()).unwrap();
152160
let key = P256PublicKey { x, y };
153161
let data = "a5010203262001215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff225820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
154162
test_de(data, key.clone());
@@ -157,8 +165,8 @@ fn de_p256() {
157165

158166
#[test]
159167
fn de_ecdh() {
160-
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
161-
let y = Bytes::from_slice(&[0xff; 32]).unwrap();
168+
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
169+
let y = Bytes::try_from([0xff; 32].as_slice()).unwrap();
162170
let key = EcdhEsHkdf256PublicKey { x, y };
163171
let data = "a501020338182001215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff225820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
164172
test_de(data, key.clone());
@@ -167,7 +175,7 @@ fn de_ecdh() {
167175

168176
#[test]
169177
fn de_ed25519() {
170-
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
178+
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
171179
let key = Ed25519PublicKey { x };
172180
let data =
173181
"a4010103272006215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";

0 commit comments

Comments
 (0)