Skip to content
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Unreleased

-
[All Changes](https://github.com/trussed-dev/cosey/compare/v0.4.0...HEAD)

[All Changes](https://github.com/trussed-dev/cosey/compare/v0.3.2...HEAD)
## [v0.4.0](https://github.com/trussed-dev/cosey/releases/tag/v0.4.0)

- Update `heapless-bytes` to 0.5.0 ([#15](https://github.com/trussed-dev/cosey/pull/15))

## [v0.3.2](https://github.com/trussed-dev/cosey/releases/tag/v0.3.2) (2025-02-26)

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosey"
version = "0.3.2"
version = "0.4.0"
authors = ["Nicolas Stalder <n@stalder.io>"]
license = "Apache-2.0 OR MIT"
description = "Data types and serde for public COSE_Keys"
Expand All @@ -11,7 +11,7 @@ readme = "README.md"
edition = "2021"

[dependencies]
heapless-bytes = "0.3.0"
heapless-bytes = "0.5.0"
serde_repr = "0.1"

[dependencies.serde]
Expand All @@ -20,7 +20,7 @@ default-features = false
features = ["derive"]

[dev-dependencies]
cbor-smol = "0.4"
cbor-smol = { version = "0.5", features = ["heapless-bytes-v0-5"]}
ciborium = "0.2.1"
hex = "0.4.3"
itertools = "0.12.0"
Expand Down
22 changes: 15 additions & 7 deletions tests/cose.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
use core::fmt::Debug;

use cbor_smol::{cbor_deserialize, cbor_serialize_bytes};
use cbor_smol::{cbor_deserialize, cbor_serialize_to};
use ciborium::Value;
use cosey::{EcdhEsHkdf256PublicKey, Ed25519PublicKey, P256PublicKey, PublicKey};
use heapless_bytes::Bytes;
use itertools::Itertools as _;
use quickcheck::{Arbitrary, Gen};
use serde::{de::DeserializeOwned, Serialize};

pub fn cbor_serialize_bytes<const N: usize, T: ?Sized + serde::Serialize>(
value: &T,
) -> cbor_smol::Result<Bytes<N>> {
let mut writer = Bytes::new();
cbor_serialize_to(value, &mut writer)?;
Ok(writer)
}

#[derive(Clone, Debug)]
struct Input(Bytes<32>);

impl Arbitrary for Input {
fn arbitrary(g: &mut Gen) -> Self {
let mut data = vec![0; 32];
data.fill_with(|| u8::arbitrary(g));
Self(Bytes::from_slice(&data).unwrap())
Self(Bytes::try_from(data.as_slice()).unwrap())
}
}

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

#[test]
fn de_p256() {
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
let y = Bytes::from_slice(&[0xff; 32]).unwrap();
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
let y = Bytes::try_from([0xff; 32].as_slice()).unwrap();
let key = P256PublicKey { x, y };
let data = "a5010203262001215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff225820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
test_de(data, key.clone());
Expand All @@ -157,8 +165,8 @@ fn de_p256() {

#[test]
fn de_ecdh() {
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
let y = Bytes::from_slice(&[0xff; 32]).unwrap();
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
let y = Bytes::try_from([0xff; 32].as_slice()).unwrap();
let key = EcdhEsHkdf256PublicKey { x, y };
let data = "a501020338182001215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff225820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
test_de(data, key.clone());
Expand All @@ -167,7 +175,7 @@ fn de_ecdh() {

#[test]
fn de_ed25519() {
let x = Bytes::from_slice(&[0xff; 32]).unwrap();
let x = Bytes::try_from([0xff; 32].as_slice()).unwrap();
let key = Ed25519PublicKey { x };
let data =
"a4010103272006215820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
Expand Down
Loading