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

Hasher trait not implemented for digests #49

Closed
PlasmaPower opened this issue Jan 22, 2018 · 5 comments
Closed

Hasher trait not implemented for digests #49

PlasmaPower opened this issue Jan 22, 2018 · 5 comments

Comments

@PlasmaPower
Copy link

PlasmaPower commented Jan 22, 2018

The std::hash::Hasher trait is not implemented for these digests. The trait is identical to the digest::Input and digest::FixedOutput traits. Implementing it would be useful for me, because I'd like to have my std::hash::Hash implementation be usable with a digest::Digest.

@PlasmaPower
Copy link
Author

Oh, I just noticed that the digest::*Output traits take self, whereas std::hash::Hasher::finish takes &self. That will be a problem.

@newpavlov
Copy link
Member

newpavlov commented Jan 22, 2018

Hasher is a really bad fit for crypto hash functions. See for example this comment and the following discussion.

@newpavlov
Copy link
Member

newpavlov commented Jan 22, 2018

One way to circumvent this in your code is to define your generic wrapper type and implement Hasher for it:

struct MyDigest<D: Digest> {
    d: D
}

impl<D: Digest> Hasher for MyDigest<D> {
    // ..
}

@PlasmaPower
Copy link
Author

I ended up using a similar solution. Perhaps we could add a method to the digest::Input trait to accept std::hash::Hash objects.

@newpavlov
Copy link
Member

In that case I will close this issue as we currently don't have plans regarding implementing Hasher. Take a look at this issue, in which we discuss crate for recursively hashing structs. maybe you'll find mzabaluev/digest-hash crate useful.

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