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
//! Encoding trait
use crateEncoder;
use crateResult;
/// Trait for types that can be encoded to ASN.1.
///
/// # Implementing this trait
///
/// Both methods must be consistent: `encoded_len` must return **exactly** the
/// number of bytes that `encode` will write to the encoder. If they disagree,
/// [`Encoder::encode_with_tag`] will write an incorrect length prefix, silently
/// producing malformed output.
///
/// A typical implementation computes `tag_len + length_field_len + value_len`,
/// where `length_field_len` is obtained via [`Length::Definite(n).encoded_len()`].
///
/// [`Encoder::encode_with_tag`]: crate::Encoder::encode_with_tag
/// [`Length::Definite(n).encoded_len()`]: crate::Length::encoded_len
/// Blanket implementation of `Encode` for shared references.
///
/// Forwarding through `&T` lets callers pass a reference where an owned value
/// would otherwise be required — in particular, the generated code produced by
/// `#[derive(Asn1Sequence)]` and friends wraps fields in `ExplicitTag<&T>` /
/// `ImplicitTag<&T>` to avoid cloning the field value just for tagging.