-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revocation registry cleanups #233
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,9 @@ | ||
use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor}; | ||
use serde::Serialize; | ||
|
||
use crate::cl::{Accumulator, RevocationRegistry as CryptoRevocationRegistry}; | ||
use crate::{impl_anoncreds_object_identifier, Error}; | ||
use crate::cl::RevocationRegistry as CryptoRevocationRegistry; | ||
use crate::impl_anoncreds_object_identifier; | ||
|
||
impl_anoncreds_object_identifier!(RevocationRegistryId); | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct RevocationRegistry { | ||
pub value: CryptoRevocationRegistry, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Serialize)] | ||
pub struct CLSignaturesRevocationRegistry(Accumulator); | ||
|
||
impl CLSignaturesRevocationRegistry { | ||
pub fn empty() -> Result<Self, Error> { | ||
let accum = Accumulator::new_inf()?; | ||
Ok(Self(accum)) | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for CLSignaturesRevocationRegistry { | ||
type Error = Error; | ||
|
||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
let accum = Accumulator::from_string(value)?; | ||
Ok(Self(accum)) | ||
} | ||
} | ||
|
||
impl From<CryptoRevocationRegistry> for CLSignaturesRevocationRegistry { | ||
fn from(value: CryptoRevocationRegistry) -> Self { | ||
Self(value.accum) | ||
} | ||
} | ||
|
||
impl From<CLSignaturesRevocationRegistry> for CryptoRevocationRegistry { | ||
fn from(value: CLSignaturesRevocationRegistry) -> Self { | ||
Self { accum: value.0 } | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for CLSignaturesRevocationRegistry { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
struct CLSignaturesRevocationRegistryVisitor; | ||
|
||
impl<'de> Visitor<'de> for CLSignaturesRevocationRegistryVisitor { | ||
type Value = CLSignaturesRevocationRegistry; | ||
|
||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(formatter, "string or map") | ||
} | ||
|
||
fn visit_str<E: serde::de::Error>( | ||
self, | ||
value: &str, | ||
) -> Result<CLSignaturesRevocationRegistry, E> { | ||
let accum = Accumulator::from_string(value).map_err(de::Error::custom)?; | ||
Ok(CLSignaturesRevocationRegistry(accum)) | ||
} | ||
|
||
fn visit_map<V>(self, mut map: V) -> Result<CLSignaturesRevocationRegistry, V::Error> | ||
where | ||
V: MapAccess<'de>, | ||
{ | ||
let mut accum = None; | ||
while let Some(key) = map.next_key()? { | ||
match key { | ||
"currentAccumulator " | "accum" => { | ||
if accum.is_some() { | ||
return Err(de::Error::duplicate_field( | ||
"(accum|currentAccumulator)", | ||
)); | ||
} | ||
accum = Some(map.next_value()?); | ||
} | ||
_ => (), | ||
} | ||
} | ||
let accum: Accumulator = | ||
accum.ok_or_else(|| de::Error::missing_field("(accum|currentAccumulator)"))?; | ||
Ok(CLSignaturesRevocationRegistry(accum)) | ||
} | ||
} | ||
deserializer.deserialize_any(CLSignaturesRevocationRegistryVisitor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an overkill. Serialization doesn't seem to require anything custom, so the attribute could instead be
deserialize_with
. But then the custom deserialization seems to only want to achieve having multiple names for the field, which can also be done with#[serde(alias = "currentAccumulator"]
.Depending on which should be the serialization name for the field, you might want to use
#[serde(rename = "currentAccumulator", alias = "accum"]
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test
json_rev_list_can_be_deserialized
might also need to be expanded to make sure that the test vector, which includescurrentAccumulator
checks thatdes.accum.is_some()
. asskip_serializing_if="Option::is_none"
is set, it will silently fail if it can not interpretcurrentAccumulator
correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't trying to change the current deserialization, but it's pretty strange. It accepts values like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably because the visitor implements the
visit_map
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do we think that's a mistake and it's just meant to support both currentAccumulator and accum as the field name? In that case it wouldn't need any custom deserialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fairly sure that it is a mistake. It was a custom implementation because we could not change it as it was a private field within Ursa (it has been a while so there might be more to it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... The changes are introduced in this PR, so I was honestly expecting you to know the answer to that 😅 . To me it just seemed weird so I pointed it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved the deserialization code around and changed it to an Accumulator value, the old implementation had the visit_map method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to just deserialize from a string, which is the format the tests use. I'm a little surprised the bitvec serialization is a list instead of hex bytes or something.