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

Added the serde_support feature #7

Closed
wants to merge 1 commit into from

Conversation

raphaelahrens
Copy link
Contributor

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

  • KeyPair,
  • SecretKey,
  • PublicKey, and
  • Signature

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
Copy link
Contributor Author

raphaelahrens commented Jan 24, 2022

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
Copy link

ineiti commented May 29, 2022

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

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

* KeyPair,
* SecretKey,
* PublicKey, and
* Signature

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.

Moved all serde related parts into a separate module.
@raphaelahrens
Copy link
Contributor Author

Should this PR be closed?

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

Successfully merging this pull request may close these issues.

None yet

2 participants