Skip to content

Commit

Permalink
Added a Serde trouble example to the README
Browse files Browse the repository at this point in the history
Originally posted as
RustCrypto/utils#2 (comment)
  • Loading branch information
mzabaluev committed Dec 11, 2017
1 parent e0438f4 commit 24b3913
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Expand Up @@ -39,6 +39,31 @@ use of them.
Configuration of these choices is decoupled from type-specific `Serialize`
implementations.

Consider this scenario:

```rust
// crate a
#[derive(Serialize)]
pub struct A {
foo: char
}

// crate b
extern crate a;
#[derive(Serialize)]
pub struct B {
bar: a::A
}
```

An application wishing to calculate a hash of `B` through the hypothetical
`Serializer` backend would have to be aware that the choice of how to hash
the inner `char` would affect the result, even though the `char` is an
implementation detail of `A` and may be not easily visible to the
application developer: she'd have to either look at the source of `a`
if that is available, or find it in a serialization dump of `B` made in
a human-readable format.

That said, a Serde backend to serialize arbitrary data structures for
purposes of cryptographic hashing may be eventually provided, and its
implementation can make use of the facilities provided by this crate.
Expand Down

0 comments on commit 24b3913

Please sign in to comment.