brine_tree/
utils.rs

1use sha2::{Digest, Sha256};
2use super::hash::Hash;
3use super::error::{ProgramError, ProgramResult};
4
5#[inline]
6pub fn hash(data: &[u8]) -> Hash {
7    let mut hasher = Sha256::new();
8    hasher.update(data);
9    Hash::new_from_array(hasher.finalize().into())
10}
11
12#[inline]
13pub fn hashv(data: &[&[u8]]) -> Hash {
14    let mut hasher = Sha256::new();
15    for d in data {
16        hasher.update(d);
17    }
18    Hash::new_from_array(hasher.finalize().into())
19}
20
21#[inline]
22pub fn check_condition(condition: bool, msg: &'static str) -> ProgramResult {
23    if condition {
24        Ok(())
25    } else {
26        Err(ProgramError::Custom(msg))
27    }
28}