/rust/registry/src/index.crates.io-6f17d22bba15001f/der-0.7.10/src/asn1/choice.rs
Line | Count | Source (jump to first uncovered line) |
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 | 0 | fn can_decode(tag: Tag) -> bool { |
24 | 0 | T::TAG == tag |
25 | 0 | } Unexecuted instantiation: <der::asn1::ia5_string::allocation::Ia5String as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::teletex_string::allocation::TeletexString as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::integer::uint::UintRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::bit_string::BitStringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <i8 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <u8 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <i32 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <u32 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <i128 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <u128 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <i16 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <u16 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <i64 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <u64 as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::ia5_string::Ia5StringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::utc_time::UtcTime as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::utf8_string::Utf8StringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::generalized_time::GeneralizedTime as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::integer::int::allocating::Int as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::integer::uint::allocating::Uint as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::integer::int::IntRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::octet_string::OctetStringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::null::Null as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::bit_string::allocating::BitString as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::octet_string::allocating::OctetString as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::teletex_string::TeletexStringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::videotex_string::VideotexStringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::printable_string::PrintableStringRef as der::asn1::choice::Choice>::can_decode Unexecuted instantiation: <der::asn1::printable_string::allocation::PrintableString as der::asn1::choice::Choice>::can_decode |
26 | | } |