bitwarden_api_api/models/
two_factor_provider_type.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum TwoFactorProviderType {
17 Authenticator,
18 Email,
19 Duo,
20 YubiKey,
21 U2f,
22 Remember,
23 OrganizationDuo,
24 WebAuthn,
25 RecoveryCode,
26
27 __Unknown(i64),
29}
30
31impl TwoFactorProviderType {
32 pub fn as_i64(&self) -> i64 {
33 match self {
34 Self::Authenticator => 0,
35 Self::Email => 1,
36 Self::Duo => 2,
37 Self::YubiKey => 3,
38 Self::U2f => 4,
39 Self::Remember => 5,
40 Self::OrganizationDuo => 6,
41 Self::WebAuthn => 7,
42 Self::RecoveryCode => 8,
43 Self::__Unknown(v) => *v,
44 }
45 }
46
47 pub fn from_i64(value: i64) -> Self {
48 match value {
49 0 => Self::Authenticator,
50 1 => Self::Email,
51 2 => Self::Duo,
52 3 => Self::YubiKey,
53 4 => Self::U2f,
54 5 => Self::Remember,
55 6 => Self::OrganizationDuo,
56 7 => Self::WebAuthn,
57 8 => Self::RecoveryCode,
58 v => Self::__Unknown(v),
59 }
60 }
61}
62
63impl serde::Serialize for TwoFactorProviderType {
64 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
65 serializer.serialize_i64(self.as_i64())
66 }
67}
68
69impl<'de> serde::Deserialize<'de> for TwoFactorProviderType {
70 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
71 struct TwoFactorProviderTypeVisitor;
72
73 impl Visitor<'_> for TwoFactorProviderTypeVisitor {
74 type Value = TwoFactorProviderType;
75
76 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77 f.write_str("an integer")
78 }
79
80 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
81 Ok(TwoFactorProviderType::from_i64(v))
82 }
83
84 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
85 Ok(TwoFactorProviderType::from_i64(v as i64))
86 }
87 }
88
89 deserializer.deserialize_i64(TwoFactorProviderTypeVisitor)
90 }
91}
92
93impl std::fmt::Display for TwoFactorProviderType {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 write!(f, "{}", self.as_i64())
96 }
97}
98impl Default for TwoFactorProviderType {
99 fn default() -> TwoFactorProviderType {
100 Self::Authenticator
101 }
102}