Skip to content

Commit

Permalink
simplify bitset updates
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
  • Loading branch information
andrewwhitehead committed Aug 3, 2023
1 parent eaf465e commit 25a15e2
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/data_types/rev_status_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25a15e2

Please sign in to comment.