trussed-dev / trussed-auth

Authentication extension and backend for Trussed
1 stars 3 forks source link

Improve byte array serialization #12

Closed robin-nitrokey closed 1 year ago

robin-nitrokey commented 1 year ago

Per default, byte arrays are serialized inefficiently by serde.

serde_bytes provides workarounds for byte slice serialization but does not support arrays yet. heapless_bytes improves the serialization for arrays but does not guarantee their length. Therefore we introduce a helper type, BytesArray, that uses heapless_bytes’ serialization but enforces a constant length.

serde-byte-array provides a wrapper type with a more efficient serialization format.

Fixes https://github.com/trussed-dev/trussed-auth/issues/11

sosthene-nitrokey commented 1 year ago

It's a bit of a pain that dtolnay completely ignores my pr to serde_bytes.

Maybe we should publish a fork of serde-bytes as serde-bytes-array? We already needed something like this in opcard (though we don't anymore).

robin-nitrokey commented 1 year ago

Maybe we should publish a fork of serde-bytes as serde-bytes-array? We already needed something like this in opcard (though we don't anymore).

Does this have to be a fork? Can’t we have a serde-byte(s)-array crate that just provides the Byte(s)Array type and, if needed, depends on serde-bytes?

sosthene-nitrokey commented 1 year ago

It doesn't necessarily have to be a fork no. We could have just the [u8;N] support in its own crate. Maybe it could be part of heapless-bytes?

robin-nitrokey commented 1 year ago

I’d prefer a separate crate. Mabye other people are also interested in using this specialization without pulling in heapless.

sosthene-nitrokey commented 1 year ago

I pushed one at https://github.com/Nitrokey/serde-byte-array

robin-nitrokey commented 1 year ago

I pushed one at https://github.com/Nitrokey/serde-byte-array

404 – is it a private repository?

sosthene-nitrokey commented 1 year ago

I made it public Should we publish it on crates.io?

robin-nitrokey commented 1 year ago

Thanks! I’ll make a PR with some minor changes and then we can release.