refactor(crypto): Rename the QrLoginError into InvalidIntent

This commit is contained in:
Damir Jelić
2026-01-19 14:40:17 +01:00
parent 036fa5ca82
commit bfe42d9ccf
2 changed files with 21 additions and 7 deletions
@@ -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<u8>,
},
}
@@ -73,7 +73,11 @@ impl TryFrom<u8> 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.