Skip to content

Commit

Permalink
Use read_exact
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Feb 4, 2021
1 parent 8504da9 commit a9b2ddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions algorithms/src/snark/gm17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ impl<E: PairingEngine> Proof<E> {

/// Deserialize a proof from compressed or uncompressed bytes.
pub fn read<R: Read>(mut reader: R) -> IoResult<Self> {
// Construct the compressed reader
// Construct the compressed reader.
let compressed_proof_size = Self::compressed_proof_size()?;
let mut compressed_reader = vec![0u8; compressed_proof_size];
reader.read(&mut compressed_reader)?;
reader.read_exact(&mut compressed_reader)?;
let duplicate_compressed_reader = compressed_reader.clone();

// Attempt to read the compressed proof.
Expand All @@ -141,7 +141,7 @@ impl<E: PairingEngine> Proof<E> {
// Construct the uncompressed reader.
let uncompressed_proof_size = Self::uncompressed_proof_size()?;
let mut uncompressed_reader = vec![0u8; uncompressed_proof_size - compressed_proof_size];
reader.read(&mut uncompressed_reader)?;
reader.read_exact(&mut uncompressed_reader)?;
uncompressed_reader = [duplicate_compressed_reader, uncompressed_reader].concat();

// Attempt to read the uncompressed proof.
Expand Down
6 changes: 3 additions & 3 deletions algorithms/src/snark/groth16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ impl<E: PairingEngine> Proof<E> {

/// Deserialize a proof from compressed or uncompressed bytes.
pub fn read<R: Read>(mut reader: R) -> IoResult<Self> {
// Construct the compressed reader
// Construct the compressed reader.
let compressed_proof_size = Self::compressed_proof_size()?;
let mut compressed_reader = vec![0u8; compressed_proof_size];
reader.read(&mut compressed_reader)?;
reader.read_exact(&mut compressed_reader)?;
let duplicate_compressed_reader = compressed_reader.clone();

// Attempt to read the compressed proof.
Expand All @@ -145,7 +145,7 @@ impl<E: PairingEngine> Proof<E> {
// Construct the uncompressed reader.
let uncompressed_proof_size = Self::uncompressed_proof_size()?;
let mut uncompressed_reader = vec![0u8; uncompressed_proof_size - compressed_proof_size];
reader.read(&mut uncompressed_reader)?;
reader.read_exact(&mut uncompressed_reader)?;
uncompressed_reader = [duplicate_compressed_reader, uncompressed_reader].concat();

// Attempt to read the uncompressed proof.
Expand Down

0 comments on commit a9b2ddc

Please sign in to comment.