diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0de07..668f49f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `Version::Fido2_3` variant. - Add `Transport::SmartCard` variant. - `ctap2::authenticator_config`: Add `Subcommand::EnableLongTouchForReset`. +- Add `EXTENSION_COUNT`, `TRANSPORT_COUNT` and `VERSION_COUNT` constants for the size of the corresponding enums. ## [0.5.0] 2026-03-23 diff --git a/src/ctap2/get_info.rs b/src/ctap2/get_info.rs index 75a6854..358749b 100644 --- a/src/ctap2/get_info.rs +++ b/src/ctap2/get_info.rs @@ -10,11 +10,11 @@ pub type AuthenticatorInfo = Response; #[serde_indexed(offset = 1)] pub struct Response { // 0x01 - pub versions: Vec, + pub versions: Vec, // 0x02 #[serde(skip_serializing_if = "Option::is_none")] - pub extensions: Option>, + pub extensions: Option>, // 0x03 pub aaguid: Bytes<16>, @@ -44,7 +44,7 @@ pub struct Response { // 0x09 // FIDO_2_1 #[serde(skip_serializing_if = "Option::is_none")] - pub transports: Option>, + pub transports: Option>, // 0x0A // FIDO_2_1 @@ -154,7 +154,7 @@ impl Default for Response { #[derive(Debug)] pub struct ResponseBuilder { - pub versions: Vec, + pub versions: Vec, pub aaguid: Bytes<16>, } @@ -214,6 +214,8 @@ pub enum Version { U2fV2, } +pub const VERSION_COUNT: usize = 5; + impl Version { const FIDO_2_0: &'static str = "FIDO_2_0"; const FIDO_2_1: &'static str = "FIDO_2_1"; @@ -249,6 +251,8 @@ impl TryFrom<&str> for Version { } } +pub const EXTENSION_COUNT: usize = 7; + #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive] #[serde(into = "&str", try_from = "&str")] @@ -303,6 +307,8 @@ impl TryFrom<&str> for Extension { } } +pub const TRANSPORT_COUNT: usize = 3; + #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive] #[serde(into = "&str", try_from = "&str")] @@ -470,7 +476,7 @@ mod tests { #[test] fn test_serde_version() { - let versions = [ + let versions: [_; VERSION_COUNT] = [ (Version::Fido2_0, "FIDO_2_0"), (Version::Fido2_1, "FIDO_2_1"), (Version::Fido2_1Pre, "FIDO_2_1_PRE"), @@ -484,7 +490,7 @@ mod tests { #[test] fn test_serde_extension() { - let extensions = [ + let extensions: [_; EXTENSION_COUNT] = [ (Extension::CredProtect, "credProtect"), (Extension::CredBlob, "credBlob"), (Extension::HmacSecret, "hmac-secret"), @@ -500,7 +506,7 @@ mod tests { #[test] fn test_serde_transport() { - let transports = [ + let transports: [_; TRANSPORT_COUNT] = [ (Transport::Nfc, "nfc"), (Transport::SmartCard, "smart-card"), (Transport::Usb, "usb"),