#![deny(clippy::all)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use hex::FromHexError;
pub mod certificate;
pub mod hash_tree;
pub use crate::hash_tree::*;
pub mod rb_tree;
pub use crate::rb_tree::*;
pub mod nested_rb_tree;
pub use crate::nested_rb_tree::*;
#[doc(inline)]
pub use hash_tree::LookupResult;
pub type HashTree = hash_tree::HashTree<Vec<u8>>;
pub type HashTreeNode = hash_tree::HashTreeNode<Vec<u8>>;
pub type Label = hash_tree::Label<Vec<u8>>;
pub type SubtreeLookupResult = hash_tree::SubtreeLookupResult<Vec<u8>>;
pub type Delegation = certificate::Delegation<Vec<u8>>;
pub type Certificate = certificate::Certificate<Vec<u8>>;
#[inline]
pub fn empty() -> HashTree {
hash_tree::empty()
}
#[inline]
pub fn fork(left: HashTree, right: HashTree) -> HashTree {
hash_tree::fork(left, right)
}
#[inline]
pub fn labeled<L: Into<Label>, N: Into<HashTree>>(label: L, node: N) -> HashTree {
hash_tree::label(label, node)
}
#[inline]
pub fn leaf<L: Into<Vec<u8>>>(leaf: L) -> HashTree {
hash_tree::leaf(leaf)
}
#[inline]
pub fn pruned<C: Into<Hash>>(content: C) -> HashTree {
hash_tree::pruned(content)
}
#[inline]
pub fn pruned_from_hex<C: AsRef<str>>(content: C) -> Result<HashTree, FromHexError> {
hash_tree::pruned_from_hex(content)
}
#[cfg(feature = "serde")]
mod serde_impl {
use std::borrow::Cow;
use serde::Deserialize;
use serde_bytes::{ByteBuf, Bytes};
pub trait Storage {
type Temp<'a>: Deserialize<'a>;
type Value<'a>: AsRef<[u8]>;
fn convert(t: Self::Temp<'_>) -> Self::Value<'_>;
}
pub struct VecStorage;
pub struct SliceStorage;
pub struct CowStorage;
impl Storage for VecStorage {
type Temp<'a> = ByteBuf;
type Value<'a> = Vec<u8>;
fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
t.into_vec()
}
}
impl Storage for SliceStorage {
type Temp<'a> = &'a Bytes;
type Value<'a> = &'a [u8];
fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
t.as_ref()
}
}
impl Storage for CowStorage {
type Temp<'a> = &'a Bytes;
type Value<'a> = Cow<'a, [u8]>;
fn convert(t: Self::Temp<'_>) -> Self::Value<'_> {
Cow::Borrowed(t.as_ref())
}
}
}