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
//! How deep a type nests, for [`Encrypt::DEPTH`](super::Encrypt::DEPTH).
//!
//! A depth counts containers below a value's own root, the way the
//! encrypting sink and the transport frame count them: a scalar is `0`, and
//! a sequence or map is one more than its deepest child. `None` means the
//! type alone does not fix it (a recursive type, a frame, a live host
//! value), so only the walk can check it.
//!
//! These are `const fn`s so a type's depth is worked out at compile time,
//! from its fields' depths.
//!
//! A generic type is checked where it is used at a concrete type, when that
//! use is built (`cargo build`, not `cargo check`). `Holder<V128<u32>>` nests
//! one level deeper than `MAX_DEPTH`, so building a use of it fails:
//!
//! ```compile_fail,E0080
//! #![recursion_limit = "512"]
//! use vitaminc_aead::{plan, Encrypt};
//!
//! type V2<T> = Vec<Vec<T>>;
//! type V4<T> = V2<V2<T>>;
//! type V8<T> = V4<V4<T>>;
//! type V16<T> = V8<V8<T>>;
//! type V32<T> = V16<V16<T>>;
//! type V64<T> = V32<V32<T>>;
//! type V128<T> = V64<V64<T>>;
//!
//! #[derive(Encrypt)]
//! struct Holder<T> {
//! value: T,
//! }
//!
//! let _ = plan::<_, (), _>(Holder { value: V128::<u32>::new() }, "aad");
//! ```
//!
//! One level shallower, at exactly `MAX_DEPTH`, it builds:
//!
//! ```
//! #![recursion_limit = "512"]
//! use vitaminc_aead::{plan, Encrypt};
//!
//! type V2<T> = Vec<Vec<T>>;
//! type V4<T> = V2<V2<T>>;
//! type V8<T> = V4<V4<T>>;
//! type V16<T> = V8<V8<T>>;
//! type V32<T> = V16<V16<T>>;
//! type V64<T> = V32<V32<T>>;
//! type V127<T> = V64<V32<V16<V8<V4<V2<Vec<T>>>>>>>;
//!
//! #[derive(Encrypt)]
//! struct Holder<T> {
//! value: T,
//! }
//!
//! assert!(plan::<_, (), _>(Holder { value: V127::<u32>::new() }, "aad").is_ok());
//! ```
//!
//! A type with only lifetime parameters is checked where it is defined, as
//! a type with none is, so no use is needed for the error:
//!
//! ```compile_fail,E0080
//! #![recursion_limit = "512"]
//! use vitaminc_aead::Encrypt;
//!
//! type V2<T> = Vec<Vec<T>>;
//! type V4<T> = V2<V2<T>>;
//! type V8<T> = V4<V4<T>>;
//! type V16<T> = V8<V8<T>>;
//! type V32<T> = V16<V16<T>>;
//! type V64<T> = V32<V32<T>>;
//! type V128<T> = V64<V64<T>>;
//!
//! #[derive(Encrypt)]
//! struct Row<'a> {
//! name: &'a str,
//! deep: V128<u32>,
//! }
//! ```
//!
//! So is a type whose field is another type of the same name, reached
//! through a path:
//!
//! ```compile_fail,E0080
//! #![recursion_limit = "512"]
//! use vitaminc_aead::Encrypt;
//!
//! type V2<T> = Vec<Vec<T>>;
//! type V4<T> = V2<V2<T>>;
//! type V8<T> = V4<V4<T>>;
//! type V16<T> = V8<V8<T>>;
//! type V32<T> = V16<V16<T>>;
//! type V64<T> = V32<V32<T>>;
//!
//! mod legacy {
//! pub type User = super::V64<super::V64<u32>>;
//! }
//!
//! #[derive(Encrypt)]
//! struct User {
//! id: u32,
//! inner: legacy::User,
//! }
//! # fn main() {}
//! ```
use crateMAX_DEPTH;
/// A scalar: nothing below it.
pub const SCALAR: = Some;
/// A sequence or map whose deepest child nests `child` deep.
pub const
/// The deeper of two depths. Not fixed if either is not.
pub const
/// A passthrough field whose value nests `value` deep. The frame that
/// carries it starts one level below the passthrough node, as the transport
/// decoder counts it.
pub const
/// Whether a value this deep can be encrypted: at most
/// [`MAX_DEPTH`]. A depth that is not fixed passes, because the
/// walk checks it.
pub const