cryptraits/convert.rs
1//! Convertion traits.
2
3#[cfg(not(feature = "std"))]
4use alloc::borrow::Cow;
5
6#[cfg(not(feature = "std"))]
7use alloc::vec::Vec;
8
9#[cfg(not(feature = "std"))]
10use alloc::boxed::Box;
11
12use crate::error::Error;
13
14/// Convert from bytes.
15pub trait FromBytes: Len {
16 type E: Error;
17 // const LEN: usize;
18
19 /// Construct a value from a slice of bytes.
20 fn from_bytes(bytes: &[u8]) -> Result<Self, Self::E>
21 where
22 Self: Sized;
23}
24
25/// Convert value into `Vec` of bytes.
26pub trait ToVec: Len {
27 // const LEN: usize;
28
29 /// Convert a key into a vec of bytes.
30 fn to_vec(&self) -> Vec<u8>
31 where
32 Self: Sized;
33}
34
35/// Output length in bytes.
36pub trait Len {
37 const LEN: usize;
38}