use crate::{
errors::DeserializationError,
field::{element::FieldElement, traits::IsField},
};
use crate::errors::ByteConversionError;
pub trait ByteConversion {
#[cfg(feature = "alloc")]
fn to_bytes_be(&self) -> alloc::vec::Vec<u8>;
#[cfg(feature = "alloc")]
fn to_bytes_le(&self) -> alloc::vec::Vec<u8>;
fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>
where
Self: Sized;
fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>
where
Self: Sized;
}
#[cfg(feature = "alloc")]
pub trait AsBytes {
fn as_bytes(&self) -> alloc::vec::Vec<u8>;
}
#[cfg(feature = "alloc")]
impl AsBytes for u32 {
fn as_bytes(&self) -> alloc::vec::Vec<u8> {
self.to_le_bytes().to_vec()
}
}
#[cfg(feature = "alloc")]
impl AsBytes for u64 {
fn as_bytes(&self) -> alloc::vec::Vec<u8> {
self.to_le_bytes().to_vec()
}
}
pub trait Deserializable {
fn deserialize(bytes: &[u8]) -> Result<Self, DeserializationError>
where
Self: Sized;
}
pub trait IsRandomFieldElementGenerator<F: IsField> {
fn generate(&self) -> FieldElement<F>;
}