signature/
encoding.rs
1#[cfg(feature = "alloc")]
4use alloc::vec::Vec;
5
6pub trait SignatureEncoding:
8 Clone + Sized + for<'a> TryFrom<&'a [u8]> + TryInto<Self::Repr>
9{
10 type Repr: 'static + AsRef<[u8]> + Clone + Send + Sync;
12
13 fn to_bytes(&self) -> Self::Repr {
15 self.clone()
16 .try_into()
17 .ok()
18 .expect("signature encoding error")
19 }
20
21 #[cfg(feature = "alloc")]
23 fn to_vec(&self) -> Vec<u8> {
24 self.to_bytes().as_ref().to_vec()
25 }
26
27 fn encoded_len(&self) -> usize {
29 self.to_bytes().as_ref().len()
30 }
31}