jid: Validate domains against idna

The idna crate validates against UTS 46, which supports domains using
either IDNA2003 or IDNA2008.  This allows us to support both old and
new internationalized domain names.

This dependency isn’t a new one in the tree, as hickory-proto, url and
tokio-xmpp all were already depending on it.

There are a bunch of other checks that have to be performed, this is
inspired by slixmpp’s JID implementation.
This commit is contained in:
Emmanuel Gil Peyrot 2025-02-05 18:26:48 +01:00
commit 2a2f532c80
5 changed files with 95 additions and 28 deletions

View file

@ -49,6 +49,9 @@ pub enum Error {
/// Happens when parsing a JID which has two @ before the resource.
TooManyAts,
/// Happens when the domain is invalid according to idna.
Idna,
}
impl core::error::Error for Error {}
@ -68,6 +71,7 @@ impl fmt::Display for Error {
Error::ResourceMissingInFullJid => "no resource found in this full JID",
Error::ResourceInBareJid => "resource found while parsing a bare JID",
Error::TooManyAts => "second @ found before parsing the resource",
Error::Idna => "domain doesnt pass idna validation",
})
}
}