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
//! Codec traits for encoding and decoding values.
//!
//! Codecs are marker types (e.g., [`Cbor`](cbor::Cbor), [`Json`](json::Json))
//! that implement [`Encode`] and [`Decode`] for the value types they support.
//!
//! The marker types are always available regardless of feature flags.
//! Enable the corresponding feature (`minicbor`, `serde_json`) to get
//! [`Encode`]/[`Decode`] implementations backed by a concrete serialization
//! library.
use Vec;
/// A codec that can encode values of type `T` to bytes.
/// A codec that can decode bytes into values of type `T`.
/// Marker trait for codecs that produce deterministic (canonical) encodings.
///
/// A canonical codec guarantees that the same value always encodes to
/// identical bytes, which is essential for content-addressed hashing.
/// Identity codec that passes bytes through unchanged.
///
/// Useful for testing or when values are already serialized.
///
/// # Example
///
/// ```
/// # #[cfg(feature = "sha2")]
/// # {
/// use evidence::digest::{Digest, sha2::Sha256};
/// use evidence::codec::Identity;
///
/// let data = b"hello world";
/// let digest: Digest<[u8; 11], Sha256, Identity> = Digest::hash(data);
/// assert_eq!(digest.as_bytes().len(), 32);
/// # }
/// ```
/// Error returned when decoding with Identity codec fails due to length mismatch.
/// A relaxed codec marker that tracks the underlying format without requiring encoding.
///
/// Use this for deserialized values where you know the codec but don't have
/// (or don't need) the encoder implementation.
///
/// # Example
///
/// ```
/// # #[cfg(feature = "sha2")]
/// # {
/// use evidence::digest::{Digest, DigestUnchecked, sha2::Sha256};
/// use evidence::codec::Relaxed;
/// use hybrid_array::Array;
///
/// // You received a digest over the network, encoded as CBOR
/// enum Cbor {}
///
/// let bytes: Array<u8, _> = Array::try_from([0u8; 32].as_slice()).unwrap();
///
/// // Use Relaxed<Cbor> to track the format without needing Encode impl
/// let digest: Digest<String, Sha256, Relaxed<Cbor>> = Digest::from_unchecked_array(bytes);
///
/// // This would NOT compile — Relaxed<Cbor> doesn't implement Encode:
/// // let d: Digest<String, Sha256, Relaxed<Cbor>> = Digest::hash(&my_string);
/// # }
/// ```
;