Skip to content

Commit

Permalink
add H384 and H768 hash types (#684)
Browse files Browse the repository at this point in the history
* add H384 and H768 hash types

* implement `impl-serde`, `impl-codec`, `impl-rlp` for `H384` and `H768` types.

* remove redundant double impl of serde for H384
  • Loading branch information
drskalman committed Oct 27, 2022
1 parent 3c807b5 commit 26c1423
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions primitive-types/src/lib.rs
Expand Up @@ -62,11 +62,21 @@ construct_fixed_hash! {
#[cfg_attr(feature = "scale-info", derive(TypeInfo))]
pub struct H256(32);
}
construct_fixed_hash! {
/// Fixed-size uninterpreted hash type with 48 bytes (384 bits) size.
#[cfg_attr(feature = "scale-info", derive(TypeInfo))]
pub struct H384(48);
}
construct_fixed_hash! {
/// Fixed-size uninterpreted hash type with 64 bytes (512 bits) size.
#[cfg_attr(feature = "scale-info", derive(TypeInfo))]
pub struct H512(64);
}
construct_fixed_hash! {
/// Fixed-size uninterpreted hash type with 96 bytes (768 bits) size.
#[cfg_attr(feature = "scale-info", derive(TypeInfo))]
pub struct H768(96);
}

#[cfg(feature = "num-traits")]
mod num_traits {
Expand All @@ -90,7 +100,9 @@ mod serde {
impl_fixed_hash_serde!(H128, 16);
impl_fixed_hash_serde!(H160, 20);
impl_fixed_hash_serde!(H256, 32);
impl_fixed_hash_serde!(H384, 48);
impl_fixed_hash_serde!(H512, 64);
impl_fixed_hash_serde!(H768, 96);
}

#[cfg(feature = "impl-codec")]
Expand All @@ -105,7 +117,9 @@ mod codec {
impl_fixed_hash_codec!(H128, 16);
impl_fixed_hash_codec!(H160, 20);
impl_fixed_hash_codec!(H256, 32);
impl_fixed_hash_codec!(H384, 48);
impl_fixed_hash_codec!(H512, 64);
impl_fixed_hash_codec!(H768, 96);
}

#[cfg(feature = "impl-rlp")]
Expand All @@ -120,7 +134,9 @@ mod rlp {
impl_fixed_hash_rlp!(H128, 16);
impl_fixed_hash_rlp!(H160, 20);
impl_fixed_hash_rlp!(H256, 32);
impl_fixed_hash_rlp!(H384, 48);
impl_fixed_hash_rlp!(H512, 64);
impl_fixed_hash_rlp!(H768, 96);
}

impl_fixed_hash_conversions!(H256, H160);
Expand Down

0 comments on commit 26c1423

Please sign in to comment.