1#![cfg_attr(docsrs, feature(doc_cfg))]
4#![no_std]
5#![doc = include_str!("../README.md")]
6extern crate alloc;
7
8#[cfg(feature = "std")]
9extern crate std;
10
11pub use digest;
12
13mod consistency;
14mod error;
15mod inclusion;
16pub mod mem_backed_tree;
17mod tree_util;
18
19#[cfg(test)]
20mod test_util;
21
22pub use consistency::*;
23pub use error::*;
24pub use inclusion::*;
25pub use tree_util::*;
26
27use digest::Digest;
28use subtle::ConstantTimeEq;
29
30#[derive(Clone, Debug)]
32pub struct RootHash<H: Digest> {
33 root_hash: digest::Output<H>,
35
36 num_leaves: u64,
38}
39
40impl<H: Digest> PartialEq for RootHash<H> {
41 fn eq(&self, other: &RootHash<H>) -> bool {
43 self.num_leaves == other.num_leaves() && self.root_hash.ct_eq(&other.root_hash).into()
44 }
45}
46
47impl<H: Digest> Eq for RootHash<H> {}
48
49impl<H: Digest> RootHash<H> {
50 pub fn new(digest: digest::Output<H>, num_leaves: u64) -> RootHash<H> {
53 RootHash {
54 root_hash: digest,
55 num_leaves,
56 }
57 }
58
59 pub fn as_bytes(&self) -> &digest::Output<H> {
64 &self.root_hash
65 }
66
67 pub fn num_leaves(&self) -> u64 {
69 self.num_leaves
70 }
71}