Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common serde functionality #880

Open
tarcieri opened this issue Jan 10, 2022 · 0 comments
Open

Common serde functionality #880

tarcieri opened this issue Jan 10, 2022 · 0 comments

Comments

@tarcieri
Copy link
Member

Context: RustCrypto/nacl-compat#27

Several of our crates have serde integrations, and it'd be nice to expand that.

One thing that'd be really nice to have is some common functionality for for writing serializers/deserializers which don't depend on serde_derive, particularly if this functionality could make writing serializers/deserializers declarative with #[serde(try_from = "...", into = "...")].

Some of the hard lessons were learned writing the serializers for the ed25519 crate which presently depends on the serde_bytes crate for serialization. That was largely a workaround for the inadequacies of the original tuple-based serializers, which resulted in bloated documents when generating CBOR.

Perhaps this could go in crypto-common? Some common concerns:

  • Lack of const generics support in serde and difficulty serializing arrays larger than 32 elements. serde_bytes addresses this somewhat, but it'd be nice not to have to loop in an additional dependency, and I think a simpler solution is possible.
  • Choosing what formats to optimize for: serializing a byte array as a tuple of N u8 elements makes for a compact bincode representation, but an extremely bloated CBOR serialization for example. We should have a single place to test commonly used binary serializers, and choose which ones we want to optimize for. I would suggest optimizing for CBOR at the cost of bincode.
  • Support for choosing different encodings for binary vs human readable formats: in several places, the elliptic-curve crate uses a hex serialization for "human readable" text-based formats like JSON/TOML, and binary otherwise. While I think this sort of autodetection should be opt-in, it'd be nice to have a single place where it's implemented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@tarcieri and others