Skip to main content

bitwarden_api_api/models/
cipher_type.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14///
15#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum CipherType {
17    Login,
18    SecureNote,
19    Card,
20    Identity,
21    SSHKey,
22    BankAccount,
23    DriversLicense,
24    Passport,
25
26    /// Unknown value returned from the server. This is used to handle forward compatibility.
27    __Unknown(i64),
28}
29
30impl CipherType {
31    pub fn as_i64(&self) -> i64 {
32        match self {
33            Self::Login => 1,
34            Self::SecureNote => 2,
35            Self::Card => 3,
36            Self::Identity => 4,
37            Self::SSHKey => 5,
38            Self::BankAccount => 6,
39            Self::DriversLicense => 7,
40            Self::Passport => 8,
41            Self::__Unknown(v) => *v,
42        }
43    }
44
45    pub fn from_i64(value: i64) -> Self {
46        match value {
47            1 => Self::Login,
48            2 => Self::SecureNote,
49            3 => Self::Card,
50            4 => Self::Identity,
51            5 => Self::SSHKey,
52            6 => Self::BankAccount,
53            7 => Self::DriversLicense,
54            8 => Self::Passport,
55            v => Self::__Unknown(v),
56        }
57    }
58}
59
60impl serde::Serialize for CipherType {
61    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
62        serializer.serialize_i64(self.as_i64())
63    }
64}
65
66impl<'de> serde::Deserialize<'de> for CipherType {
67    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
68        struct CipherTypeVisitor;
69
70        impl Visitor<'_> for CipherTypeVisitor {
71            type Value = CipherType;
72
73            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
74                f.write_str("an integer")
75            }
76
77            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
78                Ok(CipherType::from_i64(v))
79            }
80
81            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
82                Ok(CipherType::from_i64(v as i64))
83            }
84        }
85
86        deserializer.deserialize_i64(CipherTypeVisitor)
87    }
88}
89
90impl std::fmt::Display for CipherType {
91    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92        write!(f, "{}", self.as_i64())
93    }
94}
95impl Default for CipherType {
96    fn default() -> CipherType {
97        Self::Login
98    }
99}