|
1 | 1 | use ark_ff::BigInteger256; |
| 2 | +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; |
2 | 3 | use malloc_size_of::MallocSizeOf; |
3 | 4 | use rsexp::{OfSexp, SexpOf}; |
4 | 5 | use serde::{Deserialize, Serialize}; |
@@ -63,16 +64,14 @@ impl BigInt { |
63 | 64 | } |
64 | 65 |
|
65 | 66 | pub fn to_bytes(&self) -> [u8; 32] { |
66 | | - use ark_ff::ToBytes; |
67 | | - let mut bytes = std::io::Cursor::new([0u8; 32]); |
68 | | - self.0 .0.write(&mut bytes).unwrap(); // Never fail, there is 32 bytes |
69 | | - bytes.into_inner() |
| 67 | + let mut bytes = Vec::with_capacity(32); |
| 68 | + self.0.serialize_uncompressed(&mut bytes).unwrap(); // Never fail, there is 32 bytes |
| 69 | + bytes.try_into().unwrap() |
70 | 70 | } |
71 | 71 |
|
72 | 72 | pub fn from_bytes(bytes: [u8; 32]) -> Self { |
73 | | - use ark_ff::FromBytes; |
74 | | - let value = FromBytes::read(&bytes[..]).expect("Don't fail"); |
75 | | - Self(BigInteger256::new(value)) // Never fail, we read from 32 bytes |
| 73 | + let value = BigInteger256::deserialize_uncompressed(&bytes[..]).expect("Don't fail"); |
| 74 | + Self(value) // Never fail, we read from 32 bytes |
76 | 75 | } |
77 | 76 |
|
78 | 77 | pub fn from_decimal(s: &str) -> Result<Self, InvalidDecimalNumber> { |
@@ -211,17 +210,15 @@ impl binprot::BinProtRead for BigInt { |
211 | 210 | where |
212 | 211 | Self: Sized, |
213 | 212 | { |
214 | | - use ark_ff::FromBytes; |
215 | | - let value = FromBytes::read(r)?; |
216 | | - Ok(Self(BigInteger256::new(value))) |
| 213 | + let mut bytes = [0u8; 32]; |
| 214 | + r.read_exact(&mut bytes)?; |
| 215 | + Ok(Self::from_bytes(bytes)) |
217 | 216 | } |
218 | 217 | } |
219 | 218 |
|
220 | 219 | impl binprot::BinProtWrite for BigInt { |
221 | 220 | fn binprot_write<W: std::io::Write>(&self, w: &mut W) -> std::io::Result<()> { |
222 | | - use ark_ff::ToBytes; |
223 | | - let Self(biginteger) = self; |
224 | | - biginteger.0.write(w) |
| 221 | + w.write_all(&self.to_bytes()) |
225 | 222 | } |
226 | 223 | } |
227 | 224 |
|
|
0 commit comments