-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let the alg decide if it wants to perform on a give frame. This required giving it the VCDU header to make decisions. I also added an Integrity::Skipped state.
- Loading branch information
Showing
9 changed files
with
95 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
use super::IntegrityAlgorithm; | ||
use super::{Integrity, IntegrityAlgorithm}; | ||
use crate::{ | ||
error::{Error, Result}, | ||
framing::VCDUHeader, | ||
}; | ||
|
||
pub struct DefaultCrc32 { | ||
/// Offset to the start of the crc checksum bytes | ||
offset: usize, | ||
size: usize, | ||
alg: crc::Crc<u32>, | ||
} | ||
|
||
impl DefaultCrc32 { | ||
const CRC_SIZE: usize = 4; | ||
pub fn new(offset: usize) -> Self { | ||
Self { offset } | ||
Self { | ||
offset, | ||
size: offset + Self::CRC_SIZE, | ||
alg: crc::Crc::<u32>::new(&crc::CRC_32_ISO_HDLC), | ||
} | ||
} | ||
} | ||
|
||
impl IntegrityAlgorithm for DefaultCrc32 { | ||
fn remove_parity<'a>(&self, _cadu_dat: &'a [u8]) -> &'a [u8] { | ||
todo!(); | ||
} | ||
fn perform(&self, _cadu_dat: &[u8]) -> super::Result<(super::Integrity, Vec<u8>)> { | ||
todo!(); | ||
fn perform(&self, header: &VCDUHeader, cadu_dat: &[u8]) -> Result<(Integrity, Vec<u8>)> { | ||
if cadu_dat.len() < self.size { | ||
return Err(Error::NotEnoughData { | ||
got: cadu_dat.len(), | ||
wanted: self.size, | ||
}); | ||
} | ||
if header.vcid == VCDUHeader::FILL { | ||
return Ok((Integrity::Skipped, cadu_dat.to_vec())); | ||
} | ||
let dat = &cadu_dat[self.offset..self.offset + Self::CRC_SIZE]; | ||
let expected = u32::from_be_bytes([dat[0], dat[1], dat[2], dat[3]]); | ||
if expected != self.alg.checksum(cadu_dat) { | ||
return Ok((Integrity::NoErrors, cadu_dat.to_vec())); | ||
} | ||
Ok((Integrity::HasErrors, cadu_dat.to_vec())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters