aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / der / src / asn1 / choice.rs
| 1 | //! ASN.1 `CHOICE` support. |
| 2 | |
| 3 | use crate::{Decode, FixedTag, Tag, Tagged}; |
| 4 | |
| 5 | /// ASN.1 `CHOICE` denotes a union of one or more possible alternatives. |
| 6 | /// |
| 7 | /// The types MUST have distinct tags. |
| 8 | /// |
| 9 | /// This crate models choice as a trait, with a blanket impl for all types |
| 10 | /// which impl `Decode + FixedTag` (i.e. they are modeled as a `CHOICE` |
| 11 | /// with only one possible variant) |
| 12 | pub trait Choice<'a>: Decode<'a> + Tagged { |
| 13 | /// Is the provided [`Tag`] decodable as a variant of this `CHOICE`? |
| 14 | fn can_decode(tag: Tag) -> bool; |
| 15 | } |
| 16 | |
| 17 | /// This blanket impl allows any [`Tagged`] type to function as a [`Choice`] |
| 18 | /// with a single alternative. |
| 19 | impl<'a, T> Choice<'a> for T |
| 20 | where |
| 21 | T: Decode<'a> + FixedTag, |
| 22 | { |
| 23 | fn can_decode(tag: Tag) -> bool { |
| 24 | T::TAG == tag |
| 25 | } |
| 26 | } |