Struct OptTaggedParser
pub struct OptTaggedParser {
pub class: Class,
pub tag: Tag,
}crypto and std only.Expand description
Helper object to parse TAGGED OPTIONAL types (explicit or implicit)
This object can be used similarly to a builder pattern, to specify the expected class and tag of the object to parse, and the content parsing function.
The content parsing function takes two arguments: the outer header, and the data.
It can be used for both EXPLICIT or IMPLICIT tagged objects by using parsing functions that expect a header (or not) in the contents.
The OptTaggedParser::from method is a shortcut to build an object with ContextSpecific
class and the given tag. The OptTaggedParser::new method is more generic.
See also OptTaggedExplicit and OptTaggedImplicit for alternatives that implement FromBer/
FromDer.
§Examples
To parse a [APPLICATION 0] EXPLICIT INTEGER OPTIONAL object:
use asn1_rs::{Class, FromDer, Integer, Tag, OptTaggedParser};
let bytes = &[0x60, 0x03, 0x2, 0x1, 0x2];
let (_, tagged) = OptTaggedParser::new(Class::Application, Tag(0))
.parse_der(bytes, |_, data| Integer::from_der(data))
.unwrap();
assert_eq!(tagged, Some(Integer::from(2)));To parse a [0] IMPLICIT INTEGER OPTIONAL object:
use asn1_rs::{Error, Integer, OptTaggedParser};
let bytes = &[0xa0, 0x1, 0x2];
let (_, tagged) = OptTaggedParser::from(0)
.parse_der::<_, Error, _>(bytes, |_, data| Ok((&[], Integer::new(data))))
.unwrap();
assert_eq!(tagged, Some(Integer::from(2)));Fields§
§class: ClassThe expected class for the object to parse
tag: TagThe expected tag for the object to parse
Implementations§
§impl OptTaggedParser
impl OptTaggedParser
pub const fn new(class: Class, tag: Tag) -> OptTaggedParser
pub const fn new(class: Class, tag: Tag) -> OptTaggedParser
Build a new OptTaggedParser object.
If using Class::ContextSpecific, using OptTaggedParser::from with either a Tag or u32 is
a shorter way to build this object.
pub const fn universal(tag: u32) -> OptTaggedParser
pub const fn tagged(tag: u32) -> OptTaggedParser
pub const fn application(tag: u32) -> OptTaggedParser
pub const fn private(tag: u32) -> OptTaggedParser
pub fn parse_ber<'a, T, E, F>(
&self,
bytes: &'a [u8],
f: F,
) -> Result<(&'a [u8], Option<T>), Err<E>>
pub fn parse_ber<'a, T, E, F>( &self, bytes: &'a [u8], f: F, ) -> Result<(&'a [u8], Option<T>), Err<E>>
Parse input as BER, and apply the provided function to parse object.
Returns the remaining bytes, and Some(T) if expected tag was found, else None.
This function returns an error if tag was found but has a different class, or if parsing fails.
§Examples
To parse a [0] EXPLICIT INTEGER OPTIONAL object:
use asn1_rs::{FromBer, Integer, OptTaggedParser};
let bytes = &[0xa0, 0x03, 0x2, 0x1, 0x2];
let (_, tagged) = OptTaggedParser::from(0)
.parse_ber(bytes, |_, data| Integer::from_ber(data))
.unwrap();
assert_eq!(tagged, Some(Integer::from(2)));pub fn parse_der<'a, T, E, F>(
&self,
bytes: &'a [u8],
f: F,
) -> Result<(&'a [u8], Option<T>), Err<E>>
pub fn parse_der<'a, T, E, F>( &self, bytes: &'a [u8], f: F, ) -> Result<(&'a [u8], Option<T>), Err<E>>
Parse input as DER, and apply the provided function to parse object.
Returns the remaining bytes, and Some(T) if expected tag was found, else None.
This function returns an error if tag was found but has a different class, or if parsing fails.
§Examples
To parse a [0] EXPLICIT INTEGER OPTIONAL object:
use asn1_rs::{FromDer, Integer, OptTaggedParser};
let bytes = &[0xa0, 0x03, 0x2, 0x1, 0x2];
let (_, tagged) = OptTaggedParser::from(0)
.parse_der(bytes, |_, data| Integer::from_der(data))
.unwrap();
assert_eq!(tagged, Some(Integer::from(2)));Trait Implementations§
§impl Debug for OptTaggedParser
impl Debug for OptTaggedParser
§impl From<Tag> for OptTaggedParser
impl From<Tag> for OptTaggedParser
§fn from(tag: Tag) -> OptTaggedParser
fn from(tag: Tag) -> OptTaggedParser
Build a TaggedOptional object with class ContextSpecific and given tag
§impl From<u32> for OptTaggedParser
impl From<u32> for OptTaggedParser
§fn from(tag: u32) -> OptTaggedParser
fn from(tag: u32) -> OptTaggedParser
Build a TaggedOptional object with class ContextSpecific and given tag
Auto Trait Implementations§
impl Freeze for OptTaggedParser
impl RefUnwindSafe for OptTaggedParser
impl Send for OptTaggedParser
impl Sync for OptTaggedParser
impl Unpin for OptTaggedParser
impl UnsafeUnpin for OptTaggedParser
impl UnwindSafe for OptTaggedParser
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more