Skip to content

Commit

Permalink
refactor: remove ToBytes and FromBytes implementations
Browse files Browse the repository at this point in the history
These traits no longer exist upstream. Instead we should be using
the `CanonicalDeserialize` or `CanonicalSerialize` traits:

arkworks-rs/algebra#417
  • Loading branch information
redshiftzero committed Apr 25, 2023
1 parent 627fc96 commit c3157a8
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
use std::convert::TryInto;

use ark_ff::{FromBytes, ToBytes};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::io::{Read, Result as IoResult, Write};

use crate::{AffineElement, Element, Encoding, FieldExt, Fq};

impl ToBytes for Element {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
let field_element = self.vartime_compress_to_field();
let bytes: [u8; 32] = field_element.to_bytes();
bytes.write(&mut writer)
}
}

impl FromBytes for Element {
#[inline]
fn read<R: Read>(mut reader: R) -> IoResult<Self> {
let field_element = Fq::read(&mut reader)?;
let element = Encoding(field_element.to_bytes())
.vartime_decompress()
.map_err(|_| std::io::ErrorKind::InvalidData)?;
Ok(element)
}
}

impl ToBytes for AffineElement {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
let element: Element = self.into();
element.write(&mut writer)
}
}

impl FromBytes for AffineElement {
#[inline]
fn read<R: Read>(mut reader: R) -> IoResult<Self> {
let element = Element::read(&mut reader)?;
Ok(element.into())
}
}

impl CanonicalDeserialize for AffineElement {
fn deserialize_with_mode<R: Read>(
reader: R,
Expand Down

0 comments on commit c3157a8

Please sign in to comment.