Merge rust-bitcoin/rust-bitcoin#1781: hashes: Derive traits on the sha512::Hash type
088fa24be8
hashes: Derive traits on the sha512::Hash type (Tobin C. Harding) Pull request description: For all the other hash types we use derive, by way of the `hash_type!` macro, unless I'm missing something we can do the same for `sha512::Hash`. ACKs for top commit: apoelstra: ACK088fa24be8
Kixunil: ACK088fa24be8
Tree-SHA512: 3849261a8208c8c6108f4ecc5643940d38289f791d1b360ef4b13d60f72b365cd29f07f625a2d320f188defde848ddd64c8532cae5979e54afbf62f741927185
This commit is contained in:
commit
6bf6898add
|
@ -23,7 +23,7 @@
|
|||
use core::convert::TryInto;
|
||||
use core::ops::Index;
|
||||
use core::slice::SliceIndex;
|
||||
use core::{cmp, hash, str};
|
||||
use core::{cmp, str};
|
||||
|
||||
use crate::{Error, HashEngine as _};
|
||||
|
||||
|
@ -80,6 +80,7 @@ impl crate::HashEngine for HashEngine {
|
|||
}
|
||||
|
||||
/// Output of the SHA512 hash function.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[repr(transparent)]
|
||||
pub struct Hash(
|
||||
|
@ -96,38 +97,6 @@ impl Hash {
|
|||
fn internal_engine() -> HashEngine { Default::default() }
|
||||
}
|
||||
|
||||
impl Copy for Hash {}
|
||||
|
||||
impl Clone for Hash {
|
||||
fn clone(&self) -> Hash {
|
||||
let mut ret = [0; 64];
|
||||
ret.copy_from_slice(&self.0);
|
||||
Hash(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Hash {
|
||||
fn eq(&self, other: &Hash) -> bool { self.0[..] == other.0[..] }
|
||||
}
|
||||
|
||||
impl Eq for Hash {}
|
||||
|
||||
impl Default for Hash {
|
||||
fn default() -> Hash { Hash([0; 64]) }
|
||||
}
|
||||
|
||||
impl PartialOrd for Hash {
|
||||
fn partial_cmp(&self, other: &Hash) -> Option<cmp::Ordering> { self.0.partial_cmp(&other.0) }
|
||||
}
|
||||
|
||||
impl Ord for Hash {
|
||||
fn cmp(&self, other: &Hash) -> cmp::Ordering { self.0.cmp(&other.0) }
|
||||
}
|
||||
|
||||
impl hash::Hash for Hash {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) { self.0.hash(state) }
|
||||
}
|
||||
|
||||
#[cfg(not(fuzzing))]
|
||||
pub(crate) fn from_engine(mut e: HashEngine) -> Hash {
|
||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 16 bytes remaining
|
||||
|
|
Loading…
Reference in New Issue