bitwarden_api_api/models/
policy_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 PolicyType {
17 TwoFactorAuthentication,
18 MasterPassword,
19 PasswordGenerator,
20 SingleOrg,
21 RequireSso,
22 OrganizationDataOwnership,
23 DisableSend,
24 SendOptions,
25 ResetPassword,
26 MaximumVaultTimeout,
27 DisablePersonalVaultExport,
28 ActivateAutofill,
29 AutomaticAppLogIn,
30 FreeFamiliesSponsorshipPolicy,
31 RemoveUnlockWithPin,
32 RestrictedItemTypesPolicy,
33 UriMatchDefaults,
34 AutotypeDefaultSetting,
35 AutomaticUserConfirmation,
36 BlockClaimedDomainAccountCreation,
37 OrganizationUserNotification,
38 SendControls,
39 FillAssist,
40 AutotypeGaPolicy,
41
42 __Unknown(i64),
44}
45
46impl PolicyType {
47 pub fn as_i64(&self) -> i64 {
48 match self {
49 Self::TwoFactorAuthentication => 0,
50 Self::MasterPassword => 1,
51 Self::PasswordGenerator => 2,
52 Self::SingleOrg => 3,
53 Self::RequireSso => 4,
54 Self::OrganizationDataOwnership => 5,
55 Self::DisableSend => 6,
56 Self::SendOptions => 7,
57 Self::ResetPassword => 8,
58 Self::MaximumVaultTimeout => 9,
59 Self::DisablePersonalVaultExport => 10,
60 Self::ActivateAutofill => 11,
61 Self::AutomaticAppLogIn => 12,
62 Self::FreeFamiliesSponsorshipPolicy => 13,
63 Self::RemoveUnlockWithPin => 14,
64 Self::RestrictedItemTypesPolicy => 15,
65 Self::UriMatchDefaults => 16,
66 Self::AutotypeDefaultSetting => 17,
67 Self::AutomaticUserConfirmation => 18,
68 Self::BlockClaimedDomainAccountCreation => 19,
69 Self::OrganizationUserNotification => 20,
70 Self::SendControls => 21,
71 Self::FillAssist => 22,
72 Self::AutotypeGaPolicy => 23,
73 Self::__Unknown(v) => *v,
74 }
75 }
76
77 pub fn from_i64(value: i64) -> Self {
78 match value {
79 0 => Self::TwoFactorAuthentication,
80 1 => Self::MasterPassword,
81 2 => Self::PasswordGenerator,
82 3 => Self::SingleOrg,
83 4 => Self::RequireSso,
84 5 => Self::OrganizationDataOwnership,
85 6 => Self::DisableSend,
86 7 => Self::SendOptions,
87 8 => Self::ResetPassword,
88 9 => Self::MaximumVaultTimeout,
89 10 => Self::DisablePersonalVaultExport,
90 11 => Self::ActivateAutofill,
91 12 => Self::AutomaticAppLogIn,
92 13 => Self::FreeFamiliesSponsorshipPolicy,
93 14 => Self::RemoveUnlockWithPin,
94 15 => Self::RestrictedItemTypesPolicy,
95 16 => Self::UriMatchDefaults,
96 17 => Self::AutotypeDefaultSetting,
97 18 => Self::AutomaticUserConfirmation,
98 19 => Self::BlockClaimedDomainAccountCreation,
99 20 => Self::OrganizationUserNotification,
100 21 => Self::SendControls,
101 22 => Self::FillAssist,
102 23 => Self::AutotypeGaPolicy,
103 v => Self::__Unknown(v),
104 }
105 }
106}
107
108impl serde::Serialize for PolicyType {
109 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
110 serializer.serialize_i64(self.as_i64())
111 }
112}
113
114impl<'de> serde::Deserialize<'de> for PolicyType {
115 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
116 struct PolicyTypeVisitor;
117
118 impl Visitor<'_> for PolicyTypeVisitor {
119 type Value = PolicyType;
120
121 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
122 f.write_str("an integer")
123 }
124
125 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
126 Ok(PolicyType::from_i64(v))
127 }
128
129 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
130 Ok(PolicyType::from_i64(v as i64))
131 }
132 }
133
134 deserializer.deserialize_i64(PolicyTypeVisitor)
135 }
136}
137
138impl std::fmt::Display for PolicyType {
139 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140 write!(f, "{}", self.as_i64())
141 }
142}
143impl Default for PolicyType {
144 fn default() -> PolicyType {
145 Self::TwoFactorAuthentication
146 }
147}