xmpp-parsers: Convert cert_management to xso

This introduces a breaking change by moving from a bool to an
Option<NoCertManagement>, which will be reverted eventually once we add
support for #[xml(flag)] types of children.
This commit is contained in:
Emmanuel Gil Peyrot 2024-08-08 16:57:46 +02:00 committed by Jonas Schäfer
commit d4f6812386
2 changed files with 49 additions and 31 deletions

View file

@ -15,6 +15,10 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
then included in `Action`. Also `Action::Erase::num` is now a wrapper then included in `Action`. Also `Action::Erase::num` is now a wrapper
type around u32, which lets us implement a custom Default on it. type around u32, which lets us implement a custom Default on it.
(!416) (!416)
- The cert_management module is now using `Option` instead of `bool` to
check whether a child element is present or not, as this is currently
implemented in xso. We might revert that change if we implement flag
metas in xso before the next release.
* New parsers/serialisers: * New parsers/serialisers:
- Stream Features (RFC 6120) (!400) - Stream Features (RFC 6120) (!400)
- Extensible SASL Profile (XEP-0388) - Extensible SASL Profile (XEP-0388)

View file

@ -25,20 +25,28 @@ pub struct Cert {
pub data: Vec<u8>, pub data: Vec<u8>,
} }
generate_element!( /// Temporary zero-sized struct for when the no-cert-management element is present.
/// For the client to upload an X.509 certificate. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
Append, "append", SASL_CERT, #[xml(namespace = ns::SASL_CERT, name = "no-cert-management")]
children: [ pub struct NoCertManagement;
/// For the client to upload an X.509 certificate.
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::SASL_CERT, name = "append")]
pub struct Append {
/// The name of this certificate. /// The name of this certificate.
name: Required<Name> = ("name", SASL_CERT) => Name, #[xml(child)]
pub name: Name,
/// The X.509 certificate to set. /// The X.509 certificate to set.
cert: Required<Cert> = ("x509cert", SASL_CERT) => Cert, #[xml(child)]
pub cert: Cert,
/// This client is forbidden from managing certificates. /// This client is forbidden from managing certificates.
no_cert_management: Present<_> = ("no-cert-management", SASL_CERT) => bool // TODO: replace with `#[xml(flag)]` once we have it.
] #[xml(child(default))]
); pub no_cert_management: Option<NoCertManagement>,
}
impl IqSetPayload for Append {} impl IqSetPayload for Append {}
@ -65,23 +73,27 @@ pub struct Users {
pub resources: Vec<Resource>, pub resources: Vec<Resource>,
} }
generate_element!( /// An X.509 certificate being set for this user.
/// An X.509 certificate being set for this user. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
Item, "item", SASL_CERT, #[xml(namespace = ns::SASL_CERT, name = "item")]
children: [ pub struct Item {
/// The name of this certificate. /// The name of this certificate.
name: Required<Name> = ("name", SASL_CERT) => Name, #[xml(child)]
pub name: Name,
/// The X.509 certificate to set. /// The X.509 certificate to set.
cert: Required<Cert> = ("x509cert", SASL_CERT) => Cert, #[xml(child)]
pub cert: Cert,
/// This client is forbidden from managing certificates. /// This client is forbidden from managing certificates.
no_cert_management: Present<_> = ("no-cert-management", SASL_CERT) => bool, #[xml(child(default))]
// TODO: replace with `#[xml(flag)]` once we have it.
pub no_cert_management: Option<NoCertManagement>,
/// List of resources currently using this certificate. /// List of resources currently using this certificate.
users: Option<Users> = ("users", SASL_CERT) => Users #[xml(child(default))]
] pub users: Option<Users>,
); }
/// Server answers with the current list of X.509 certificates. /// Server answers with the current list of X.509 certificates.
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
@ -126,6 +138,7 @@ mod tests {
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[test] #[test]
fn test_size() { fn test_size() {
assert_size!(NoCertManagement, 0);
assert_size!(Append, 28); assert_size!(Append, 28);
assert_size!(Disable, 12); assert_size!(Disable, 12);
assert_size!(Revoke, 12); assert_size!(Revoke, 12);
@ -140,6 +153,7 @@ mod tests {
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
#[test] #[test]
fn test_size() { fn test_size() {
assert_size!(NoCertManagement, 0);
assert_size!(Append, 56); assert_size!(Append, 56);
assert_size!(Disable, 24); assert_size!(Disable, 24);
assert_size!(Revoke, 24); assert_size!(Revoke, 24);
@ -211,7 +225,7 @@ mod tests {
cert: Cert { cert: Cert {
data: b"\0\0\0".to_vec(), data: b"\0\0\0".to_vec(),
}, },
no_cert_management: false, no_cert_management: None,
}; };
let elem: Element = append.into(); let elem: Element = append.into();
assert!(elem.is("append", ns::SASL_CERT)); assert!(elem.is("append", ns::SASL_CERT));
@ -237,7 +251,7 @@ mod tests {
cert: Cert { cert: Cert {
data: b"\0\0\0".to_vec(), data: b"\0\0\0".to_vec(),
}, },
no_cert_management: false, no_cert_management: None,
users: None, users: None,
}; };
@ -256,7 +270,7 @@ mod tests {
cert: Cert { cert: Cert {
data: b"\0\0\0".to_vec(), data: b"\0\0\0".to_vec(),
}, },
no_cert_management: false, no_cert_management: None,
}; };
let serialized: Element = append.into(); let serialized: Element = append.into();