webauthn_authenticator_rs/ctap2/commands/
selection.rs

1use serde::Serialize;
2
3use self::CBORCommand;
4use super::*;
5
6/// `authenticatorSelection` request type.
7///
8/// This feature **requires** FIDO v2.1. v2.1-PRE isn't good enough.
9///
10/// This has no parameters or response type.
11///
12/// <https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorSelection>
13#[derive(Serialize, Debug, Clone)]
14pub struct SelectionRequest {}
15
16impl CBORCommand for SelectionRequest {
17    const CMD: u8 = 0x0b;
18    const HAS_PAYLOAD: bool = false;
19    type Response = NoResponse;
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25    use crate::transport::iso7816::ISO7816LengthForm;
26
27    #[test]
28    fn selection_request() {
29        let req = SelectionRequest {};
30        let short = vec![0x80, 0x10, 0, 0, 1, 0xb, 0];
31        let ext = vec![0x80, 0x10, 0, 0, 0, 0, 1, 0xb, 0, 0];
32
33        let a = to_short_apdus(&req.cbor().unwrap());
34        assert_eq!(1, a.len());
35        assert_eq!(short, a[0].to_bytes(&ISO7816LengthForm::ShortOnly).unwrap());
36        assert_eq!(short, a[0].to_bytes(&ISO7816LengthForm::Extended).unwrap());
37
38        assert_eq!(
39            ext,
40            to_extended_apdu(req.cbor().unwrap())
41                .to_bytes(&ISO7816LengthForm::Extended)
42                .unwrap()
43        );
44        assert_eq!(
45            ext,
46            to_extended_apdu(req.cbor().unwrap())
47                .to_bytes(&ISO7816LengthForm::ExtendedOnly)
48                .unwrap()
49        );
50        assert!(to_extended_apdu(req.cbor().unwrap())
51            .to_bytes(&ISO7816LengthForm::ShortOnly)
52            .is_err());
53    }
54}