-
Notifications
You must be signed in to change notification settings - Fork 293
Closed
Description
Claimed by @gsgsingh93
Moved from #1:
I'm having some trouble with the types for Grostl. The issue is that the BlockSize depends on the OutputSize, and so I can't figure out to define the impl for Digest
. If the Output size is 256 bits or less, then 512 is used as the block size. If the output size is greater than 256 bytes, then 1024 is used as the block size. Here's what I have right now, with the incorrectly hardcoded BlockSize
as U512
extern crate digest;
extern crate generic_array;
use std::marker::PhantomData;
use digest::Digest;
use generic_array::{ArrayLength, GenericArray};
use generic_array::typenum::U512;
// TODO: This could also be U1024
type BlockSize = U512;
pub struct Grostl<OutputSize: ArrayLength<u8>> {
phantom: PhantomData<OutputSize>,
}
impl<OutputSize: ArrayLength<u8>> Grostl<OutputSize> {
fn new() -> Grostl<OutputSize> {
Grostl { phantom: PhantomData }
}
}
impl<OutputSize: ArrayLength<u8>> Default for Grostl<OutputSize> {
fn default() -> Self { Self::new() }
}
impl<OutputSize: ArrayLength<u8>> Digest for Grostl<OutputSize> {
type OutputSize = OutputSize;
type BlockSize = BlockSize;
fn input(&mut self, input: &[u8]) {
}
fn result(mut self) -> GenericArray<u8, Self::OutputSize> {
GenericArray::default()
}
}
Note that OutputSize
is parameterized here because Grostl can output hashes between 1 and 64 bytes.
EDIT: I guess if there's no fancy solution with the generics that could get this to work, I could always just override block_bytes
and block_bits
in the trait, and just set a dummy BlockSize
and not use it.
Metadata
Metadata
Assignees
Labels
No labels