asn1_rs/asn1_types/tagged/application.rs
1use crate::{Class, Explicit, Implicit, TaggedValue};
2
3/// A helper object to parse `[APPLICATION n] EXPLICIT T`
4///
5/// A helper object implementing [`FromBer`](crate::FromBer) and [`FromDer`](crate::FromDer), to
6/// parse explicit application-tagged values.
7///
8/// # Examples
9///
10/// To parse a `[APPLICATION 0] EXPLICIT INTEGER` object:
11///
12/// ```rust
13/// use asn1_rs::{ApplicationExplicit, Error, FromBer, Integer, TaggedValue};
14///
15/// let bytes = &[0x60, 0x03, 0x2, 0x1, 0x2];
16///
17/// // If tagged object is present (and has expected tag), parsing succeeds:
18/// let (_, tagged) = ApplicationExplicit::<Integer, Error, 0>::from_ber(bytes).unwrap();
19/// assert_eq!(tagged, TaggedValue::explicit(Integer::from(2)));
20/// ```
21pub type ApplicationExplicit<T, E, const TAG: u32> =
22 TaggedValue<T, E, Explicit, { Class::APPLICATION }, TAG>;
23
24/// A helper object to parse `[APPLICATION n] IMPLICIT T`
25///
26/// A helper object implementing [`FromBer`](crate::FromBer) and [`FromDer`](crate::FromDer), to
27/// parse explicit application-tagged values.
28///
29/// # Examples
30///
31/// To parse a `[APPLICATION 0] IMPLICIT INTEGER` object:
32///
33/// ```rust
34/// use asn1_rs::{ApplicationImplicit, Error, FromBer, Integer, TaggedValue};
35///
36/// let bytes = &[0x60, 0x1, 0x2];
37///
38/// let (_, tagged) = ApplicationImplicit::<Integer, Error, 0>::from_ber(bytes).unwrap();
39/// assert_eq!(tagged, TaggedValue::implicit(Integer::from(2_u8)));
40/// ```
41pub type ApplicationImplicit<T, E, const TAG: u32> =
42 TaggedValue<T, E, Implicit, { Class::APPLICATION }, TAG>;