jedisct1 / rust-ed25519-compact

Small, wasm-friendly, zero-dependencies Ed25519 and X25519 implementation for Rust.
MIT License
121 stars 22 forks source link

Added the serde_support feature #7

Closed raphaelahrens closed 2 years ago

raphaelahrens commented 2 years ago

This change adds the serde_support feature, which when enabled adds Serialize and Deserialize implementations for

The Serialization is done manual, because of the of the large Size of the bytes array in SecretKey (64) and Signature (64) and for consistency also for PublicKey. All these Types are serialized to a NeytypeStruct holding a bytes array. While the NewtypeStruct should be ignored by the Serializer implementations

Serializers are encouraged to treat newtype structs as insignificant wrappers around the data they contain. A reasonable implementation would be to forward to value.serialize(self).

But not all do.

Only KeyPair uses the derive macro.

raphaelahrens commented 2 years ago

Hi, I am not very happy with this PR so I just wanted to show you the draft and hear your opinion.

So because of the size of the arrays inside SecretKey and Signature, it is at the moment not possible to just use the derive macro. So the option was to just serialize them as Bytes and lose the type. Or to go and implement the Visitors and all that.

This was an unexpected deep dive into serde and I must say it is not nice to see how the sausage is made.

Let me know what you think.

ineiti commented 2 years ago

I discovered serde_with, which might make this easier: https://docs.rs/serde_with/latest/serde_with/

raphaelahrens commented 2 years ago

Should this PR be closed?