From 25a15e267ca53abc526e3ff6f6aa67c48d942225 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Thu, 3 Aug 2023 13:32:40 -0700 Subject: [PATCH] simplify bitset updates Signed-off-by: Andrew Whitehead --- src/data_types/rev_status_list.rs | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/data_types/rev_status_list.rs b/src/data_types/rev_status_list.rs index cae1525e..c1376341 100644 --- a/src/data_types/rev_status_list.rs +++ b/src/data_types/rev_status_list.rs @@ -89,30 +89,35 @@ impl RevocationStatusList { if let Some(reg) = registry { self.registry = Some(reg.into()); } + let slots_count = self.revocation_list.len(); if let Some(issued) = issued { + if let Some(max_idx) = issued.last().copied() { + if max_idx as usize >= slots_count { + return Err(Error::from_msg( + crate::ErrorKind::Unexpected, + "Update Revocation List Index Out of Range", + )); + } + } // issued credentials are assigned `false` // i.e. NOT revoked for i in issued { - let mut bit = self.revocation_list.get_mut(i as usize).ok_or_else(|| { - Error::from_msg( - crate::ErrorKind::Unexpected, - "Update Revocation List Index Out of Range", - ) - })?; - *bit = false; + self.revocation_list.set(i as usize, false); } } if let Some(revoked) = revoked { + if let Some(max_idx) = revoked.last().copied() { + if max_idx as usize >= slots_count { + return Err(Error::from_msg( + crate::ErrorKind::Unexpected, + "Update Revocation List Index Out of Range", + )); + } + } // revoked credentials are assigned `true` // i.e. IS revoked for i in revoked { - let mut bit = self.revocation_list.get_mut(i as usize).ok_or_else(|| { - Error::from_msg( - crate::ErrorKind::Unexpected, - "Update Revocation List Index Out of Range", - ) - })?; - *bit = true; + self.revocation_list.set(i as usize, true); } } // only update if input is Some