Skip to content

Commit

Permalink
Document that the write_u*() functions are unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Aug 22, 2023
1 parent 7118362 commit 750454b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module implements the 128-bit mode.

Usage
-----

In `Cargo.toml`:

```toml
Expand Down Expand Up @@ -41,3 +42,14 @@ use siphasher::sip128::{Hasher128, Siphasher, SipHasher13, SipHasher24};

[API documentation](https://docs.rs/siphasher/)
-----------------------------------------------

Note
----

The `Hasher` trait from the standard library includes methods such as `write_u32()` or `write_usize()` that look perfect in order to hash values.

However, what the standard library documentation doesn't mention (or maybe it does, but this is not obvious) is that these functions are equivalent to hashing a byte array representation of these values *in native order*.

So using `write_u32()` may cause a hash function to return different results according to the host endianness. When using `serde` on structures containing primitive values, don't expect the result to be portable.

This is a poor design decision, counterintuitive and unsafe, but that's the way it is.

0 comments on commit 750454b

Please sign in to comment.