1#![deny(clippy::all)]
4#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
5
6use hex::FromHexError;
7
8pub mod certificate;
9pub mod hash_tree;
10pub use crate::hash_tree::*;
11pub mod rb_tree;
12pub use crate::rb_tree::*;
13pub mod nested_rb_tree;
14pub use crate::nested_rb_tree::*;
15
16#[doc(inline)]
17pub use hash_tree::LookupResult;
18
19pub type HashTree = hash_tree::HashTree<Vec<u8>>;
21pub type HashTreeNode = hash_tree::HashTreeNode<Vec<u8>>;
23pub type Label = hash_tree::Label<Vec<u8>>;
25pub type SubtreeLookupResult = hash_tree::SubtreeLookupResult<Vec<u8>>;
27
28pub type Delegation = certificate::Delegation<Vec<u8>>;
30pub type Certificate = certificate::Certificate<Vec<u8>>;
32
33#[inline]
35pub fn empty() -> HashTree {
36 hash_tree::empty()
37}
38
39#[inline]
41pub fn fork(left: HashTree, right: HashTree) -> HashTree {
42 hash_tree::fork(left, right)
43}
44
45#[inline]
47pub fn labeled<L: Into<Label>, N: Into<HashTree>>(label: L, node: N) -> HashTree {
48 hash_tree::label(label, node)
49}
50
51#[inline]
53pub fn leaf<L: Into<Vec<u8>>>(leaf: L) -> HashTree {
54 hash_tree::leaf(leaf)
55}
56
57#[inline]
59pub fn pruned<C: Into<Hash>>(content: C) -> HashTree {
60 hash_tree::pruned(content)
61}
62
63#[inline]
66pub fn pruned_from_hex<C: AsRef<str>>(content: C) -> Result<HashTree, FromHexError> {
67 hash_tree::pruned_from_hex(content)
68}
69
70#[cfg(feature = "serde")]
71mod serde_impl {
72 use std::borrow::Cow;
73
74 use serde::Deserialize;
75 use serde_bytes::{ByteBuf, Bytes};
76
77 pub trait Storage {
79 type Temp<'a>: Deserialize<'a>;
80 type Value<'a>: AsRef<[u8]>;
81 fn convert(t: Self::Temp<'_>) -> Self::Value<'_>;
82 }
83
84 pub struct VecStorage;
86 pub struct SliceStorage;
88 pub struct CowStorage;
90
91 impl Storage for VecStorage {
92 type Temp<'a> = ByteBuf;
93 type Value<'a> = Vec<u8>;
94 fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
95 t.into_vec()
96 }
97 }
98
99 impl Storage for SliceStorage {
100 type Temp<'a> = &'a Bytes;
101 type Value<'a> = &'a [u8];
102 fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
103 t.as_ref()
104 }
105 }
106
107 impl Storage for CowStorage {
108 type Temp<'a> = &'a Bytes;
109 type Value<'a> = Cow<'a, [u8]>;
110 fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
111 Cow::Borrowed(t.as_ref())
112 }
113 }
114}