diff --git a/crates/matrix-sdk-crypto/src/types/qr_login/mod.rs b/crates/matrix-sdk-crypto/src/types/qr_login/mod.rs index c64f2148d..f574902e9 100644 --- a/crates/matrix-sdk-crypto/src/types/qr_login/mod.rs +++ b/crates/matrix-sdk-crypto/src/types/qr_login/mod.rs @@ -39,12 +39,19 @@ pub enum LoginQrCodeDecodeError { /// One of the URLs in the QR code data could not be parsed. #[error("One of the URLs in the QR code data could not be parsed: {0:?}")] UrlParse(#[from] url::ParseError), - /// The QR code data contains an invalid mode, we expect the login (0x03) - /// mode or the reciprocate mode (0x04). + /// The QR code data contains an invalid intent, we expect the login + /// intent or the reciprocate intent. #[error( - "The QR code data contains an invalid QR code login mode, expected 0x03 or 0x04, got {0}" + "The QR code data contains an invalid QR code intent, expected {expected_login} or {expected_reciprocate}, got {got}" )] - InvalidMode(u8), + InvalidIntent { + /// The constant we expect for the login intent. + expected_login: u8, + /// The constant we expect for the reciprocate intent. + expected_reciprocate: u8, + /// The intent we received. + got: u8, + }, /// The QR code data contains an unsupported type. #[error("The QR code data contains an unsupported type, expected {expected}, got {got}")] InvalidType { @@ -63,7 +70,7 @@ pub enum LoginQrCodeDecodeError { /// The expected prefix. expected: &'static [u8], /// The prefix we received. - got: [u8; 6], + got: Vec, }, } diff --git a/crates/matrix-sdk-crypto/src/types/qr_login/msc_4108.rs b/crates/matrix-sdk-crypto/src/types/qr_login/msc_4108.rs index 66f048aed..a82f16105 100644 --- a/crates/matrix-sdk-crypto/src/types/qr_login/msc_4108.rs +++ b/crates/matrix-sdk-crypto/src/types/qr_login/msc_4108.rs @@ -73,7 +73,11 @@ impl TryFrom for QrCodeIntent { match value { 0x03 => Ok(Self::Login), 0x04 => Ok(Self::Reciprocate), - mode => Err(LoginQrCodeDecodeError::InvalidMode(mode)), + intent => Err(LoginQrCodeDecodeError::InvalidIntent { + expected_login: QrCodeIntent::Login as u8, + expected_reciprocate: QrCodeIntent::Reciprocate as u8, + got: intent, + }), } } } @@ -128,7 +132,10 @@ impl QrCodeData { reader.read_exact(&mut prefix)?; if PREFIX != prefix { - return Err(LoginQrCodeDecodeError::InvalidPrefix { expected: PREFIX, got: prefix }); + return Err(LoginQrCodeDecodeError::InvalidPrefix { + expected: PREFIX, + got: prefix.to_vec(), + }); } // 2. Next up is the version, we continue only if the version matches.