Coverage Report

Created: 2026-03-23 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/signature-2.2.0/src/encoding.rs
Line
Count
Source
1
//! Encoding support.
2
3
#[cfg(feature = "alloc")]
4
use alloc::vec::Vec;
5
6
/// Support for decoding/encoding signatures as bytes.
7
pub trait SignatureEncoding:
8
    Clone + Sized + for<'a> TryFrom<&'a [u8]> + TryInto<Self::Repr>
9
{
10
    /// Byte representation of a signature.
11
    type Repr: 'static + AsRef<[u8]> + Clone + Send + Sync;
12
13
    /// Encode signature as its byte representation.
14
0
    fn to_bytes(&self) -> Self::Repr {
15
0
        self.clone()
16
0
            .try_into()
17
0
            .ok()
18
0
            .expect("signature encoding error")
19
0
    }
20
21
    /// Encode signature as a byte vector.
22
    #[cfg(feature = "alloc")]
23
0
    fn to_vec(&self) -> Vec<u8> {
24
0
        self.to_bytes().as_ref().to_vec()
25
0
    }
26
27
    /// Get the length of this signature when encoded.
28
0
    fn encoded_len(&self) -> usize {
29
0
        self.to_bytes().as_ref().len()
30
0
    }
31
}