Skip to content

Commit

Permalink
capsules: test: sha256 implement CapsuleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Mar 4, 2024
1 parent bc694f8 commit e5f4ced
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion capsules/extra/src/test/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use core::cell::Cell;
use core::cmp;

use crate::sha256::Sha256Software;
use capsules_core::test::capsule_test::{CapsuleTest, CapsuleTestClient};
use kernel::debug;
use kernel::hil::digest;
use kernel::hil::digest::{Digest, DigestData, DigestVerify};
use kernel::utilities::cells::TakeCell;
use kernel::utilities::cells::{OptionalCell, TakeCell};
use kernel::utilities::leasable_buffer::SubSlice;
use kernel::utilities::leasable_buffer::SubSliceMut;
use kernel::ErrorCode;
Expand All @@ -25,6 +26,7 @@ pub struct TestSha256 {
hash: TakeCell<'static, [u8; 32]>, // The supplied hash
position: Cell<usize>, // Keep track of position in data
correct: Cell<bool>, // Whether supplied hash is correct
client: OptionalCell<&'static dyn CapsuleTestClient>,
}

// We add data in chunks of 12 bytes to ensure that the underlying
Expand All @@ -45,6 +47,7 @@ impl TestSha256 {
hash: TakeCell::new(hash),
position: Cell::new(0),
correct: Cell::new(correct),
client: OptionalCell::empty(),
}
}

Expand Down Expand Up @@ -119,6 +122,10 @@ impl digest::ClientVerify<32> for TestSha256 {
self.correct.get(),
success
);
} else {
self.client.map(|client| {
client.done(Ok(()));
});
}
}
Err(e) => {
Expand All @@ -131,3 +138,9 @@ impl digest::ClientVerify<32> for TestSha256 {
impl digest::ClientHash<32> for TestSha256 {
fn hash_done(&self, _result: Result<(), ErrorCode>, _digest: &'static mut [u8; 32]) {}
}

impl CapsuleTest for TestSha256 {
fn set_client(&self, client: &'static dyn CapsuleTestClient) {
self.client.set(client);
}
}

0 comments on commit e5f4ced

Please sign in to comment.