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
23    /// Unknown value returned from the server. This is used to handle forward compatibility.
24    __Unknown(i64),
25}
26
27impl CipherType {
28    pub fn as_i64(&self) -> i64 {
29        match self {
30            Self::Login => 1,
31            Self::SecureNote => 2,
32            Self::Card => 3,
33            Self::Identity => 4,
34            Self::SSHKey => 5,
35            Self::__Unknown(v) => *v,
36        }
37    }
38
39    pub fn from_i64(value: i64) -> Self {
40        match value {
41            1 => Self::Login,
42            2 => Self::SecureNote,
43            3 => Self::Card,
44            4 => Self::Identity,
45            5 => Self::SSHKey,
46            v => Self::__Unknown(v),
47        }
48    }
49}
50
51impl serde::Serialize for CipherType {
52    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
53        serializer.serialize_i64(self.as_i64())
54    }
55}
56
57impl<'de> serde::Deserialize<'de> for CipherType {
58    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
59        struct CipherTypeVisitor;
60
61        impl Visitor<'_> for CipherTypeVisitor {
62            type Value = CipherType;
63
64            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
65                f.write_str("an integer")
66            }
67
68            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
69                Ok(CipherType::from_i64(v))
70            }
71
72            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
73                Ok(CipherType::from_i64(v as i64))
74            }
75        }
76
77        deserializer.deserialize_i64(CipherTypeVisitor)
78    }
79}
80
81impl std::fmt::Display for CipherType {
82    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83        write!(f, "{}", self.as_i64())
84    }
85}
86impl Default for CipherType {
87    fn default() -> CipherType {
88        Self::Login
89    }
90}