w3f_bls/
serialize.rs

1use alloc::{vec, vec::Vec};
2use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
3
4/// Serialization code that is used by multiple modules.
5// Note that ark_ff::bytes::ToBytes for projective points export them without converting them to affine
6// and so they might leak information about the secret key.
7pub trait SerializableToBytes: CanonicalSerialize + CanonicalDeserialize {
8    const SERIALIZED_BYTES_SIZE: usize;
9
10    fn to_bytes(&self) -> Vec<u8> {
11        let mut serialized_representation: Vec<u8> = vec![0; Self::SERIALIZED_BYTES_SIZE];
12        self.serialize_compressed(&mut serialized_representation[..])
13            .unwrap();
14
15        return serialized_representation;
16    }
17
18    fn from_bytes(bytes: &[u8]) -> Result<Self, SerializationError> {
19        Self::deserialize_compressed(bytes)
20    }
21}