2023-06-19 23:54:08 +02:00
|
|
|
|
// Copyright (c) 2017, 2018 lumi <lumi@pew.im>
|
|
|
|
|
|
// Copyright (c) 2017, 2018, 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
|
|
// Copyright (c) 2017, 2018, 2019 Maxime “pep” Buquet <pep@bouah.net>
|
|
|
|
|
|
// Copyright (c) 2017, 2018 Astro <astro@spaceboyz.net>
|
|
|
|
|
|
// Copyright (c) 2017 Bastien Orivel <eijebong@bananium.fr>
|
|
|
|
|
|
//
|
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
2024-04-25 21:18:39 +02:00
|
|
|
|
use core::fmt;
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
|
|
|
|
|
/// An error that signifies that a `Jid` cannot be parsed from a string.
|
2023-06-20 12:49:20 +02:00
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2023-06-20 12:51:37 +02:00
|
|
|
|
pub enum Error {
|
2023-06-20 17:58:16 +02:00
|
|
|
|
/// Happens when the node is empty, that is the string starts with a @.
|
|
|
|
|
|
NodeEmpty,
|
|
|
|
|
|
|
2023-06-19 23:54:08 +02:00
|
|
|
|
/// Happens when the resource is empty, that is the string ends with a /.
|
2023-06-20 17:58:16 +02:00
|
|
|
|
ResourceEmpty,
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
2023-06-20 12:49:20 +02:00
|
|
|
|
/// Happens when the localpart is longer than 1023 bytes.
|
|
|
|
|
|
NodeTooLong,
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
2023-06-20 12:49:20 +02:00
|
|
|
|
/// Happens when the resource is longer than 1023 bytes.
|
|
|
|
|
|
ResourceTooLong,
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
2023-06-20 12:49:20 +02:00
|
|
|
|
/// Happens when the localpart is invalid according to nodeprep.
|
|
|
|
|
|
NodePrep,
|
|
|
|
|
|
|
|
|
|
|
|
/// Happens when the domain is invalid according to nameprep.
|
|
|
|
|
|
NamePrep,
|
|
|
|
|
|
|
|
|
|
|
|
/// Happens when the resource is invalid according to resourceprep.
|
|
|
|
|
|
ResourcePrep,
|
|
|
|
|
|
|
2023-06-20 17:58:16 +02:00
|
|
|
|
/// Happens when there is no resource, that is string contains no /.
|
|
|
|
|
|
ResourceMissingInFullJid,
|
|
|
|
|
|
|
2023-06-20 12:49:20 +02:00
|
|
|
|
/// Happens when parsing a bare JID and there is a resource.
|
|
|
|
|
|
ResourceInBareJid,
|
2025-02-04 18:11:42 +01:00
|
|
|
|
|
|
|
|
|
|
/// Happens when parsing a JID which has two @ before the resource.
|
|
|
|
|
|
TooManyAts,
|
2025-02-05 18:26:48 +01:00
|
|
|
|
|
|
|
|
|
|
/// Happens when the domain is invalid according to idna.
|
|
|
|
|
|
Idna,
|
2023-06-20 12:49:20 +02:00
|
|
|
|
}
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
2024-11-13 10:50:25 +01:00
|
|
|
|
impl core::error::Error for Error {}
|
2023-06-19 23:54:08 +02:00
|
|
|
|
|
2023-06-20 12:51:37 +02:00
|
|
|
|
impl fmt::Display for Error {
|
2023-06-19 23:54:08 +02:00
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2023-06-20 12:49:20 +02:00
|
|
|
|
fmt.write_str(match self {
|
2023-06-20 17:58:16 +02:00
|
|
|
|
Error::NodeEmpty => "nodepart empty despite the presence of a @",
|
|
|
|
|
|
Error::ResourceEmpty => "resource empty despite the presence of a /",
|
2023-06-20 12:51:37 +02:00
|
|
|
|
Error::NodeTooLong => "localpart longer than 1023 bytes",
|
|
|
|
|
|
Error::ResourceTooLong => "resource longer than 1023 bytes",
|
|
|
|
|
|
Error::NodePrep => "localpart doesn’t pass nodeprep validation",
|
|
|
|
|
|
Error::NamePrep => "domain doesn’t pass nameprep validation",
|
|
|
|
|
|
Error::ResourcePrep => "resource doesn’t pass resourceprep validation",
|
2023-06-20 17:58:16 +02:00
|
|
|
|
Error::ResourceMissingInFullJid => "no resource found in this full JID",
|
2023-06-20 12:51:37 +02:00
|
|
|
|
Error::ResourceInBareJid => "resource found while parsing a bare JID",
|
2025-02-04 18:11:42 +01:00
|
|
|
|
Error::TooManyAts => "second @ found before parsing the resource",
|
2025-02-05 18:26:48 +01:00
|
|
|
|
Error::Idna => "domain doesn’t pass idna validation",
|
2023-06-20 12:49:20 +02:00
|
|
|
|
})
|
2023-06-19 23:54:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|