Giter Site home page Giter Site logo

Comments (5)

burdges avatar burdges commented on August 15, 2024

Right now, the digest crate and these hashes use the generic_array crate because Rust only gained const generics recently. I'd hope that once const generics stabilize the generic_array crate will be removed from all crates including this one, and doing so means adding a constant for the digest length.

from hashes.

newpavlov avatar newpavlov commented on August 15, 2024

On stabilization of const generics I'll definitely migrate to them, but right now as @burdges said we are tied to generic-array and typenum. If you want to retrieve digest output size at runtime, you can write the following code:

use generic-array::typenum::Unsigned;
let n = Sha256::OutputSize::to_usize();

We could use associated constant in addition to OutputSize, but right now it's fairly useless and I don't see much benefit in introducing it.

Could you please provide use-case for which you need this constant? Otherwise I am inclined to close this issue.

from hashes.

cardoe avatar cardoe commented on August 15, 2024

Plenty of file formats and other protocols internally include a hash in their data. They typically support multiple hashes in that case and have some form of identifier. When dealing with a binary format you decide which hash is in the data based on the identifier and then read DIGEST_LENGTH of bytes from the data. I honestly expected the Digest trait to provide a length method that was #[inline] that returned the size of the digest. The example provided above by @newpavlov is a bit clunky to say the least.

from hashes.

newpavlov avatar newpavlov commented on August 15, 2024

Well, I guess until const generics are introduced we probably could add output_size method to FixedOutput and Digest traits.

from hashes.

newpavlov avatar newpavlov commented on August 15, 2024

Fixed with digest v0.8. See output_size method on Digest trait.

from hashes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.