Skip to content

Commit

Permalink
Gate properly
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Jan 3, 2025
1 parent e455541 commit 625e079
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/crc32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(all(target_arch = "aarch64", target_feature = "crc"))]
pub fn compute_crc_aarch64<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 {
pub fn compute_crc<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 {
use std::arch::aarch64::__crc32b;

let mut crc = 0xffff_ffff;
Expand All @@ -15,7 +15,8 @@ pub fn compute_crc_aarch64<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u3
!crc
}

pub fn compute_crc_fast<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 {
#[cfg(not(all(target_arch = "aarch64", target_feature = "crc")))]
pub fn compute_crc<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 {
use crc32fast::Hasher;

let mut hx = Hasher::new();
Expand Down
11 changes: 2 additions & 9 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{collections::BTreeMap, io::Read};
use anyhow::{bail, ensure, Result};
use flate2::read::ZlibDecoder;

#[cfg(all(target_arch = "aarch64", target_feature = "crc"))]
use crate::crc32::compute_crc_aarch64;

use crate::{crc32::compute_crc_fast, Chunk, ColorType, Filter, ImageHeader, Png};
use crate::{crc32::compute_crc, Chunk, ColorType, Filter, ImageHeader, Png};

#[derive(Debug)]
pub struct Decoder<'a> {
Expand Down Expand Up @@ -195,11 +192,7 @@ impl<'a> Decoder<'a> {
}

fn validate_crc(&self, chunk_type: &'a [u8], chunk_data: &'a [u8], expected_crc: u32) -> bool {
let computed_crc = if cfg!(all(target_arch = "aarch64", target_feature = "crc")) {
compute_crc_aarch64(chunk_type, chunk_data)
} else {
compute_crc_fast(chunk_type, chunk_data)
};
let computed_crc = compute_crc(chunk_type, chunk_data);

computed_crc == expected_crc
}
Expand Down

0 comments on commit 625e079

Please sign in to comment.