Comments (5)
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.
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.
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.
Well, I guess until const generics are introduced we probably could add output_size
method to FixedOutput
and Digest
traits.
from hashes.
Fixed with digest v0.8
. See output_size
method on Digest
trait.
from hashes.
Related Issues (20)
- fix(?): some `extern` functions couldn't be found HOT 2
- `sha2` fails to build in Windows on an ARM device HOT 2
- blake2: MAC variants should not be constructable with an empty key?
- sha2: Interested in a way to save/restore internal state HOT 1
- Strange quirk in SHA256 impl HOT 1
- "no such associated item" in IDE but build succeeds HOT 3
- jh: remove dependency on `ppv-lite86`
- Sha256::new() is always marked as an error in the vscode HOT 1
- can't build `[email protected]` HOT 1
- soft-sha512 code size seems unreasonably high on thumbv7em HOT 1
- Broken documentation: What on earth is "GenericArray" HOT 9
- sha256 has very wildly varying performance compared to ring between computers (same binary) HOT 2
- sha2: aarch64 acceleration broken on master
- sha2: use ARM intrinsics rather than ASM HOT 1
- Finalising a sha256 has into an [u8; 32] HOT 9
- When are asm and intrinsics worth it? HOT 1
- No tag for sha-1 v0.10.1 HOT 2
- Replace assertions with debug assertions HOT 1
- Tracking issue for next release series
- Point users to how to make hex strings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashes.