From dcd08e8d3b696c5a24bd4cbd73a01c6e7e05cdba Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 30 Oct 2025 16:06:18 +0100 Subject: [PATCH] refactor(oauth): move QrProgress to module file for later reuse Signed-off-by: Johannes Marbach --- .../src/authentication/oauth/qrcode/login.rs | 21 +++++-------------- .../src/authentication/oauth/qrcode/mod.rs | 16 +++++++++++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs index db5bdeec1..adbadf31f 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs @@ -27,7 +27,7 @@ use ruma::{ api::client::discovery::get_authorization_server_metadata::v1::AuthorizationServerMetadata, }; use tracing::trace; -use vodozemac::{Curve25519PublicKey, ecies::CheckCode}; +use vodozemac::Curve25519PublicKey; use super::{ DeviceAuthorizationOAuthError, QRCodeLoginError, SecureChannelError, @@ -38,7 +38,7 @@ use crate::{ Client, authentication::oauth::{ ClientRegistrationData, OAuth, OAuthError, - qrcode::{CheckCodeSender, GeneratedQrProgress, LoginProtocolType}, + qrcode::{CheckCodeSender, GeneratedQrProgress, LoginProtocolType, QrProgress}, }, }; @@ -247,7 +247,7 @@ pub enum LoginProgress { #[default] Starting, /// We have established the secure channel, but need to exchange the - /// [`CheckCode`] so the channel can be verified to indeed be secure. + /// checkcode so the channel can be verified to indeed be secure. EstablishingSecureChannel(Q), /// We're waiting for the OAuth 2.0 authorization server to give us the /// access token. This will only happen if the other device allows the @@ -264,18 +264,6 @@ pub enum LoginProgress { Done, } -/// Metadata to be used with [`LoginProgress::EstablishingSecureChannel`] when -/// this device is the one scanning the QR code. -/// -/// We have established the secure channel, but we need to let the other -/// side know about the [`CheckCode`] so they can verify that the secure -/// channel is indeed secure. -#[derive(Clone, Debug)] -pub struct QrProgress { - /// The check code we need to, out of band, send to the other device. - pub check_code: CheckCode, -} - /// Named future for logging in by scanning a QR code with the /// [`OAuth::login_with_qr_code()`] method. #[derive(Debug)] @@ -290,7 +278,7 @@ impl LoginWithQrCode<'_> { /// Subscribe to the progress of QR code login. /// /// It's usually necessary to subscribe to this to let the existing device - /// know about the [`CheckCode`] which is used to verify that the two + /// know about the checkcode which is used to verify that the two /// devices are communicating in a secure manner. pub fn subscribe_to_progress(&self) -> impl Stream> + use<> { self.state.subscribe() @@ -500,6 +488,7 @@ mod test { use matrix_sdk_common::executor::spawn; use matrix_sdk_test::async_test; use serde_json::json; + use vodozemac::ecies::CheckCode; use super::*; use crate::{ diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs index 939f1cb3c..9e9cb1aec 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs @@ -36,6 +36,7 @@ pub use oauth2::{ use thiserror::Error; use tokio::sync::Mutex; use url::Url; +use vodozemac::ecies::CheckCode; pub use vodozemac::ecies::{Error as EciesError, MessageDecodeError}; mod grant; @@ -46,7 +47,7 @@ mod secure_channel; pub use self::{ grant::{GrantLoginProgress, GrantLoginWithGeneratedQrCode}, - login::{LoginProgress, LoginWithGeneratedQrCode, LoginWithQrCode, QrProgress}, + login::{LoginProgress, LoginWithGeneratedQrCode, LoginWithQrCode}, messages::{LoginFailureReason, LoginProtocolType, QrAuthMessage}, }; use super::CrossProcessRefreshLockError; @@ -256,6 +257,19 @@ pub enum SecureChannelError { CannotReceiveCheckCode, } +/// Metadata to be used with [`LoginProgress::EstablishingSecureChannel`] +/// or [`GrantLoginProgress::EstablishingSecureChannel`] when +/// this device is the one scanning the QR code. +/// +/// We have established the secure channel, but we need to let the other +/// side know about the [`CheckCode`] so they can verify that the secure +/// channel is indeed secure. +#[derive(Clone, Debug)] +pub struct QrProgress { + /// The check code we need to, out of band, send to the other device. + pub check_code: CheckCode, +} + /// Metadata to be used with [`LoginProgress::EstablishingSecureChannel`] and /// [`GrantLoginProgress::EstablishingSecureChannel`] when this device is the /// one generating the QR code.