easyofd_core/crypto/
mod.rs1mod provider;
16
17pub use provider::CryptoProvider;
18
19#[derive(Debug, Clone, Default)]
23pub struct CryptoParameter {
24 pub name: String,
26 pub value: String,
28}
29
30impl CryptoParameter {
31 #[must_use]
33 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
34 Self {
35 name: name.into(),
36 value: value.into(),
37 }
38 }
39}
40
41#[derive(Debug, Clone, Default)]
45pub struct SigParameter {
46 pub name: String,
48 pub value: String,
50}
51
52impl SigParameter {
53 #[must_use]
55 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
56 Self {
57 name: name.into(),
58 value: value.into(),
59 }
60 }
61}
62
63#[derive(Debug, Clone, Default)]
67pub struct SigParameters {
68 pub parameters: Vec<SigParameter>,
70}
71
72impl SigParameters {
73 #[must_use]
75 pub fn new() -> Self {
76 Self::default()
77 }
78
79 pub fn add(&mut self, param: SigParameter) {
81 self.parameters.push(param);
82 }
83
84 #[must_use]
86 pub fn len(&self) -> usize {
87 self.parameters.len()
88 }
89
90 #[must_use]
92 pub fn is_empty(&self) -> bool {
93 self.parameters.is_empty()
94 }
95}
96
97#[derive(Debug, Clone, Default)]
101pub struct UserInfo {
102 pub user_name: Option<String>,
104 pub cert: Option<String>,
106}
107
108impl UserInfo {
109 #[must_use]
111 pub fn new() -> Self {
112 Self::default()
113 }
114
115 #[must_use]
117 pub fn user_name(mut self, name: impl Into<String>) -> Self {
118 self.user_name = Some(name.into());
119 self
120 }
121}
122
123#[derive(Debug, Clone, Default)]
127pub struct Encryptions {
128 pub items: Vec<String>,
130}
131
132impl Encryptions {
133 #[must_use]
135 pub fn new() -> Self {
136 Self::default()
137 }
138
139 pub fn add(&mut self, item: impl Into<String>) {
141 self.items.push(item.into());
142 }
143}
144
145#[derive(Debug, Clone, Default)]
149pub struct ExtendParams {
150 pub params: Vec<(String, String)>,
152}
153
154impl ExtendParams {
155 #[must_use]
157 pub fn new() -> Self {
158 Self::default()
159 }
160
161 pub fn add(&mut self, key: impl Into<String>, value: impl Into<String>) {
163 self.params.push((key.into(), value.into()));
164 }
165}
166
167#[derive(Debug, Clone, Default)]
171pub struct DecyptSeed {
172 pub seed: Vec<u8>,
174}
175
176impl DecyptSeed {
177 #[must_use]
179 pub fn new(seed: Vec<u8>) -> Self {
180 Self { seed }
181 }
182}
183
184#[cfg(test)]
185mod tests {
186 use super::*;
187
188 #[test]
189 fn crypto_parameter_new() {
190 let p = CryptoParameter::new("key", "value");
191 assert_eq!(p.name, "key");
192 assert_eq!(p.value, "value");
193 }
194
195 #[test]
196 fn sig_parameter_new() {
197 let p = SigParameter::new("algo", "SM2");
198 assert_eq!(p.name, "algo");
199 }
200
201 #[test]
202 fn sig_parameters_add() {
203 let mut params = SigParameters::new();
204 params.add(SigParameter::new("a", "1"));
205 assert_eq!(params.len(), 1);
206 }
207
208 #[test]
209 fn user_info_builder() {
210 let ui = UserInfo::new().user_name("test");
211 assert_eq!(ui.user_name.unwrap(), "test");
212 }
213
214 #[test]
215 fn encryptions_add() {
216 let mut e = Encryptions::new();
217 e.add("entry1");
218 assert_eq!(e.items.len(), 1);
219 }
220
221 #[test]
222 fn extend_params_add() {
223 let mut ep = ExtendParams::new();
224 ep.add("k", "v");
225 assert_eq!(ep.params.len(), 1);
226 }
227
228 #[test]
229 fn decypt_seed_new() {
230 let ds = DecyptSeed::new(vec![1, 2, 3]);
231 assert_eq!(ds.seed.len(), 3);
232 }
233}