Comments (9)
@WhyNotHugo regarding the diagnostics, here's a tracking issue for that: RustCrypto/traits#1069
from hashes.
finalize
for SHA-256 returns GenericArray<u8; U32>
(you can not click on type in the digest
docs because of a certain rustdoc bug) which effectively is [u8; 32]
. It implements Into<[u8; 32]>
trait, so you can write let hash: [u8; 32] = hasher.finalize().into();
. Now, if you want to return only 8 bytes, you have to decide which bytes to take and which to discard. GenericArray
supports all the usual slice operations, so it should be easy to do.
from hashes.
Er, sorry, I meant [u8;32]
, my bad.
from hashes.
let hash: [u8; 32] = hasher.finalize().into();
would generate a GenericArray<u8; U32>
and then convert that into an array. Is there some way to get the hash directly without the intermediate type?
from hashes.
You should be able to do something like:
let mut buf = [0u8; 32];
digest.finalize_into(buf.as_ref());
(it might require .as_ref().into()
)
However note that there's no cost to the "intermediate type" and these two are really equivalent.
from hashes.
Thanks, let hash: [u8; 32] = hasher.finalize().into();
works fine.
I prefer to avoid adding generic-array as a direct dependency and using GenericArray
directly since I don't want internal implementation details of sha2
leaking into my own codebase.
from hashes.
However note that there's no cost to the "intermediate type" and these two are really equivalent.
This is a good-to-know. Do you think it's worth including the example above in the README or in the docs?
from hashes.
We are in the process of migrating to hybrid-array
, which will make extraction of array easier, so it's probably not worth to write new GenericArray
-centric docs now.
from hashes.
Nice, happy to see that there is also a path to move onto const-generic, that will definitely make things simpler on the API side :)
from hashes.
Related Issues (20)
- comparing after dereferencing or unsafely indexing, which is faster? HOT 1
- Blake2 parameters cannot be used without a key HOT 3
- use keccak crate in k12 HOT 2
- streebog: Use const fn to generate `SHUFFLED_LIN_TABLE`
- 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 8
- 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
- When are asm and intrinsics worth it? 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.