-
Notifications
You must be signed in to change notification settings - Fork 11
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
Looks up for kid
and alg
also in unprotected header
#25
Conversation
Codecov Report
@@ Coverage Diff @@
## main #25 +/- ##
==========================================
+ Coverage 82.34% 82.36% +0.02%
==========================================
Files 10 10
Lines 1048 1072 +24
==========================================
+ Hits 863 883 +20
- Misses 185 189 +4
Continue to review full report at Codecov.
|
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.
You may squash the two commits in one while at it.
b4531ae
to
e268f09
Compare
src/dgc_cert.rs
Outdated
fn t_empty_if_null<'de, D>(deserializer: D) -> Result<Vec<Test>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let opt = Option::deserialize(deserializer)?; | ||
Ok(opt.unwrap_or_default()) | ||
} | ||
|
||
fn v_empty_if_null<'de, D>(deserializer: D) -> Result<Vec<Vaccination>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let opt = Option::deserialize(deserializer)?; | ||
Ok(opt.unwrap_or_default()) | ||
} | ||
|
||
fn r_empty_if_null<'de, D>(deserializer: D) -> Result<Vec<Recovery>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let opt = Option::deserialize(deserializer)?; | ||
Ok(opt.unwrap_or_default()) | ||
} | ||
|
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.
Note that I had to do this because there were 2 tests (originally skipped because of the "kid in unprotected header" problem) that have the following content encoded:
{
"r": null,
"t": null,
"v": [
// ...
],
}
Instead of having only one value set between r
, t
, or v
they set two of them to null
and the other to an appropriate array.
Solution based on serde-rs/serde#1098
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 have generalised this to one generic empty_if_null
function...
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.
FYI: https://docs.rs/serde_with/1.11.0/serde_with/
This can be pretty useful...
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.
Nice one. Is there any utility there that would do what we are doing here? I couldn't find one at first glance...
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.
In this case I am not sure. However, this a lifesaver to avoid skip_serialization_if(Option::is_none)
everywhere. For some of my projects I discovered this a bit too late... 😓
@lu-zero, this is now rebases with |
Note that with this PR we solve most of the broken test. We go from:
To:
So 30 new tests are now passing! 🎉 |
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 going to propose a commit (it would be a little bit a mess using diff changes), feel free to reject it if you find it out of scope. I noticed that some parts have been refactored but they could be improved a little bit.
This is the change I was talking about. Let me know what do you think about 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.
LGTM :)
I love the suggested changes @dodomorandi! Thanks. I actually contributed to ciborium adding the existing I'll try to fix the conflict, rebase and get this merged today 🤞 |
No worries, I'll do it because I caused the conflict 😁. I was just waiting for your feedback before performing a forced push.
I totally agree!! |
…late kid from certificates
Unfortunately `ciborium` misses some ergonomic features in order to keep things easy. I added an _extension trait_ to overcome this problem and I used it to keep code a little bit cleaner.
b4e22f3
to
672e19f
Compare
Fixes #1
kid
andalg
from unprotected header.header_unprotected
(not used anymore) and makesheader_protected_raw
andpayload_raw
private inCwt
(it felt like a leaking abstraction)Note: It is better to merge #23 first and then rebase this branch, so we can easily test against all the previously failing tests.DoneCC: @rez23 who was already looking at this!