Skip to content

Commit 2683e84

Browse files
committed
Update HashMap docs regarding DoS protection
Because of changes to how Rust acquires randomness HashMap is not guaranteed to be DoS resistant. This commit reflects these changes in the docs themselves and provides an alternative method to creating a hash that is resistant if needed.
1 parent 41fe4b7 commit 2683e84

File tree

1 file changed

+6
-7
lines changed
  • src/libstd/collections/hash

1 file changed

+6
-7
lines changed

src/libstd/collections/hash/map.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ fn test_resize_policy() {
199199
/// A hash map implementation which uses linear probing with Robin
200200
/// Hood bucket stealing.
201201
///
202-
/// The hashes are all keyed by the thread-local random number generator
203-
/// on creation by default. This means that the ordering of the keys is
204-
/// randomized, but makes the tables more resistant to
205-
/// denial-of-service attacks (Hash DoS). No guarantees are made to the
206-
/// quality of the random data. The implementation uses the best available
207-
/// random data from your platform at the time of creation. This behavior
208-
/// can be overridden with one of the constructors.
202+
/// By default, HashMap uses a somewhat slow hashing algorithm which can provide resistance
203+
/// to DoS attacks. Rust makes a best attempt at acquiring random numbers without IO
204+
/// blocking from your system. Because of this HashMap is not guaranteed to provide
205+
/// DoS resistance since the numbers generated might not be truly random. If you do
206+
/// require this behavior you can create your own hashing function using
207+
/// [BuildHasherDefault](../hash/struct.BuildHasherDefault.html).
209208
///
210209
/// It is required that the keys implement the `Eq` and `Hash` traits, although
211210
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.

0 commit comments

Comments
 (0)