pub trait ByteConvertible<T> {
    // Required methods
    fn convert_to(t: &T) -> Vec<u8>;
    fn convert_from(bytes: &[u8]) -> Result<T, Box<dyn Error>>
       where Self: Sized;
}
Expand description

A trait for converting types to and from byte representations.

This trait provides a common interface for types that can be converted to a byte array and constructed back from a byte array. It is particularly useful for cryptographic operations where serialization and deserialization of objects like points on an elliptic curve or scalars are needed.

Required Methods§

source

fn convert_to(t: &T) -> Vec<u8>

Converts the provided object to a byte array.

Arguments
  • t: A reference to the object to be converted.
Returns

A Vec<u8> representing the byte array of the object.

source

fn convert_from(bytes: &[u8]) -> Result<T, Box<dyn Error>>where Self: Sized,

Constructs an object from a byte array.

Arguments
  • bytes: A slice of bytes from which the object should be constructed.
Returns

A Result which is Ok containing the constructed object if successful, or an Err containing an error if the conversion failed.

Implementations on Foreign Types§

source§

impl ByteConvertible<Scalar> for Scalar

Implementation of ByteConvertible for Scalar.

This implementation provides methods to convert Scalar objects to and from byte arrays. Scalars are fundamental in cryptographic operations and being able to serialize and deserialize them is crucial.

source§

fn convert_to(t: &Scalar) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<Scalar, Box<dyn Error>>

source§

impl ByteConvertible<BigUint> for BigUint

Implementation of ByteConvertible for BigUint.

This implementation provides methods to convert BigUint objects to and from byte arrays, using big-endian byte order.

source§

impl ByteConvertible<Fq> for Scalar

source§

fn convert_to(t: &Scalar) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<Scalar, Box<dyn Error>>

source§

impl ByteConvertible<Fp> for Scalar

source§

fn convert_to(t: &Scalar) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<Scalar, Box<dyn Error>>

source§

impl ByteConvertible<Ep> for Point

source§

fn convert_to(t: &Point) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<Point, Box<dyn Error>>

source§

impl ByteConvertible<RistrettoPoint> for RistrettoPoint

Implementation of ByteConvertible for RistrettoPoint.

This implementation provides methods to convert RistrettoPoint objects to and from byte arrays. It uses the compression and decompression features of the Ristretto group to achieve this.

source§

fn convert_to(t: &RistrettoPoint) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<RistrettoPoint, Box<dyn Error>>

source§

impl ByteConvertible<Eq> for Point

source§

fn convert_to(t: &Point) -> Vec<u8>

source§

fn convert_from(bytes: &[u8]) -> Result<Point, Box<dyn Error>>

Implementors§