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