Skip to content

Commit

Permalink
feat: rev list serde and issuance type enhancements
Browse files Browse the repository at this point in the history
Signed-off-by: bwty <[email protected]>
  • Loading branch information
whalelephant committed Jan 6, 2023
1 parent 0263802 commit 1577d79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions anoncreds/src/data_types/anoncreds/rev_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ pub mod serde_revocation_list {
{
let mut seq = s.serialize_seq(Some(state.len()))?;
for element in state {
let e = match *element.as_ref() {
true => 1,
false => 0,
};
let e = *element as i32;
seq.serialize_element(&e)?;
}
seq.end()
Expand All @@ -125,7 +122,10 @@ pub mod serde_revocation_list {
type Value = bitvec::vec::BitVec;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a seq containing revoation state, i.e. [1, 0, 1]")
write!(
formatter,
"a seq containing revoation state, i.e. [1, 0, 1]"
)
}

fn visit_seq<S>(self, mut v: S) -> Result<Self::Value, S::Error>
Expand Down
11 changes: 11 additions & 0 deletions anoncreds/src/data_types/anoncreds/rev_reg_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ impl FromStr for IssuanceType {
}
}

impl From<IssuanceType> for usize {
fn from(value: IssuanceType) -> usize {
match value {
// Credentials are by default revoked
IssuanceType::ISSUANCE_ON_DEMAND => 1,
// Credentials are by default not revoked
IssuanceType::ISSUANCE_BY_DEFAULT => 0,
}
}
}

impl IssuanceType {
pub fn to_bool(&self) -> bool {
*self == IssuanceType::ISSUANCE_BY_DEFAULT
Expand Down
11 changes: 2 additions & 9 deletions anoncreds/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,8 @@ pub fn create_or_update_revocation_state(
} else {
let list_size = usize::try_from(revoc_reg_def.value.max_cred_num)
.map_err(|e| Error::from_msg(crate::ErrorKind::InvalidState, e.to_string()))?;
let list = match revoc_reg_def.value.issuance_type {
// All cred are revoked by default
IssuanceType::ISSUANCE_ON_DEMAND => {
bitvec![1; list_size]
}
IssuanceType::ISSUANCE_BY_DEFAULT => {
bitvec![0; list_size]
}
};
let bit: usize = revoc_reg_def.value.issuance_type.into();
let list = bitvec![bit; list_size];
_create_index_deltas(
rev_reg_list.state_owned().bitxor(list),
rev_reg_list.state(),
Expand Down

0 comments on commit 1577d79

Please sign in to comment.