Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SipHasher13 instead of DefaultHasher #63

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions refinery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cfg-if = "0.1.10"
thiserror = "1"
async-trait = "0.1"
toml = "0.5"
siphasher = "0.3"

rusqlite = {version = "0.21", optional = true}
postgres = {version = "0.17", optional = true}
Expand Down
12 changes: 10 additions & 2 deletions refinery/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use chrono::{DateTime, Local};
use regex::Regex;
use siphasher::sip::SipHasher13;

use std::cmp::Ordering;
use std::collections::hash_map::DefaultHasher;
use std::fmt;
use std::hash::{Hash, Hasher};

Expand Down Expand Up @@ -60,7 +60,15 @@ impl Migration {
}

pub fn checksum(&self) -> u64 {
let mut hasher = DefaultHasher::new();
// Previously, `std::collections::hash_map::DefaultHasher` was used
// to calculate the checksum and the implementation at that time
// was SipHasher13. However, that implementation is not guaranteed:
// > The internal algorithm is not specified, and so it and its
// > hashes should not be relied upon over releases.
// We now explicitly use SipHasher13 to both remain compatible with
// existing migrations and prevent breaking from possible future
// changes to `DefaultHasher`.
let mut hasher = SipHasher13::new();
jxs marked this conversation as resolved.
Show resolved Hide resolved
self.name.hash(&mut hasher);
self.version.hash(&mut hasher);
self.sql.hash(&mut hasher);
Expand Down