Skip to content

Commit

Permalink
make Checksum a boxed array
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Jan 2, 2024
1 parent 59fb1cd commit 8bd14b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/encoded_replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use sha2::{Digest, Sha256};

use crate::*;

pub type Checksum = Vec<u8>;
/// We use this instead of a `Vec<u8>` because it's 1/3 the size on the stack.
pub type Checksum = Box<[u8; 32]>;

/// A [`Replica`] encoded into a compact binary format suitable for
/// transmission over the network.
Expand Down Expand Up @@ -88,5 +89,6 @@ pub enum DecodeError {

#[inline]
pub fn checksum(bytes: &[u8]) -> Checksum {
Sha256::digest(bytes)[..].to_vec()
let checksum = Sha256::digest(bytes);
Box::new(*checksum.as_ref())
}

0 comments on commit 8bd14b2

Please sign in to comment.