1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![deny(broken_intra_doc_links)]
#[cfg(not(feature = "json"))]
include!("codegen/google.crypto.tink.rs");
#[cfg(feature = "json")]
include!("codegen/serde/google.crypto.tink.rs");
#[cfg(feature = "json")]
pub mod json {
pub mod key_status_type {
use serde::Deserialize;
pub fn serialize<S: serde::Serializer>(
val: &i32,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(match crate::KeyStatusType::from_i32(*val) {
Some(crate::KeyStatusType::Enabled) => "ENABLED",
Some(crate::KeyStatusType::Disabled) => "DISABLED",
Some(crate::KeyStatusType::Destroyed) => "DESTROYED",
_ => "UNKNOWN",
})
}
pub fn deserialize<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<i32, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(match s.as_ref() {
"ENABLED" => crate::KeyStatusType::Enabled as i32,
"DISABLED" => crate::KeyStatusType::Disabled as i32,
"DESTROYED" => crate::KeyStatusType::Destroyed as i32,
_ => crate::KeyStatusType::UnknownStatus as i32,
})
}
}
pub mod output_prefix_type {
use serde::Deserialize;
pub fn serialize<S: serde::Serializer>(
val: &i32,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(match crate::OutputPrefixType::from_i32(*val) {
Some(crate::OutputPrefixType::Tink) => "TINK",
Some(crate::OutputPrefixType::Legacy) => "LEGACY",
Some(crate::OutputPrefixType::Raw) => "RAW",
Some(crate::OutputPrefixType::Crunchy) => "CRUNCHY",
_ => "UNKNOWN",
})
}
pub fn deserialize<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<i32, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(match s.as_ref() {
"TINK" => crate::OutputPrefixType::Tink as i32,
"LEGACY" => crate::OutputPrefixType::Legacy as i32,
"RAW" => crate::OutputPrefixType::Raw as i32,
"CRUNCHY" => crate::OutputPrefixType::Crunchy as i32,
_ => crate::OutputPrefixType::UnknownPrefix as i32,
})
}
}
pub mod key_material_type {
use serde::Deserialize;
pub fn serialize<S: serde::Serializer>(
val: &i32,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(match crate::key_data::KeyMaterialType::from_i32(*val) {
Some(crate::key_data::KeyMaterialType::Symmetric) => "SYMMETRIC",
Some(crate::key_data::KeyMaterialType::AsymmetricPrivate) => "ASYMMETRIC_PRIVATE",
Some(crate::key_data::KeyMaterialType::AsymmetricPublic) => "ASYMMETRIC_PUBLIC",
Some(crate::key_data::KeyMaterialType::Remote) => "REMOTE",
_ => "UNKNOWN",
})
}
pub fn deserialize<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<i32, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(match s.as_ref() {
"SYMMETRIC" => crate::key_data::KeyMaterialType::Symmetric as i32,
"ASYMMETRIC_PRIVATE" => crate::key_data::KeyMaterialType::AsymmetricPrivate as i32,
"ASYMMETRIC_PUBLIC" => crate::key_data::KeyMaterialType::AsymmetricPublic as i32,
"REMOTE" => crate::key_data::KeyMaterialType::Remote as i32,
_ => crate::key_data::KeyMaterialType::UnknownKeymaterial as i32,
})
}
}
pub mod b64 {
use serde::Deserialize;
pub fn serialize<S: serde::Serializer>(
val: &[u8],
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&base64::encode(val))
}
pub fn deserialize<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Vec<u8>, D::Error> {
let s = String::deserialize(deserializer)?;
base64::decode(&s).map_err(|_e| {
serde::de::Error::invalid_value(
serde::de::Unexpected::Str(&s),
&"base64 data expected",
)
})
}
}
}