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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//! Algorithm wrapper implementations for type-safe cryptographic operations.
//!
//! 用于类型安全密码操作的算法包装器实现。
//!
//! ## Overview | 概述
//!
//! This module provides concrete implementations of cryptographic algorithm traits,
//! wrapping the underlying cryptographic libraries with a unified, type-safe interface.
//! Each wrapper ensures that operations are performed with the correct algorithm
//! and provides runtime verification of key compatibility.
//!
//! 此模块提供密码算法 trait 的具体实现,用统一的类型安全接口包装底层密码库。
//! 每个包装器确保使用正确的算法执行操作,并提供密钥兼容性的运行时验证。
//!
//! ## Design Pattern | 设计模式
//!
//! ### Wrapper Pattern | 包装器模式
//!
//! Each cryptographic algorithm is wrapped in a struct that:
//! - Implements the appropriate trait (e.g., `AeadAlgorithmTrait`)
//! - Provides algorithm-specific functionality
//! - Ensures type safety and prevents misuse
//! - Handles error conversion and validation
//!
//! 每个密码算法都包装在一个结构体中,该结构体:
//! - 实现适当的 trait(例如 `AeadAlgorithmTrait`)
//! - 提供算法特定的功能
//! - 确保类型安全并防止误用
//! - 处理错误转换和验证
//!
//! ### Trait Objects | Trait 对象
//!
//! Wrappers can be converted to trait objects (`Box<dyn Trait>`), enabling:
//! - Runtime polymorphism
//! - Algorithm selection at runtime
//! - Uniform interfaces across different algorithms
//! - Storage in collections
//!
//! 包装器可以转换为 trait 对象(`Box<dyn Trait>`),启用:
//! - 运行时多态性
//! - 运行时算法选择
//! - 不同算法间的统一接口
//! - 在集合中存储
//!
//! ## Macro Utilities | 宏工具
//!
//! The `define_wrapper!` macro provides a standardized way to create wrapper
//! implementations with consistent patterns and reduced boilerplate code.
//!
//! `define_wrapper!` 宏提供了一种标准化的方式来创建包装器实现,
//! 具有一致的模式和减少的样板代码。
/// Macro for defining cryptographic algorithm wrapper structs.
///
/// 用于定义密码算法包装器结构体的宏。
///
/// ## Purpose | 目的
///
/// This macro reduces boilerplate code when creating wrapper implementations
/// by providing standardized patterns for different wrapper types.
///
/// 此宏通过为不同包装器类型提供标准化模式来减少创建包装器实现时的样板代码。
///
/// ## Variants | 变体
///
/// ### Unit Struct Wrapper | 单元结构体包装器
/// ```ignore
/// define_wrapper!(
/// @unit_struct,
/// MyWrapper,
/// MyTrait,
/// { /* trait implementation */ }
/// );
/// ```
///
/// ### Struct with Algorithm Field | 带算法字段的结构体
/// ```ignore
/// define_wrapper!(
/// @struct_with_algorithm,
/// MyWrapper,
/// MyAlgorithm,
/// MyTrait,
/// { fn new(algo: MyAlgorithm) -> Self { Self { algorithm: algo } } },
/// { /* trait implementation */ }
/// );
/// ```
///
/// ### Struct with Default Algorithm | 带默认算法的结构体
/// ```ignore
/// define_wrapper!(
/// @struct_with_algorithm_default,
/// MyWrapper,
/// MyAlgorithm,
/// MyTrait,
/// { /* trait implementation */ }
/// );
/// ```
}
};
// Case 2: For wrappers with an 'algorithm' field and custom new()
=>
};
// Case 3: For wrappers with an 'algorithm' field using Default
=> ;
}
// Asymmetric algorithm wrappers | 非对称算法包装器
// Key derivation function wrappers | 密钥派生函数包装器
// Aead algorithm wrappers | 对称算法包装器
// Extendable output function wrappers | 可扩展输出函数包装器
// Hash algorithm wrappers | 哈希算法包装器