add more graceful handling of erase inconsistencies

This commit is contained in:
bunnie 2026-01-19 00:18:13 +08:00
parent 763a2c290d
commit 18a58c7d18

View file

@ -352,15 +352,23 @@ pub fn erase_secrets(csprng: &mut Option<&mut Csprng>) -> Result<(), String> {
match rw_perms {
RwPerms::ReadWrite | RwPerms::WriteOnly => {
// only clear ACL if it isn't already cleared
if slot_mgr.get_acl(slot).unwrap().raw_u32() != 0 {
if slot_mgr
.get_acl(slot)
.unwrap_or(AccessSettings::Data(DataSlotAccess::new_with_raw_value(0xFFFF_FFFF)))
.raw_u32()
!= 0
{
// clear the ACL so we can operate on the data
slot_mgr
.set_acl(
&mut rram,
slot,
&AccessSettings::Data(DataSlotAccess::new_with_raw_value(0)),
)
.expect("couldn't reset ACL");
match slot_mgr.set_acl(
&mut rram,
slot,
&AccessSettings::Data(DataSlotAccess::new_with_raw_value(0)),
) {
Ok(_) => (),
Err(e) => {
crate::println!("Couldn't erase ACL: {:?}", e);
}
}
}
let bytes = unsafe { slot_mgr.read_data_slot(data_index) };
if bytes.iter().all(|&b| b == 0) {