Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 75d4566

Browse files
authored
Merge pull request #108 from LNP-BP/feat/c-repr
Repr(C) for hash types
2 parents 6e22bd8 + 4f5e805 commit 75d4566

10 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/hash160.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use Error;
2929
/// Output of the Bitcoin HASH160 hash function
3030
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
3131
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
32+
#[repr(transparent)]
3233
pub struct Hash(
3334
#[cfg_attr(feature = "schemars", schemars(schema_with="crate::util::json_hex_string::len_20"))]
3435
[u8; 20]

src/hmac.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use Error;
3131
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
3232
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3333
#[cfg_attr(feature = "schemars", schemars(transparent))]
34+
#[repr(transparent)]
3435
pub struct Hmac<T: HashTrait>(T);
3536

3637
impl<T: HashTrait + str::FromStr> str::FromStr for Hmac<T> {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ macro_rules! hash_newtype {
146146
($newtype:ident, $hash:ty, $len:expr, $docs:meta, $reverse:expr) => {
147147
#[$docs]
148148
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
149+
#[repr(transparent)]
149150
pub struct $newtype($hash);
150151

151152
hex_fmt_impl!(Debug, $newtype);

src/ripemd160.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl EngineTrait for HashEngine {
7777
/// Output of the RIPEMD160 hash function
7878
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
7979
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
80+
#[repr(transparent)]
8081
pub struct Hash(
8182
#[cfg_attr(feature = "schemars", schemars(schema_with="util::json_hex_string::len_20"))]
8283
[u8; 20]

src/sha1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl EngineTrait for HashEngine {
7272
/// Output of the SHA1 hash function
7373
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
7474
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
75+
#[repr(transparent)]
7576
pub struct Hash(
7677
#[cfg_attr(feature = "schemars", schemars(schema_with="util::json_hex_string::len_20"))]
7778
[u8; 20]

src/sha256.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl EngineTrait for HashEngine {
7373
/// Output of the SHA256 hash function
7474
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
7575
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
76+
#[repr(transparent)]
7677
pub struct Hash(
7778
#[cfg_attr(feature = "schemars", schemars(schema_with="util::json_hex_string::len_32"))]
7879
[u8; 32]

src/sha256d.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use Error;
2323
/// Output of the SHA256d hash function
2424
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
2525
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
26+
#[repr(transparent)]
2627
pub struct Hash(
2728
#[cfg_attr(feature = "schemars", schemars(schema_with="crate::util::json_hex_string::len_32"))]
2829
[u8; 32]

src/sha256t.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub trait Tag {
3131

3232
/// Output of the SHA256t hash function.
3333
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
34+
#[repr(transparent)]
3435
pub struct Hash<T: Tag>(
3536
#[cfg_attr(feature = "schemars", schemars(schema_with="crate::util::json_hex_string::len_32"))]
3637
[u8; 32],

src/sha512.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl EngineTrait for HashEngine {
7979

8080
/// Output of the SHA256 hash function
8181
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
82+
#[repr(transparent)]
8283
pub struct Hash(
8384
#[cfg_attr(feature = "schemars", schemars(schema_with="util::json_hex_string::len_64"))]
8485
[u8; 64]

src/siphash24.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl EngineTrait for HashEngine {
197197
/// Output of the SipHash24 hash function.
198198
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
199199
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
200+
#[repr(transparent)]
200201
pub struct Hash(
201202
#[cfg_attr(feature = "schemars", schemars(schema_with="util::json_hex_string::len_8"))]
202203
[u8; 8]

0 commit comments

Comments
 (0)