use crate::pad_secret::Secret;
use crate::{error::DecodingError, index::TreeIndex};
pub trait Mergeable {
fn merge(lch: &Self, rch: &Self) -> Self;
}
pub trait Paddable {
fn padding(idx: &TreeIndex, secret: &Secret) -> Self;
}
pub trait TypeName {
fn get_name() -> String {
"Name".to_owned()
}
}
pub trait Rand {
fn randomize(&mut self) {}
}
pub trait ProofExtractable {
type ProofNode;
fn get_proof_node(&self) -> Self::ProofNode;
}
pub trait PaddingProvable {
type PaddingProof;
fn prove_padding_node(&self, idx: &TreeIndex, secret: &Secret) -> Self::PaddingProof;
fn verify_padding_node(
node: &<Self as ProofExtractable>::ProofNode,
proof: &Self::PaddingProof,
idx: &TreeIndex,
) -> bool
where
Self: ProofExtractable;
}
pub trait Serializable {
fn serialize(&self) -> Vec<u8>
where
Self: std::marker::Sized;
fn deserialize_as_a_unit(bytes: &[u8], begin: &mut usize) -> Result<Self, DecodingError>
where
Self: std::marker::Sized;
fn deserialize(bytes: &[u8]) -> Result<Self, DecodingError>
where
Self: std::marker::Sized,
{
let mut begin = 0usize;
let res = Self::deserialize_as_a_unit(bytes, &mut begin);
if let Err(e) = res {
return Err(e);
}
if begin != bytes.len() {
println!("{}, {}", begin, bytes.len());
return Err(DecodingError::TooManyEncodedBytes);
}
res
}
}
pub trait InclusionProvable {
type ProofNodeType;
type TreeStruct;
fn generate_inclusion_proof(tree: &Self::TreeStruct, list: &[TreeIndex]) -> Option<Self>
where
Self: std::marker::Sized;
fn verify_inclusion_proof(
&self,
leaves: &[Self::ProofNodeType],
root: &Self::ProofNodeType,
) -> bool;
}
pub trait RandomSampleable {
type ProofNodeType;
type TreeStruct;
fn random_sampling(tree: &Self::TreeStruct, idx: &TreeIndex, secret: &Secret) -> Self;
fn verify_random_sampling_proof(&self, root: &Self::ProofNodeType) -> bool;
}