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

Hash stability #17

Open
prataprc opened this issue Nov 13, 2021 · 2 comments
Open

Hash stability #17

prataprc opened this issue Nov 13, 2021 · 2 comments

Comments

@prataprc
Copy link
Owner

prataprc commented Nov 13, 2021

Values in jsondata::Json should not change in its hash value for any given hashing algorithm. Also the serialized form of jsondata::Json should not affect its hash value for any give hashing algorithm.

List of common hashing algorithm:

fasthash::city
fasthash::murmur3
SHA1

@Roenbaeck
Copy link

Json currently does not implement Hash. Given that it's internally sorted, from what I understand, I added this impl.

impl Hash for Json{
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.to_string().hash(state);
    }
}

Under what circumstances would two semantically equal JSON documents produce different hashes using this approach?

@prataprc
Copy link
Owner Author

to_string is part of ToString trait, which in turn is consumed by fmt::Display, which is meant for human consumption of data. So we cannot make any guarantees on the output of ToString, it might change later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants