Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

fix non-human-readable serde deserialization #36

Merged
merged 3 commits into from
Mar 4, 2019
Merged

Conversation

apoelstra
Copy link
Member

No description provided.

@apoelstra
Copy link
Member Author

IMHO this requires only a minor version bump since it strictly increases the set of things that can be deserialized.

Prior to this PR we would attempt to deserialize hashes first as &[u8], which we would copy into the hash type. The Deserialize impl for &[u8] uses a Visitor object that can only handle "borrowed bytes" (which are slices with a sufficiently long lifetime that they can be returned to callers; compare "bytes", which are also borrowed, but which are not assumed to outlive the invocation of Visitor::visit_bytes).

We don't need our byteslices to live long enough to to be returned, since we just copy the bytes into a new Hash object and return that. So we implement our own visitor which does exactly the same thing as before, but implements visit_bytes rather than visit_borrowed_bytes (and the default impl of visit_borrowed_bytes will fallthrough to visit_bytes).

This is needed to roundtrip using serde_cbor and probably other binary deserializiers.

@apoelstra apoelstra merged commit a2ff38e into master Mar 4, 2019
@apoelstra apoelstra deleted the 2019-03-serdefix branch March 4, 2019 20:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants