asn1_rs/
derive.rs

1/// # BerSequence custom derive
2///
3/// `BerSequence` is a custom derive attribute, to derive a BER [`Sequence`](super::Sequence) parser automatically from the structure definition.
4/// This attribute will automatically derive implementations for the following traits:
5///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
6///   - [`Tagged`](super::Tagged)
7///
8/// `DerSequence` implies `BerSequence`, and will conflict with this custom derive. Use `BerSequence` when you only want the
9/// above traits derived.
10///
11/// Parsers will be automatically derived from struct fields. Every field type must implement the [`FromBer`](super::FromBer) trait.
12///
13/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
14///
15/// ## Examples
16///
17/// To parse the following ASN.1 structure:
18/// <pre>
19/// S ::= SEQUENCE {
20///     a INTEGER(0..2^32),
21///     b INTEGER(0..2^16),
22///     c INTEGER(0..2^16),
23/// }
24/// </pre>
25///
26/// Define a structure and add the `BerSequence` derive:
27///
28/// ```rust
29/// use asn1_rs::*;
30///
31/// #[derive(BerSequence)]
32/// struct S {
33///   a: u32,
34///   b: u16,
35///   c: u16
36/// }
37/// ```
38///
39/// ## Debugging
40///
41/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
42///
43/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
44///
45/// Example:
46/// ```rust
47/// use asn1_rs::*;
48///
49/// #[derive(BerSequence)]
50/// #[debug_derive]
51/// struct S {
52///   a: u32,
53/// }
54/// ```
55pub use asn1_rs_derive::BerSequence;
56
57/// # DerSequence custom derive
58///
59/// `DerSequence` is a custom derive attribute, to derive both BER and DER [`Sequence`](super::Sequence) parsers automatically from the structure definition.
60/// This attribute will automatically derive implementations for the following traits:
61///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
62///   - [`Tagged`](super::Tagged)
63///   - [`CheckDerConstraints`](super::CheckDerConstraints)
64///   - [`FromDer`](super::FromDer)
65///
66/// `DerSequence` implies `BerSequence`, and will conflict with this custom derive.
67///
68/// Parsers will be automatically derived from struct fields. Every field type must implement the [`FromDer`](super::FromDer) trait.
69///
70/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
71///
72/// ## Examples
73///
74/// To parse the following ASN.1 structure:
75/// <pre>
76/// S ::= SEQUENCE {
77///     a INTEGER(0..2^32),
78///     b INTEGER(0..2^16),
79///     c INTEGER(0..2^16),
80/// }
81/// </pre>
82///
83/// Define a structure and add the `DerSequence` derive:
84///
85/// ```rust
86/// use asn1_rs::*;
87///
88/// #[derive(DerSequence)]
89/// struct S {
90///   a: u32,
91///   b: u16,
92///   c: u16
93/// }
94/// ```
95///
96/// ## Debugging
97///
98/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
99///
100/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
101///
102/// Example:
103/// ```rust
104/// use asn1_rs::*;
105///
106/// #[derive(DerSequence)]
107/// #[debug_derive]
108/// struct S {
109///   a: u32,
110/// }
111/// ```
112pub use asn1_rs_derive::DerSequence;
113
114/// # BerSet custom derive
115///
116/// `BerSet` is a custom derive attribute, to derive a BER [`Set`](super::Set) parser automatically from the structure definition.
117/// This attribute will automatically derive implementations for the following traits:
118///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
119///   - [`Tagged`](super::Tagged)
120///
121/// `DerSet` implies `BerSet`, and will conflict with this custom derive. Use `BerSet` when you only want the
122/// above traits derived.
123///
124/// Parsers will be automatically derived from struct fields. Every field type must implement the [`FromBer`](super::FromBer) trait.
125///
126/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
127///
128/// ## Examples
129///
130/// To parse the following ASN.1 structure:
131/// <pre>
132/// S ::= SET {
133///     a INTEGER(0..2^32),
134///     b INTEGER(0..2^16),
135///     c INTEGER(0..2^16),
136/// }
137/// </pre>
138///
139/// Define a structure and add the `BerSet` derive:
140///
141/// ```rust
142/// use asn1_rs::*;
143///
144/// #[derive(BerSet)]
145/// struct S {
146///   a: u32,
147///   b: u16,
148///   c: u16
149/// }
150/// ```
151///
152/// ## Debugging
153///
154/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
155///
156/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
157///
158/// Example:
159/// ```rust
160/// use asn1_rs::*;
161///
162/// #[derive(BerSet)]
163/// #[debug_derive]
164/// struct S {
165///   a: u32,
166/// }
167/// ```
168pub use asn1_rs_derive::BerSet;
169
170/// # DerSet custom derive
171///
172/// `DerSet` is a custom derive attribute, to derive both BER and DER [`Set`](super::Set) parsers automatically from the structure definition.
173/// This attribute will automatically derive implementations for the following traits:
174///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
175///   - [`Tagged`](super::Tagged)
176///   - [`CheckDerConstraints`](super::CheckDerConstraints)
177///   - [`FromDer`](super::FromDer)
178///
179/// `DerSet` implies `BerSet`, and will conflict with this custom derive.
180///
181/// Parsers will be automatically derived from struct fields. Every field type must implement the [`FromDer`](super::FromDer) trait.
182///
183/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
184///
185/// ## Examples
186///
187/// To parse the following ASN.1 structure:
188/// <pre>
189/// S ::= SEt {
190///     a INTEGER(0..2^32),
191///     b INTEGER(0..2^16),
192///     c INTEGER(0..2^16),
193/// }
194/// </pre>
195///
196/// Define a structure and add the `DerSet` derive:
197///
198/// ```rust
199/// use asn1_rs::*;
200///
201/// #[derive(DerSet)]
202/// struct S {
203///   a: u32,
204///   b: u16,
205///   c: u16
206/// }
207/// ```
208///
209/// ## Debugging
210///
211/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
212///
213/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
214///
215/// Example:
216/// ```rust
217/// use asn1_rs::*;
218///
219/// #[derive(DerSet)]
220/// #[debug_derive]
221/// struct S {
222///   a: u32,
223/// }
224/// ```
225pub use asn1_rs_derive::DerSet;
226
227/// # BerAlias custom derive
228///
229/// `BerAlias` is a custom derive attribute, to derive a BER object parser automatically from the structure definition.
230/// This attribute will automatically derive implementations for the following traits:
231///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
232///   - [`Tagged`](super::Tagged)
233///   - [`CheckDerConstraints`](super::CheckDerConstraints)
234///   - [`FromDer`](super::FromDer)
235///
236/// `DerAlias` implies `BerAlias`, and will conflict with this custom derive. Use `BerAlias` when you only want the
237/// above traits derived.
238///
239/// When defining alias, only unnamed (tuple) structs with one field are supported.
240///
241/// Parser will be automatically derived from the struct field. This field type must implement the `TryFrom<Any>` trait.
242///
243/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
244///
245/// ## Examples
246///
247/// To parse the following ASN.1 object:
248/// <pre>
249/// MyInt ::= INTEGER(0..2^32)
250/// </pre>
251///
252/// Define a structure and add the `BerAlias` derive:
253///
254/// ```rust
255/// use asn1_rs::*;
256///
257/// #[derive(BerAlias)]
258/// struct S(pub u32);
259/// ```
260///
261/// ## Debugging
262///
263/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
264///
265/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
266///
267/// Example:
268/// ```rust
269/// use asn1_rs::*;
270///
271/// #[derive(BerAlias)]
272/// #[debug_derive]
273/// struct S(pub u32);
274/// ```
275pub use asn1_rs_derive::BerAlias;
276
277/// # DerAlias custom derive
278///
279/// `DerAlias` is a custom derive attribute, to derive a DER object parser automatically from the structure definition.
280/// This attribute will automatically derive implementations for the following traits:
281///   - [`TryFrom<Any>`](super::Any), also providing [`FromBer`](super::FromBer)
282///   - [`Tagged`](super::Tagged)
283///
284/// `DerAlias` implies `BerAlias`, and will conflict with this custom derive.
285///
286/// When defining alias, only unnamed (tuple) structs with one field are supported.
287///
288/// Parser will be automatically derived from the struct field. This field type must implement the `TryFrom<Any>` and `FromDer` traits.
289///
290/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
291///
292/// ## Examples
293///
294/// To parse the following ASN.1 object:
295/// <pre>
296/// MyInt ::= INTEGER(0..2^32)
297/// </pre>
298///
299/// Define a structure and add the `DerAlias` derive:
300///
301/// ```rust
302/// use asn1_rs::*;
303///
304/// #[derive(DerAlias)]
305/// struct S(pub u32);
306/// ```
307///
308/// ## Debugging
309///
310/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
311///
312/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
313///
314/// Example:
315/// ```rust
316/// use asn1_rs::*;
317///
318/// #[derive(DerAlias)]
319/// #[debug_derive]
320/// struct S(pub u32);
321/// ```
322pub use asn1_rs_derive::DerAlias;
323
324/// # ToStatic custom derive
325///
326/// `ToStatic` is a custom derive attribute, to derive the [`ToStatic`](ToStatic) trait automatically from the structure definition.
327///
328/// ## Example
329///
330/// ```rust
331/// use asn1_rs::ToStatic;
332/// use std::borrow::Cow;
333///
334/// #[derive(ToStatic)]
335/// struct S<'a>(pub Cow<'a, str>);
336/// ```
337///
338/// ## Debugging
339///
340/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
341///
342/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
343///
344/// Example:
345/// ```rust
346/// use asn1_rs::ToStatic;
347/// use std::borrow::Cow;
348///
349/// #[derive(ToStatic)]
350/// #[debug_derive]
351/// struct S<'a>(pub Cow<'a, str>);
352/// ```
353pub use asn1_rs_derive::ToStatic;
354
355/// # ToDerSequence custom derive
356///
357/// `ToDerSequence` is a custom derive attribute, to derive both DER [`Sequence`](super::Sequence) serialization automatically from the structure definition.
358/// This attribute will automatically derive implementations for the following traits:
359///   - [`ToDer`](super::ToDer)
360///
361/// Serialization will be automatically derived from struct fields. Every field type must implement the [`ToDer`](super::ToDer) trait.
362///
363/// See [`derive`](crate::doc::derive) documentation for more examples and documentation.
364///
365/// ## Examples
366///
367/// To serialize the following ASN.1 structure:
368/// <pre>
369/// S ::= SEQUENCE {
370///     a INTEGER(0..2^32),
371///     b INTEGER(0..2^16),
372///     c INTEGER(0..2^16),
373/// }
374/// </pre>
375///
376/// Define a structure and add the `DerSequence` derive:
377///
378#[cfg_attr(feature = "std", doc = r#"```rust"#)]
379#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
380/// use asn1_rs::*;
381///
382/// #[derive(DerSequence, ToDerSequence)]
383/// struct S {
384///   a: u32,
385///   b: u16,
386///   c: u16
387/// }
388///
389/// let s = S { a: 1, b: 2, c: 3 };
390/// let data = s.to_der_vec().expect("Serialization failed");
391/// ```
392///
393/// ## Debugging
394///
395/// To help debugging the generated code, the `#[debug_derive]` attribute has been added.
396///
397/// When this attribute is specified, the generated code will be printed to `stderr` during compilation.
398///
399/// Example:
400/// ```rust
401/// use asn1_rs::*;
402///
403/// #[derive(DerSequence, ToDerSequence)]
404/// #[debug_derive]
405/// struct S {
406///   a: u32,
407/// }
408/// ```
409pub use asn1_rs_derive::ToDerSequence;