fedimint_core/bls12_381_serde/
g2.rs1use bls12_381::G2Affine;
2use serde::de::Error;
3use serde::{Deserializer, Serializer};
4
5pub fn serialize<S: Serializer>(point: &G2Affine, s: S) -> Result<S::Ok, S::Error> {
6 serdect::array::serialize_hex_lower_or_bin(&point.to_compressed(), s)
7}
8
9pub fn deserialize<'d, D: Deserializer<'d>>(d: D) -> Result<G2Affine, D::Error> {
10 let mut byte_array = [0; 96];
11
12 serdect::array::deserialize_hex_or_bin(&mut byte_array, d)?;
13
14 Option::from(G2Affine::from_compressed(&byte_array))
15 .ok_or_else(|| Error::custom("Could not decode compressed group element"))
16}