fix: Remove panic!() call

This commit is contained in:
Hocuri
2025-08-16 18:58:58 +02:00
parent f66f6f3e92
commit dc5237f530

View File

@@ -309,14 +309,14 @@ pub(crate) async fn send_handshake_message(
) -> Result<()> { ) -> Result<()> {
let mut msg = Message { let mut msg = Message {
viewtype: Viewtype::Text, viewtype: Viewtype::Text,
text: step.body_text(invite), text: step.body_text(invite)?,
hidden: true, hidden: true,
..Default::default() ..Default::default()
}; };
msg.param.set_cmd(SystemMessage::SecurejoinMessage); msg.param.set_cmd(SystemMessage::SecurejoinMessage);
// Sends the step in Secure-Join header. // Sends the step in Secure-Join header.
msg.param.set(Param::Arg, step.securejoin_header(invite)); msg.param.set(Param::Arg, step.securejoin_header(invite)?);
match step { match step {
BobHandshakeMsg::Request => { BobHandshakeMsg::Request => {
@@ -365,8 +365,8 @@ impl BobHandshakeMsg {
/// This text has no significance to the protocol, but would be visible if users see /// This text has no significance to the protocol, but would be visible if users see
/// this email message directly, e.g. when accessing their email without using /// this email message directly, e.g. when accessing their email without using
/// DeltaChat. /// DeltaChat.
fn body_text(&self, invite: &QrInvite) -> String { fn body_text(&self, invite: &QrInvite) -> Result<String> {
format!("Secure-Join: {}", self.securejoin_header(invite)) Ok(format!("Secure-Join: {}", self.securejoin_header(invite)?))
} }
/// Returns the `Secure-Join` header value. /// Returns the `Secure-Join` header value.
@@ -374,21 +374,22 @@ impl BobHandshakeMsg {
/// This identifies the step this message is sending information about. Most protocol /// This identifies the step this message is sending information about. Most protocol
/// steps include additional information into other headers, see /// steps include additional information into other headers, see
/// [`send_handshake_message`] for these. /// [`send_handshake_message`] for these.
fn securejoin_header(&self, invite: &QrInvite) -> &'static str { fn securejoin_header(&self, invite: &QrInvite) -> Result<&'static str> {
match self { let res = match self {
Self::Request => match invite { Self::Request => match invite {
QrInvite::Contact { .. } => "vc-request", QrInvite::Contact { .. } => "vc-request",
QrInvite::Group { .. } => "vg-request", QrInvite::Group { .. } => "vg-request",
QrInvite::Broadcast { .. } => { QrInvite::Broadcast { .. } => {
panic!("There is no request-with-auth for broadcasts") bail!("There is no request-with-auth for broadcasts")
} // TODO remove panic }
}, },
Self::RequestWithAuth => match invite { Self::RequestWithAuth => match invite {
QrInvite::Contact { .. } => "vc-request-with-auth", QrInvite::Contact { .. } => "vc-request-with-auth",
QrInvite::Group { .. } => "vg-request-with-auth", QrInvite::Group { .. } => "vg-request-with-auth",
QrInvite::Broadcast { .. } => "vb-request-with-auth", QrInvite::Broadcast { .. } => "vb-request-with-auth",
}, },
} };
Ok(res)
} }
} }