Validates BSATN `byte` to conform to `seed`. The BSATN can originate from untrusted sources, e.g., from module code. This also means that e.g., a `BytesKey` can be trusted to hold valid BSATN for the key type, which we can rely on in e.g., `decode_algebraic_value`, which isn't used in a context where it would be appropriate to fail. Another reason to validate is that we wish for `BytesKey` to be
(seed: &'a S, mut bytes: &'de [u8])
| 183 | /// since if all parts that are encoded into it are valid according to a key type, |
| 184 | /// then `bytes` cannot be longer than `N`. |
| 185 | fn validate<'a, 'de, S: 'a + ?Sized>(seed: &'a S, mut bytes: &'de [u8]) -> DecodeResult<()> |
| 186 | where |
| 187 | WithTypespace<'a, S>: DeserializeSeed<'de>, |
| 188 | { |
| 189 | WithTypespace::empty(seed).validate(Deserializer::new(&mut bytes))?; |
| 190 | |
| 191 | if !bytes.is_empty() { |
| 192 | return Err(DecodeError::custom(format_args!( |
| 193 | "after decoding, there are {} extra bytes", |
| 194 | bytes.len() |
| 195 | ))); |
| 196 | } |
| 197 | |
| 198 | Ok(()) |
| 199 | } |
| 200 | |
| 201 | impl<const N: usize> BytesKey<N> { |
| 202 | fn new(length: usize, bytes: [u8; N]) -> Self { |
no test coverage detected
searching dependent graphs…