Skip to content

Commit

Permalink
login: Add supports_* to ProtocolVersion/Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gtker committed Mar 21, 2024
1 parent 15786ba commit fbedcb1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wow_login_messages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* `std::fmt::Display` for new enums.
* `supports_pin`/`supports_matrix_card`/`supports_authenticator` functions for `ProtocolVersion` and `Version`.

### Changed

Expand All @@ -32,6 +33,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* BREAKING: `Locale`, `Os`, and `Platform` no longer have an `Other` enumerator.
* BREAKING: Opcode types no longer implement `Eq`.
* BREAKING: `Population::Other` changed from `u32` to `f32`.

### Removed

* BREAKING: Removed `print-testcase` feature and all associated functionality. All known versions have been identified
and tests have been added.

Expand Down
2 changes: 2 additions & 0 deletions wow_login_messages/src/manual/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub(crate) mod population;
mod protocol_version;
mod version;

pub use population::*;
37 changes: 37 additions & 0 deletions wow_login_messages/src/manual/protocol_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::all::ProtocolVersion;

impl ProtocolVersion {
/// Returns whether the protocol supports PIN two-factor authentication.
///
/// Every protocol after [`Self::Two`] supports this.
pub fn supports_pin(&self) -> bool {
match self {
ProtocolVersion::Two => false,
ProtocolVersion::Three
| ProtocolVersion::Five
| ProtocolVersion::Six
| ProtocolVersion::Seven
| ProtocolVersion::Eight => true,
}
}

/// Returns whether the protocol supports matrix card two-factor authentication.
///
/// Every protocol after [`Self::Three`] supports this.
pub fn supports_matrix_card(&self) -> bool {
match self {
ProtocolVersion::Two | ProtocolVersion::Three => false,
ProtocolVersion::Five
| ProtocolVersion::Six
| ProtocolVersion::Seven
| ProtocolVersion::Eight => true,
}
}

/// Returns whether the protocol supports the TOTP authenticator.
///
/// Only [`Self::Eight`] supports this.
pub fn supports_authenticator(&self) -> bool {
matches!(self, Self::Eight)
}
}
36 changes: 36 additions & 0 deletions wow_login_messages/src/manual/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::all::Version;

impl Version {
/// Returns whether the protocol supports PIN two-factor authentication.
///
/// Any version released after `1.12.x` supports this.
pub fn supports_pin(&self) -> bool {
match (self.major, self.minor, self.patch) {
(0, _, _) => false,
(1, 0..=11, _) => false,
_ => true,
}
}

/// Returns whether the protocol supports matrix card two-factor authentication.
///
/// Any version released after `2.0.1.6180` supports this.
pub fn supports_matrix_card(&self) -> bool {
match (self.major, self.minor, self.patch) {
(0..=1, _, _) => false,
(2, 0, 0..=2) => false,
_ => true,
}
}

/// Returns whether the protocol supports the TOTP authenticator.
///
/// Any version released after `2.4.0.8089` supports this.
pub fn supports_authenticator(&self) -> bool {
match (self.major, self.minor, self.patch) {
(0..=1, _, _) => false,
(2, 0..=3, _) => false,
_ => true,
}
}
}

0 comments on commit fbedcb1

Please sign in to comment.