The AccountBuilder can now skip None Values#7
Conversation
By using an Serializer that takes care of the checks and transformations it converts the data into json for the authenticates_request method
|
I decided to write an own Serializer, because the normal serializer would consume the reference and the Type conversions would be better elsewhere |
There was a problem hiding this comment.
Pull Request Overview
This PR updates the AccountBuilder to skip serializing None values by implementing a custom Serialize trait, and refactors the build method to ensure a private key is generated if one is not provided.
- Implements custom Serialize for AccountBuilder to conditionally serialize fields
- Refactors build() to generate and cache a private key if absent
- Leverages serde_json::to_value for cleaner JSON payload generation
| obj.serialize_entry("onlyReturnExisting", &self.only_return_existing.clone())? | ||
| } | ||
| if let Some(eab) = self.eab_config.clone() { | ||
| let payload = serde_json::to_string(&Jwk::new(&self.private_key.clone().unwrap())).unwrap(); |
There was a problem hiding this comment.
Serializing the external account binding relies on unwrapping the private_key, which could panic if it is None. Consider handling the error more gracefully or ensuring that private_key is always set prior to serialization.
| let payload = serde_json::to_string(&Jwk::new(&self.private_key.clone().unwrap())).unwrap(); | |
| let private_key = match &self.private_key { | |
| Some(key) => key, | |
| None => { | |
| return Err(serde::ser::Error::custom("private_key is not set, cannot serialize externalAccountBinding")); | |
| } | |
| }; | |
| let payload = match serde_json::to_string(&Jwk::new(private_key)) { | |
| Ok(p) => p, | |
| Err(error) => { | |
| return Err(serde::ser::Error::custom(format!("Failed to serialize JWK: {}", error))); | |
| } | |
| }; |
|
Hi @stop5, thanks for the PR. Could you give a bit more context about why this is necessary? It's been a while since I read the ACME spec, is I wonder if |
|
The Biggest problem i had trying to do it with |
1b7190e to
ce7477a
Compare
|
to show the issue here is my code: https://gitea.sebastian-tobie.de/sebastian/racme |
|
Thanks for that context, but that page is a 404 for me. |
|
i forgot that the repo was created by push. Its now publicly available. |
By using an Serializer that takes care of the checks and transformations it converts the data into json for the authenticates_request method