#[repr(transparent)]pub struct Hash256(pub [u8; 32]);Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl Hash256
impl Hash256
Sourcepub fn digest<T: AsRef<[u8]>>(bytes: &T) -> Self
pub fn digest<T: AsRef<[u8]>>(bytes: &T) -> Self
Creates a new hash from a byte representation of some data.
let data = "This is some data that can be hashed !";
let hash = Hash256::digest(&data);Sourcepub fn digest_w_x00<T: AsRef<[u8]>>(bytes: &T) -> Self
pub fn digest_w_x00<T: AsRef<[u8]>>(bytes: &T) -> Self
Creates a new hash from a byte representation of some data.
A special byte \x00 is fed into the hasher, before the data is added.
Can be used for merkle hash trees that conform to RFC6962.
Sourcepub fn digest_w_x01<T: AsRef<[u8]>>(bytes: &T) -> Self
pub fn digest_w_x01<T: AsRef<[u8]>>(bytes: &T) -> Self
Creates a new hash from a byte representation of some data.
A special byte \x01 is fed into the hasher, before the data is added.
Can be used for merkle hash trees that conform to RFC6962.
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Creates a Hash256, where all bits are set to 0.
This is mostly used for testing, where we want to create hashes without some data.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates a new hash without any data.
This returns the initial state of the hasher, without updating it with data. The following variants all create the same output hash:
let hash = Hash256::empty();
let h2 = Hash256::digest(b"");
let mut hasher = Hasher::new();
let h3 = hasher.finalize();
assert_eq!(hash, h2);
assert_eq!(hash, h3);Sourcepub fn sum(h1: &Hash256, h2: &Hash256) -> Hash256
pub fn sum(h1: &Hash256, h2: &Hash256) -> Hash256
Constructs a new hash from two other hashes.
Note: The sum of two hashes is not commutative, so the order of the hashes matter:
let h1 = Hash256::empty();
let h2 = Hash256::zero();
assert_ne!(Hash256::sum(&h1, &h2), Hash256::sum(&h2, &h1));Alternatively you can use the + operator directly, since the Hash256 implements Add:
let h1 = Hash256::empty();
let h2 = Hash256::zero();
let sum = Hash256::sum(&h1, &h2);
assert_eq!(h1 + h2, sum);Sourcepub fn to_u64(&self) -> u64
pub fn to_u64(&self) -> u64
Converts the hash to an u64 value.
The Hash256 can also be used to generate random values (which are equally distributed,
due to the cryptographic properties of the underlying hash-function).
Sourcepub fn into_vec(self) -> Vec<u8> ⓘ
pub fn into_vec(self) -> Vec<u8> ⓘ
Consumes the hash and returns the underlying byte-slice as a vector
Sourcepub fn into_slice(self) -> [u8; 32]
pub fn into_slice(self) -> [u8; 32]
Consumes the hash and returns the underlying byte-slice
Trait Implementations§
impl Copy for Hash256
Source§impl<'de> Deserialize<'de> for Hash256
impl<'de> Deserialize<'de> for Hash256
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Hash256
Source§impl From<GenericArray<u8, <CoreWrapper<Sha3_256Core> as OutputSizeUser>::OutputSize>> for Hash256
impl From<GenericArray<u8, <CoreWrapper<Sha3_256Core> as OutputSizeUser>::OutputSize>> for Hash256
Source§impl Ord for Hash256
impl Ord for Hash256
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Hash256
impl PartialOrd for Hash256
impl SimpleToVerifyInSlice for Hash256
impl StructuralPartialEq for Hash256
Source§impl<'a> Verifiable for Hash256
impl<'a> Verifiable for Hash256
Source§fn run_verifier(
v: &mut Verifier<'_, '_>,
pos: usize,
) -> Result<(), InvalidFlatbuffer>
fn run_verifier( v: &mut Verifier<'_, '_>, pos: usize, ) -> Result<(), InvalidFlatbuffer>
pos in the verifier’s buffer.
Should not need to be called directly.