use bacteria::Transcript;
use mohan::dalek::digest::generic_array::typenum::{U32, U64};
use mohan::dalek::digest::{ExtendableOutput, FixedOutput, XofReader};
#[derive(Clone)] pub struct SigningContext(Transcript);
impl SigningContext {
pub fn new(context: &'static [u8]) -> SigningContext {
SigningContext(Transcript::new(context))
}
pub fn to_owned(&mut self) -> Transcript {
self.0.clone()
}
pub fn bytes(&self, bytes: &[u8]) -> Transcript {
let mut t = self.0.clone();
t.append_message(b"sign-bytes", bytes);
t
}
pub fn xof<D: ExtendableOutput>(&self, h: D) -> Transcript {
let mut prehash = [0u8; 32];
h.xof_result().read(&mut prehash);
let mut t = self.0.clone();
t.append_message(b"sign-XoF", &prehash);
t
}
pub fn from_hash256<D: FixedOutput<OutputSize = U32>>(&self, h: D) -> Transcript {
let mut prehash = [0u8; 32];
prehash.copy_from_slice(h.fixed_result().as_slice());
let mut t = self.0.clone();
t.append_message(b"sign-256", &prehash);
t
}
pub fn from_hash512<D: FixedOutput<OutputSize = U64>>(&self, h: D) -> Transcript {
let mut prehash = [0u8; 64];
prehash.copy_from_slice(h.fixed_result().as_slice());
let mut t = self.0.clone();
t.append_message(b"sign-256", &prehash);
t
}
}