You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Digest requires FixedOutput and DynDigest requires FixedOutputReset. k12::KangarooTwelve implements neither, so I can't fully generically/universally allow users to pick it when providing a function that takes e.g. DynDigest:
error[E0277]: the trait bound `KangarooTwelve: FixedOutputReset` is not satisfied
--> src/main.rs:19:29
|
19 | hash_path("Cargo.toml", &mut k12::KangarooTwelve::default()).unwrap();
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FixedOutputReset` is not implemented for `KangarooTwelve`
| |
| required by a bound introduced by this call
|
= help: the trait `FixedOutputReset` is implemented for `CoreWrapper<T>`
= note: required because of the requirements on the impl of `DynDigest` for `KangarooTwelve`
= note: required for the cast to the object type `dyn DynDigest`
Are there alternatives to Digest and DynDigest that don't require a fixed output? As author of a function like fn hash_path I don't really care about the length of the output, so could Digest and DynDigest alternatively be changed to not require fixed output?
I noticed this while implementing clap-digest. I basically had to drop all implementations that have variable lengths, and was wondering if there is or could be another abstraction that would allow variable length digests as well.
The text was updated successfully, but these errors were encountered:
No, you would need to develop your own trait which abstracts over fixed output hashes and XOFs. We may potentially adapt it into digest later.
Note that, k12 is a XOF, i.e. it can produce hash of an arbitrary length. So finalization methods of the hypothetical trait have to accept desired length of output hash. But what it will do for fixed output functions in cases of length mismatch? Should the methods panic, or maybe truncate if requested length is smaller?
An alternative approach could be to introduce a wrapper which transforms XOF into a type which implements the FixedOutput trait, something like:
// This type implements `FixedOutput` with `OutputSize = U32`typeKangarooTwelve_256 = XofFixedWrapper<k12::KangarooTwelve,U32>;
Digest
requiresFixedOutput
andDynDigest
requiresFixedOutputReset
.k12::KangarooTwelve
implements neither, so I can't fully generically/universally allow users to pick it when providing a function that takes e.g.DynDigest
:Are there alternatives to
Digest
andDynDigest
that don't require a fixed output? As author of a function likefn hash_path
I don't really care about the length of the output, so couldDigest
andDynDigest
alternatively be changed to not require fixed output?I noticed this while implementing clap-digest. I basically had to drop all implementations that have variable lengths, and was wondering if there is or could be another abstraction that would allow variable length digests as well.
The text was updated successfully, but these errors were encountered: