passkey_types/ctap2/
flags.rs

1use bitflags::bitflags;
2
3bitflags! {
4    /// Flags for authenticator Data
5    ///
6    /// <https://w3c.github.io/webauthn/#authdata-flags>
7    #[repr(transparent)]
8    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
9    pub struct Flags: u8 {
10        /// User Present, bit 0
11        const UP = 1 << 0;
12        /// User Verified, bit 2
13        const UV = 1 << 2;
14        /// Backup Eligibility, bit 3
15        const BE = 1 << 3;
16        /// Backup state, bit 4
17        const BS = 1 << 4;
18        /// Attested Credential Data, bit 6
19        const AT = 1 << 6;
20        /// Extension Data Included, bit 7
21        const ED = 1 << 7;
22    }
23}
24
25impl Default for Flags {
26    fn default() -> Self {
27        Flags::BE | Flags::BS
28    }
29}
30
31impl From<Flags> for u8 {
32    fn from(src: Flags) -> Self {
33        src.bits()
34    }
35}
36
37impl TryFrom<u8> for Flags {
38    type Error = ();
39
40    fn try_from(value: u8) -> Result<Self, Self::Error> {
41        Flags::from_bits(value).ok_or(())
42    }
43}