Skip to content

Commit bb4f857

Browse files
Add constants for enum sizes
1 parent af3a162 commit bb4f857

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Add `Version::Fido2_3` variant.
2020
- Add `Transport::SmartCard` variant.
2121
- `ctap2::authenticator_config`: Add `Subcommand::EnableLongTouchForReset`.
22+
- Add `EXTENSION_COUNT`, `TRANSPORT_COUNT` and `VERSION_COUNT` constants for the size of the corresponding enums.
2223

2324
## [0.5.0] 2026-03-23
2425

src/ctap2/get_info.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ pub type AuthenticatorInfo = Response;
1010
#[serde_indexed(offset = 1)]
1111
pub struct Response {
1212
// 0x01
13-
pub versions: Vec<Version, 5>,
13+
pub versions: Vec<Version, VERSION_COUNT>,
1414

1515
// 0x02
1616
#[serde(skip_serializing_if = "Option::is_none")]
17-
pub extensions: Option<Vec<Extension, 7>>,
17+
pub extensions: Option<Vec<Extension, EXTENSION_COUNT>>,
1818

1919
// 0x03
2020
pub aaguid: Bytes<16>,
@@ -44,7 +44,7 @@ pub struct Response {
4444
// 0x09
4545
// FIDO_2_1
4646
#[serde(skip_serializing_if = "Option::is_none")]
47-
pub transports: Option<Vec<Transport, 3>>,
47+
pub transports: Option<Vec<Transport, TRANSPORT_COUNT>>,
4848

4949
// 0x0A
5050
// FIDO_2_1
@@ -154,7 +154,7 @@ impl Default for Response {
154154

155155
#[derive(Debug)]
156156
pub struct ResponseBuilder {
157-
pub versions: Vec<Version, 5>,
157+
pub versions: Vec<Version, VERSION_COUNT>,
158158
pub aaguid: Bytes<16>,
159159
}
160160

@@ -214,6 +214,8 @@ pub enum Version {
214214
U2fV2,
215215
}
216216

217+
pub const VERSION_COUNT: usize = 5;
218+
217219
impl Version {
218220
const FIDO_2_0: &'static str = "FIDO_2_0";
219221
const FIDO_2_1: &'static str = "FIDO_2_1";
@@ -249,6 +251,8 @@ impl TryFrom<&str> for Version {
249251
}
250252
}
251253

254+
pub const EXTENSION_COUNT: usize = 7;
255+
252256
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
253257
#[non_exhaustive]
254258
#[serde(into = "&str", try_from = "&str")]
@@ -303,6 +307,8 @@ impl TryFrom<&str> for Extension {
303307
}
304308
}
305309

310+
pub const TRANSPORT_COUNT: usize = 3;
311+
306312
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
307313
#[non_exhaustive]
308314
#[serde(into = "&str", try_from = "&str")]
@@ -470,7 +476,7 @@ mod tests {
470476

471477
#[test]
472478
fn test_serde_version() {
473-
let versions = [
479+
let versions: [_; VERSION_COUNT] = [
474480
(Version::Fido2_0, "FIDO_2_0"),
475481
(Version::Fido2_1, "FIDO_2_1"),
476482
(Version::Fido2_1Pre, "FIDO_2_1_PRE"),
@@ -484,7 +490,7 @@ mod tests {
484490

485491
#[test]
486492
fn test_serde_extension() {
487-
let extensions = [
493+
let extensions: [_; EXTENSION_COUNT] = [
488494
(Extension::CredProtect, "credProtect"),
489495
(Extension::CredBlob, "credBlob"),
490496
(Extension::HmacSecret, "hmac-secret"),
@@ -500,7 +506,7 @@ mod tests {
500506

501507
#[test]
502508
fn test_serde_transport() {
503-
let transports = [
509+
let transports: [_; TRANSPORT_COUNT] = [
504510
(Transport::Nfc, "nfc"),
505511
(Transport::SmartCard, "smart-card"),
506512
(Transport::Usb, "usb"),

0 commit comments

Comments
 (0)