SpinResearch / merkle.rs

:christmas_tree: Merkle tree in Rust
BSD 3-Clause "New" or "Revised" License
129 stars 23 forks source link

Serde serialization. #30

Closed afck closed 6 years ago

afck commented 6 years ago

We're using merkle's Proofs in messages that need to be serialized, and want to support Serde in addition to protobuf, so I added a very crude serialization-serde feature in my fork: https://github.com/afck/merkle.rs/commit/dd41698a8a012643c7b9273e51943ac704524c70

Unfortunately Proof can't just be deserialized, so we added a ProofData that doesn't contain the algorithm field, and conversion functions.

Would you be interested in merging something like that into master? Is there a better way to handle proof deserialization?

romac commented 6 years ago

That would indeed be nice to have, though I wonder if there is indeed a better way to handle proof deserialization without having ProofData. Perhaps by writing manual Serialize/Deserialize instances for Proof, and encoding the Algorithm as eg. a string equals to the name of the corresponding static in ring::digest, ie. SHA1, SHA256, SHA384, SHA512, SHA512_256.

What do you think?

afck commented 6 years ago

Good idea! Supporting the constants in ring::digest should be sufficient for most use-cases. I'll give it a try.

romac commented 6 years ago

@afck Thank you for the PR! Just published v1.7.0 to crates.io with your changes :)