From 1577d79c735a434f2aed86beffb71c41cd1ea354 Mon Sep 17 00:00:00 2001 From: bwty Date: Thu, 5 Jan 2023 17:09:43 +0700 Subject: [PATCH] feat: rev list serde and issuance type enhancements Signed-off-by: bwty --- anoncreds/src/data_types/anoncreds/rev_reg.rs | 10 +++++----- anoncreds/src/data_types/anoncreds/rev_reg_def.rs | 11 +++++++++++ anoncreds/src/services/prover.rs | 11 ++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/anoncreds/src/data_types/anoncreds/rev_reg.rs b/anoncreds/src/data_types/anoncreds/rev_reg.rs index 65c21ab2..c4ff356f 100644 --- a/anoncreds/src/data_types/anoncreds/rev_reg.rs +++ b/anoncreds/src/data_types/anoncreds/rev_reg.rs @@ -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() @@ -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(self, mut v: S) -> Result diff --git a/anoncreds/src/data_types/anoncreds/rev_reg_def.rs b/anoncreds/src/data_types/anoncreds/rev_reg_def.rs index 7a935aac..cfa19d93 100644 --- a/anoncreds/src/data_types/anoncreds/rev_reg_def.rs +++ b/anoncreds/src/data_types/anoncreds/rev_reg_def.rs @@ -34,6 +34,17 @@ impl FromStr for IssuanceType { } } +impl From 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 diff --git a/anoncreds/src/services/prover.rs b/anoncreds/src/services/prover.rs index 2de6a9fc..ff0e0344 100644 --- a/anoncreds/src/services/prover.rs +++ b/anoncreds/src/services/prover.rs @@ -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(),