[xmpp] no panic!

This commit is contained in:
JustTestingV 2024-01-20 20:12:40 +03:00
parent 77d175ccd9
commit 798b27ccb2
4 changed files with 7 additions and 4 deletions

1
Cargo.lock generated
View File

@ -1376,6 +1376,7 @@ dependencies = [
"anyhow", "anyhow",
"assert_matches", "assert_matches",
"derive_more", "derive_more",
"lavina-core",
"lazy_static", "lazy_static",
"quick-xml", "quick-xml",
"regex", "regex",

View File

@ -83,7 +83,7 @@ pub async fn launch(
let key = match read_one(&mut SyncBufReader::new(File::open(config.key)?))? { let key = match read_one(&mut SyncBufReader::new(File::open(config.key)?))? {
Some(PemItem::ECKey(k) | PemItem::PKCS8Key(k) | PemItem::RSAKey(k)) => PrivateKey(k), Some(PemItem::ECKey(k) | PemItem::PKCS8Key(k) | PemItem::RSAKey(k)) => PrivateKey(k),
_ => panic!("no keys in file"), _ => return Err(fail("no keys in file")),
}; };
let loaded_config = Arc::new(LoadedConfig { let loaded_config = Arc::new(LoadedConfig {

View File

@ -4,6 +4,7 @@ edition = "2021"
version.workspace = true version.workspace = true
[dependencies] [dependencies]
lavina-core.workspace = true
quick-xml.workspace = true quick-xml.workspace = true
lazy_static.workspace = true lazy_static.workspace = true
regex.workspace = true regex.workspace = true

View File

@ -3,6 +3,7 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
use quick_xml::name::{Namespace, QName, ResolveResult}; use quick_xml::name::{Namespace, QName, ResolveResult};
use quick_xml::{NsReader, Writer}; use quick_xml::{NsReader, Writer};
use tokio::io::{AsyncBufRead, AsyncWrite}; use tokio::io::{AsyncBufRead, AsyncWrite};
use lavina_core::prelude::fail;
use super::skip_text; use super::skip_text;
@ -28,10 +29,10 @@ impl ClientStreamStart {
if let Event::Start(e) = incoming { if let Event::Start(e) = incoming {
let (ns, local) = reader.resolve_element(e.name()); let (ns, local) = reader.resolve_element(e.name());
if ns != ResolveResult::Bound(Namespace(XMLNS.as_bytes())) { if ns != ResolveResult::Bound(Namespace(XMLNS.as_bytes())) {
return Err(panic!()); return Err(fail("Invalid namespace for stream element"));
} }
if local.into_inner() != b"stream" { if local.into_inner() != b"stream" {
return Err(panic!()); return Err(fail("Invalid local name for stream element"));
} }
let mut to = None; let mut to = None;
let mut lang = None; let mut lang = None;
@ -64,7 +65,7 @@ impl ClientStreamStart {
version: version.unwrap(), version: version.unwrap(),
}) })
} else { } else {
Err(panic!()) Err(fail("Incoming message does not belong XML Start Event"))
} }
} }
} }