Skip to content
Snippets Groups Projects
Unverified Commit 57aa3311 authored by Wei Tang's avatar Wei Tang Committed by GitHub
Browse files

ssz: RawHashable and RawDigestible (#121)

parent 812fcd0d
Branches
No related merge requests found
Pipeline #36287 passed with stages
in 8 minutes and 48 seconds
......@@ -2,6 +2,8 @@ use primitive_types::{U256, H256, H160};
use hash_db::Hasher;
use digest::Digest;
use generic_array::GenericArray;
use core::marker::PhantomData;
use crate::Fixed;
pub trait Digestible<D: Digest> {
......@@ -20,6 +22,32 @@ pub trait Hashable<H: Hasher> {
pub trait Composite { }
pub struct RawDigestible<D: Digest> {
hash: GenericArray<u8, D::OutputSize>,
_marker: PhantomData<D>,
}
impl<D: Digest> Composite for RawDigestible<D> { }
impl<D: Digest> Digestible<D> for RawDigestible<D> {
fn hash(&self) -> GenericArray<u8, D::OutputSize> {
self.hash.clone()
}
}
pub struct RawHashable<H: Hasher> {
hash: H::Out,
_marker: PhantomData<H>,
}
impl<H: Hasher> Composite for RawHashable<H> { }
impl<H: Hasher> Hashable<H> for RawHashable<H> {
fn hash(&self) -> H::Out {
self.hash.clone()
}
}
macro_rules! impl_hashable_and_digestible_with_chunkify {
( $t:ty, $self:ident, $merkleize:ident, $chunkify:ident, $mix_in_length:ident, $e:expr ) => {
impl<H: Hasher> Hashable<H> for $t {
......
......@@ -58,7 +58,7 @@ pub mod hash;
mod tests;
pub use self::codec::{Input, Output, Encode, Decode, Prefixable, Fixed};
pub use self::hash::{Hashable, Digestible, Composite};
pub use self::hash::{Hashable, Digestible, Composite, RawDigestible, RawHashable};
/// Trait that allows zero-copy read/write of value-references to/from slices in LE format.
pub trait Ssz: Decode + Encode {}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment