Let update_len be usize for now

This commit is contained in:
Rasmus Melchior Jacobsen 2023-04-05 06:57:56 +02:00
parent 043b3072c4
commit d8e2f82569
2 changed files with 10 additions and 12 deletions

View File

@ -119,13 +119,11 @@ impl FirmwareUpdater {
_state_and_dfu_flash: &mut F,
_public_key: &[u8],
_signature: &[u8],
_update_len: u32,
_update_len: usize,
_aligned: &mut [u8],
) -> Result<(), FirmwareUpdaterError> {
let _read_size = _aligned.len();
assert_eq!(_aligned.len(), F::WRITE_SIZE);
assert!(_update_len <= self.dfu.len() as u32);
assert!(_update_len <= self.dfu.len());
#[cfg(feature = "ed25519-dalek")]
{
@ -182,10 +180,11 @@ impl FirmwareUpdater {
pub async fn hash<F: AsyncNorFlash, D: Digest>(
&mut self,
dfu_flash: &mut F,
update_len: u32,
update_len: usize,
chunk_buf: &mut [u8],
output: &mut [u8],
) -> Result<(), FirmwareUpdaterError> {
let update_len = update_len as u32;
let mut digest = D::new();
for offset in (0..update_len).step_by(chunk_buf.len()) {
self.dfu.read(dfu_flash, offset, chunk_buf).await?;
@ -341,13 +340,11 @@ impl FirmwareUpdater {
_state_and_dfu_flash: &mut F,
_public_key: &[u8],
_signature: &[u8],
_update_len: u32,
_update_len: usize,
_aligned: &mut [u8],
) -> Result<(), FirmwareUpdaterError> {
let _read_size = _aligned.len();
assert_eq!(_aligned.len(), F::WRITE_SIZE);
assert!(_update_len <= self.dfu.len() as u32);
assert!(_update_len <= self.dfu.len());
#[cfg(feature = "ed25519-dalek")]
{
@ -402,10 +399,11 @@ impl FirmwareUpdater {
pub fn hash_blocking<F: NorFlash, D: Digest>(
&mut self,
dfu_flash: &mut F,
update_len: u32,
update_len: usize,
chunk_buf: &mut [u8],
output: &mut [u8],
) -> Result<(), FirmwareUpdaterError> {
let update_len = update_len as u32;
let mut digest = D::new();
for offset in (0..update_len).step_by(chunk_buf.len()) {
self.dfu.read_blocking(dfu_flash, offset, chunk_buf)?;
@ -536,7 +534,7 @@ mod tests {
block_on(updater.write_firmware(0, to_write.as_slice(), &mut flash)).unwrap();
let mut chunk_buf = [0; 2];
let mut hash = [0; 20];
block_on(updater.hash::<_, Sha1>(&mut flash, update.len() as u32, &mut chunk_buf, &mut hash)).unwrap();
block_on(updater.hash::<_, Sha1>(&mut flash, update.len(), &mut chunk_buf, &mut hash)).unwrap();
assert_eq!(Sha1::digest(update).as_slice(), hash);
}

View File

@ -281,7 +281,7 @@ mod tests {
&mut flash,
&public_key.to_bytes(),
&signature.to_bytes(),
firmware_len as u32,
firmware_len,
&mut aligned,
))
.is_ok());