/rust/registry/src/index.crates.io-1949cf8c6b5b557f/der-parser-9.0.0/src/ber/multi.rs
Line | Count | Source |
1 | | use crate::ber::*; |
2 | | use crate::error::*; |
3 | | use asn1_rs::Tag; |
4 | | use nom::bytes::complete::take; |
5 | | use nom::combinator::{all_consuming, complete, cut, map}; |
6 | | use nom::error::ParseError; |
7 | | use nom::multi::many0; |
8 | | use nom::{Err, IResult}; |
9 | | |
10 | | /// Parse a SEQUENCE OF object |
11 | | /// |
12 | | /// Given a subparser for a BER type, parse a sequence of identical objects. |
13 | | /// |
14 | | /// ```rust |
15 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_sequence_of, BerObject}; |
16 | | /// # use der_parser::error::BerResult; |
17 | | /// # |
18 | | /// /// Read a SEQUENCE OF INTEGER |
19 | | /// fn parser(i:&[u8]) -> BerResult<BerObject> { |
20 | | /// parse_ber_sequence_of(parse_ber_integer)(i) |
21 | | /// } |
22 | | /// |
23 | | /// # let empty = &b""[..]; |
24 | | /// # let bytes = [ 0x30, 0x0a, |
25 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
26 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
27 | | /// # ]; |
28 | | /// # let expected = BerObject::from_seq(vec![ |
29 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
30 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
31 | | /// # ]); |
32 | | /// # assert_eq!(parser(&bytes), Ok((empty, expected))); |
33 | | /// let (rem, v) = parser(&bytes).expect("parsing failed"); |
34 | | /// ``` |
35 | 0 | pub fn parse_ber_sequence_of<'a, F>(f: F) -> impl FnMut(&'a [u8]) -> BerResult |
36 | 0 | where |
37 | 0 | F: Fn(&'a [u8]) -> BerResult, |
38 | | { |
39 | 0 | map(parse_ber_sequence_of_v(f), BerObject::from_seq) |
40 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of::<_> Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of::<_> |
41 | | |
42 | | /// Parse a SEQUENCE OF object (returning a vec) |
43 | | /// |
44 | | /// Given a subparser for a BER type, parse a sequence of identical objects. |
45 | | /// |
46 | | /// This differs from `parse_ber_sequence_of` in the parse function and return type. |
47 | | /// |
48 | | /// ```rust |
49 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_sequence_of_v, BerObject}; |
50 | | /// # use der_parser::error::BerResult; |
51 | | /// # |
52 | | /// /// Read a SEQUENCE OF INTEGER |
53 | | /// fn parser(i:&[u8]) -> BerResult<Vec<BerObject>> { |
54 | | /// parse_ber_sequence_of_v(parse_ber_integer)(i) |
55 | | /// } |
56 | | /// |
57 | | /// # let empty = &b""[..]; |
58 | | /// # let bytes = [ 0x30, 0x0a, |
59 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
60 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
61 | | /// # ]; |
62 | | /// # let expected = vec![ |
63 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
64 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
65 | | /// # ]; |
66 | | /// let (rem, v) = parser(&bytes).expect("parsing failed"); |
67 | | /// # assert_eq!(v, expected); |
68 | | /// ``` |
69 | 45.7k | pub fn parse_ber_sequence_of_v<'a, T, F, E>( |
70 | 45.7k | f: F, |
71 | 45.7k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> |
72 | 45.7k | where |
73 | 45.7k | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, |
74 | 45.7k | E: ParseError<&'a [u8]> + From<BerError>, |
75 | | { |
76 | 45.7k | let mut subparser = all_consuming(many0(complete(cut(f)))); |
77 | 45.7k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 77 | 2.13k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) |
der_parser::ber::multi::parse_ber_sequence_of_v::<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 77 | 1 | parse_ber_sequence_defined_g(move |data, _| subparser(data)) |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<_, _, _>::{closure#0}der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 77 | 109 | parse_ber_sequence_defined_g(move |data, _| subparser(data)) |
der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 77 | 8.50k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) |
der_parser::ber::multi::parse_ber_sequence_of_v::<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 77 | 24.0k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<_, _, _>::{closure#0} |
78 | 45.7k | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error> der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error> Line | Count | Source | 69 | 6.81k | pub fn parse_ber_sequence_of_v<'a, T, F, E>( | 70 | 6.81k | f: F, | 71 | 6.81k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> | 72 | 6.81k | where | 73 | 6.81k | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, | 74 | 6.81k | E: ParseError<&'a [u8]> + From<BerError>, | 75 | | { | 76 | 6.81k | let mut subparser = all_consuming(many0(complete(cut(f)))); | 77 | 6.81k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) | 78 | 6.81k | } |
der_parser::ber::multi::parse_ber_sequence_of_v::<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error> Line | Count | Source | 69 | 1 | pub fn parse_ber_sequence_of_v<'a, T, F, E>( | 70 | 1 | f: F, | 71 | 1 | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> | 72 | 1 | where | 73 | 1 | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, | 74 | 1 | E: ParseError<&'a [u8]> + From<BerError>, | 75 | | { | 76 | 1 | let mut subparser = all_consuming(many0(complete(cut(f)))); | 77 | 1 | parse_ber_sequence_defined_g(move |data, _| subparser(data)) | 78 | 1 | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<_, _, _> der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error> Line | Count | Source | 69 | 111 | pub fn parse_ber_sequence_of_v<'a, T, F, E>( | 70 | 111 | f: F, | 71 | 111 | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> | 72 | 111 | where | 73 | 111 | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, | 74 | 111 | E: ParseError<&'a [u8]> + From<BerError>, | 75 | | { | 76 | 111 | let mut subparser = all_consuming(many0(complete(cut(f)))); | 77 | 111 | parse_ber_sequence_defined_g(move |data, _| subparser(data)) | 78 | 111 | } |
der_parser::ber::multi::parse_ber_sequence_of_v::<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error> Line | Count | Source | 69 | 11.3k | pub fn parse_ber_sequence_of_v<'a, T, F, E>( | 70 | 11.3k | f: F, | 71 | 11.3k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> | 72 | 11.3k | where | 73 | 11.3k | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, | 74 | 11.3k | E: ParseError<&'a [u8]> + From<BerError>, | 75 | | { | 76 | 11.3k | let mut subparser = all_consuming(many0(complete(cut(f)))); | 77 | 11.3k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) | 78 | 11.3k | } |
der_parser::ber::multi::parse_ber_sequence_of_v::<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error> Line | Count | Source | 69 | 27.4k | pub fn parse_ber_sequence_of_v<'a, T, F, E>( | 70 | 27.4k | f: F, | 71 | 27.4k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> | 72 | 27.4k | where | 73 | 27.4k | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, | 74 | 27.4k | E: ParseError<&'a [u8]> + From<BerError>, | 75 | | { | 76 | 27.4k | let mut subparser = all_consuming(many0(complete(cut(f)))); | 77 | 27.4k | parse_ber_sequence_defined_g(move |data, _| subparser(data)) | 78 | 27.4k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_of_v::<_, _, _> |
79 | | |
80 | | /// Parse a defined sequence of DER elements (function version) |
81 | | /// |
82 | | /// Given a list of expected parsers, apply them to build a DER sequence and |
83 | | /// return the remaining bytes and the built object. |
84 | | /// |
85 | | /// The remaining bytes point *after* the sequence: any bytes that are part of the sequence but not |
86 | | /// parsed are ignored. |
87 | | /// |
88 | | /// The object header is not available to the parsing function, and the returned type is always a |
89 | | /// `BerObject`. |
90 | | /// For a generic version, see |
91 | | /// [`parse_ber_sequence_defined_g`](fn.parse_ber_sequence_defined_g.html). |
92 | | /// |
93 | | /// # Examples |
94 | | /// |
95 | | /// Parsing a sequence of identical types (same as `parse_ber_sequence_of`): |
96 | | /// |
97 | | /// ```rust |
98 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_sequence_defined, BerObject}; |
99 | | /// # use der_parser::error::BerResult; |
100 | | /// use nom::combinator::complete; |
101 | | /// use nom::multi::many1; |
102 | | /// |
103 | | /// fn localparse_seq(i:&[u8]) -> BerResult { |
104 | | /// parse_ber_sequence_defined( |
105 | | /// many1(complete(parse_ber_integer)) |
106 | | /// )(i) |
107 | | /// } |
108 | | /// |
109 | | /// # let empty = &b""[..]; |
110 | | /// # let bytes = [ 0x30, 0x0a, |
111 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
112 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
113 | | /// # ]; |
114 | | /// # let expected = BerObject::from_seq(vec![ |
115 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
116 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
117 | | /// # ]); |
118 | | /// # assert_eq!(localparse_seq(&bytes), Ok((empty, expected))); |
119 | | /// let (rem, v) = localparse_seq(&bytes).expect("parsing failed"); |
120 | | /// ``` |
121 | | /// |
122 | | /// Parsing a defined sequence with different types: |
123 | | /// |
124 | | /// ```rust |
125 | | /// # use der_parser::ber::*; |
126 | | /// # use der_parser::error::BerResult; |
127 | | /// use nom::combinator::map; |
128 | | /// use nom::sequence::tuple; |
129 | | /// |
130 | | /// /// Read a DER-encoded object: |
131 | | /// /// SEQUENCE { |
132 | | /// /// a INTEGER, |
133 | | /// /// b OCTETSTRING |
134 | | /// /// } |
135 | | /// fn localparse_seq(i:&[u8]) -> BerResult { |
136 | | /// parse_ber_sequence_defined( |
137 | | /// // the nom `tuple` combinator returns a tuple, so we have to map it |
138 | | /// // to a list |
139 | | /// map( |
140 | | /// tuple((parse_ber_integer, parse_ber_octetstring)), |
141 | | /// |(a, b)| vec![a, b] |
142 | | /// ) |
143 | | /// )(i) |
144 | | /// } |
145 | | /// |
146 | | /// # let empty = &b""[..]; |
147 | | /// # let bytes = [ 0x30, 0x0a, |
148 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
149 | | /// # 0x04, 0x03, 0x01, 0x00, 0x00, |
150 | | /// # ]; |
151 | | /// # let expected = BerObject::from_seq(vec![ |
152 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
153 | | /// # BerObject::from_obj(BerObjectContent::OctetString(b"\x01\x00\x00")), |
154 | | /// # ]); |
155 | | /// # assert_eq!(localparse_seq(&bytes), Ok((empty, expected))); |
156 | | /// let (rem, v) = localparse_seq(&bytes).expect("parsing failed"); |
157 | | /// ``` |
158 | 0 | pub fn parse_ber_sequence_defined<'a, F>(mut f: F) -> impl FnMut(&'a [u8]) -> BerResult |
159 | 0 | where |
160 | 0 | F: FnMut(&'a [u8]) -> BerResult<Vec<BerObject>>, |
161 | | { |
162 | 0 | map( |
163 | 0 | parse_ber_sequence_defined_g(move |data, _| f(data)), Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined::<_>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined::<_>::{closure#0} |
164 | | BerObject::from_seq, |
165 | | ) |
166 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined::<_> Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined::<_> |
167 | | |
168 | | /// Parse a defined SEQUENCE object (generic function) |
169 | | /// |
170 | | /// Given a parser for sequence content, apply it to build a DER sequence and |
171 | | /// return the remaining bytes and the built object. |
172 | | /// |
173 | | /// The remaining bytes point *after* the sequence: any bytes that are part of the sequence but not |
174 | | /// parsed are ignored. |
175 | | /// |
176 | | /// Unlike `parse_ber_sequence_defined`, this function allows returning any object or error type, |
177 | | /// and also passes the object header to the callback. |
178 | | /// |
179 | | /// # Examples |
180 | | /// |
181 | | /// Parsing a defined sequence with different types: |
182 | | /// |
183 | | /// ```rust |
184 | | /// # use der_parser::ber::*; |
185 | | /// # use der_parser::error::BerResult; |
186 | | /// # |
187 | | /// # #[derive(Debug, PartialEq)] |
188 | | /// pub struct MyObject<'a> { |
189 | | /// a: u32, |
190 | | /// b: &'a [u8], |
191 | | /// } |
192 | | /// |
193 | | /// /// Read a DER-encoded object: |
194 | | /// /// SEQUENCE { |
195 | | /// /// a INTEGER (0..4294967295), |
196 | | /// /// b OCTETSTRING |
197 | | /// /// } |
198 | | /// fn parse_myobject(i: &[u8]) -> BerResult<MyObject> { |
199 | | /// parse_ber_sequence_defined_g( |
200 | | /// |i:&[u8], _| { |
201 | | /// let (i, a) = parse_ber_u32(i)?; |
202 | | /// let (i, obj) = parse_ber_octetstring(i)?; |
203 | | /// let b = obj.as_slice().unwrap(); |
204 | | /// Ok((i, MyObject{ a, b })) |
205 | | /// } |
206 | | /// )(i) |
207 | | /// } |
208 | | /// |
209 | | /// # let empty = &b""[..]; |
210 | | /// # let bytes = [ 0x30, 0x0a, |
211 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
212 | | /// # 0x04, 0x03, 0x01, 0x00, 0x00, |
213 | | /// # ]; |
214 | | /// # let expected = MyObject { |
215 | | /// # a: 0x010001, |
216 | | /// # b: &[01, 00, 00] |
217 | | /// # }; |
218 | | /// # assert_eq!(parse_myobject(&bytes), Ok((empty, expected))); |
219 | | /// let (rem, v) = parse_myobject(&bytes).expect("parsing failed"); |
220 | | /// ``` |
221 | 45.7k | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( |
222 | 45.7k | mut f: F, |
223 | 45.7k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> |
224 | 45.7k | where |
225 | 45.7k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, |
226 | 45.7k | E: ParseError<&'a [u8]> + From<BerError>, |
227 | | { |
228 | 45.7k | parse_ber_container(move |i, hdr| { |
229 | 36.2k | hdr.assert_tag(Tag::Sequence) |
230 | 36.2k | .map_err(|e| Err::Error(e.into()))?; Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}Line | Count | Source | 230 | 468 | .map_err(|e| Err::Error(e.into()))?; |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _>::{closure#0}::{closure#0}der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}Line | Count | Source | 230 | 545 | .map_err(|e| Err::Error(e.into()))?; |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}Line | Count | Source | 230 | 1 | .map_err(|e| Err::Error(e.into()))?; |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}::{closure#0}Line | Count | Source | 230 | 443 | .map_err(|e| Err::Error(e.into()))?; |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _>::{closure#0}::{closure#0} |
231 | 34.7k | f(i, hdr) |
232 | 36.2k | }) der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 228 | 1 | parse_ber_container(move |i, hdr| { | 229 | 1 | hdr.assert_tag(Tag::Sequence) | 230 | 1 | .map_err(|e| Err::Error(e.into()))?; | 231 | 1 | f(i, hdr) | 232 | 1 | }) |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 228 | 2.59k | parse_ber_container(move |i, hdr| { | 229 | 2.59k | hdr.assert_tag(Tag::Sequence) | 230 | 2.59k | .map_err(|e| Err::Error(e.into()))?; | 231 | 2.13k | f(i, hdr) | 232 | 2.59k | }) |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _>::{closure#0}der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 228 | 24.5k | parse_ber_container(move |i, hdr| { | 229 | 24.5k | hdr.assert_tag(Tag::Sequence) | 230 | 24.5k | .map_err(|e| Err::Error(e.into()))?; | 231 | 24.0k | f(i, hdr) | 232 | 24.5k | }) |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 228 | 110 | parse_ber_container(move |i, hdr| { | 229 | 110 | hdr.assert_tag(Tag::Sequence) | 230 | 110 | .map_err(|e| Err::Error(e.into()))?; | 231 | 109 | f(i, hdr) | 232 | 110 | }) |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 228 | 8.94k | parse_ber_container(move |i, hdr| { | 229 | 8.94k | hdr.assert_tag(Tag::Sequence) | 230 | 8.94k | .map_err(|e| Err::Error(e.into()))?; | 231 | 8.50k | f(i, hdr) | 232 | 8.94k | }) |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _>::{closure#0} |
233 | 45.7k | } der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 221 | 1 | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( | 222 | 1 | mut f: F, | 223 | 1 | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 224 | 1 | where | 225 | 1 | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 226 | 1 | E: ParseError<&'a [u8]> + From<BerError>, | 227 | | { | 228 | 1 | parse_ber_container(move |i, hdr| { | 229 | | hdr.assert_tag(Tag::Sequence) | 230 | | .map_err(|e| Err::Error(e.into()))?; | 231 | | f(i, hdr) | 232 | | }) | 233 | 1 | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 221 | 6.81k | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( | 222 | 6.81k | mut f: F, | 223 | 6.81k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 224 | 6.81k | where | 225 | 6.81k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 226 | 6.81k | E: ParseError<&'a [u8]> + From<BerError>, | 227 | | { | 228 | 6.81k | parse_ber_container(move |i, hdr| { | 229 | | hdr.assert_tag(Tag::Sequence) | 230 | | .map_err(|e| Err::Error(e.into()))?; | 231 | | f(i, hdr) | 232 | | }) | 233 | 6.81k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _> der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 221 | 27.4k | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( | 222 | 27.4k | mut f: F, | 223 | 27.4k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 224 | 27.4k | where | 225 | 27.4k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 226 | 27.4k | E: ParseError<&'a [u8]> + From<BerError>, | 227 | | { | 228 | 27.4k | parse_ber_container(move |i, hdr| { | 229 | | hdr.assert_tag(Tag::Sequence) | 230 | | .map_err(|e| Err::Error(e.into()))?; | 231 | | f(i, hdr) | 232 | | }) | 233 | 27.4k | } |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 221 | 111 | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( | 222 | 111 | mut f: F, | 223 | 111 | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 224 | 111 | where | 225 | 111 | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 226 | 111 | E: ParseError<&'a [u8]> + From<BerError>, | 227 | | { | 228 | 111 | parse_ber_container(move |i, hdr| { | 229 | | hdr.assert_tag(Tag::Sequence) | 230 | | .map_err(|e| Err::Error(e.into()))?; | 231 | | f(i, hdr) | 232 | | }) | 233 | 111 | } |
der_parser::ber::multi::parse_ber_sequence_defined_g::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 221 | 11.3k | pub fn parse_ber_sequence_defined_g<'a, O, F, E>( | 222 | 11.3k | mut f: F, | 223 | 11.3k | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 224 | 11.3k | where | 225 | 11.3k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 226 | 11.3k | E: ParseError<&'a [u8]> + From<BerError>, | 227 | | { | 228 | 11.3k | parse_ber_container(move |i, hdr| { | 229 | | hdr.assert_tag(Tag::Sequence) | 230 | | .map_err(|e| Err::Error(e.into()))?; | 231 | | f(i, hdr) | 232 | | }) | 233 | 11.3k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_sequence_defined_g::<_, _, _> |
234 | | |
235 | | /// Parse a SET OF object |
236 | | /// |
237 | | /// Given a subparser for a BER type, parse a set of identical objects. |
238 | | /// |
239 | | /// ```rust |
240 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_set_of, BerObject}; |
241 | | /// # use der_parser::error::BerResult; |
242 | | /// # |
243 | | /// /// Read a SET OF INTEGER |
244 | | /// fn parser(i:&[u8]) -> BerResult<BerObject> { |
245 | | /// parse_ber_set_of(parse_ber_integer)(i) |
246 | | /// } |
247 | | /// |
248 | | /// # let empty = &b""[..]; |
249 | | /// # let bytes = [ 0x31, 0x0a, |
250 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
251 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
252 | | /// # ]; |
253 | | /// # let expected = BerObject::from_set(vec![ |
254 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
255 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
256 | | /// # ]); |
257 | | /// # assert_eq!(parser(&bytes), Ok((empty, expected))); |
258 | | /// let (rem, v) = parser(&bytes).expect("parsing failed"); |
259 | | /// ``` |
260 | 0 | pub fn parse_ber_set_of<'a, F>(f: F) -> impl FnMut(&'a [u8]) -> BerResult |
261 | 0 | where |
262 | 0 | F: Fn(&'a [u8]) -> BerResult, |
263 | | { |
264 | 0 | map(parse_ber_set_of_v(f), BerObject::from_set) |
265 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of::<_> Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of::<_> |
266 | | |
267 | | /// Parse a SET OF object (returning a vec) |
268 | | /// |
269 | | /// Given a subparser for a BER type, parse a set of identical objects. |
270 | | /// |
271 | | /// This differs from `parse_ber_set_of` in the parse function and return type. |
272 | | /// |
273 | | /// ```rust |
274 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_set_of_v, BerObject}; |
275 | | /// # use der_parser::error::BerResult; |
276 | | /// # |
277 | | /// /// Read a SET OF INTEGER |
278 | | /// fn parser(i:&[u8]) -> BerResult<Vec<BerObject>> { |
279 | | /// parse_ber_set_of_v(parse_ber_integer)(i) |
280 | | /// } |
281 | | /// |
282 | | /// # let empty = &b""[..]; |
283 | | /// # let bytes = [ 0x31, 0x0a, |
284 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
285 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
286 | | /// # ]; |
287 | | /// # let expected = vec![ |
288 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
289 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
290 | | /// # ]; |
291 | | /// let (rem, v) = parser(&bytes).expect("parsing failed"); |
292 | | /// # assert_eq!(v, expected); |
293 | | /// ``` |
294 | 0 | pub fn parse_ber_set_of_v<'a, T, F, E>(f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], Vec<T>, E> |
295 | 0 | where |
296 | 0 | F: FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>, |
297 | 0 | E: ParseError<&'a [u8]> + From<BerError>, |
298 | | { |
299 | 0 | let mut subparser = all_consuming(many0(complete(cut(f)))); |
300 | 0 | parse_ber_set_defined_g(move |data, _| subparser(data)) Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of_v::<_, _, _>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of_v::<_, _, _>::{closure#0} |
301 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of_v::<_, _, _> Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_of_v::<_, _, _> |
302 | | |
303 | | /// Parse a defined set of DER elements (function version) |
304 | | /// |
305 | | /// Given a list of expected parsers, apply them to build a DER set and |
306 | | /// return the remaining bytes and the built object. |
307 | | /// |
308 | | /// The remaining bytes point *after* the set: any bytes that are part of the sequence but not |
309 | | /// parsed are ignored. |
310 | | /// The nom combinator `all_consuming` can be used to ensure all the content is parsed. |
311 | | /// |
312 | | /// The object header is not available to the parsing function, and the returned type is always a |
313 | | /// `BerObject`. |
314 | | /// For a generic version, see [`parse_ber_set_defined_g`](fn.parse_ber_set_defined_g.html). |
315 | | /// |
316 | | /// # Examples |
317 | | /// |
318 | | /// Parsing a set of identical types (same as `parse_ber_set_of`): |
319 | | /// |
320 | | /// ```rust |
321 | | /// # use der_parser::ber::{parse_ber_integer, parse_ber_set_defined, BerObject}; |
322 | | /// # use der_parser::error::BerResult; |
323 | | /// use nom::combinator::complete; |
324 | | /// use nom::multi::many1; |
325 | | /// |
326 | | /// fn localparse_seq(i:&[u8]) -> BerResult { |
327 | | /// parse_ber_set_defined( |
328 | | /// many1(complete(parse_ber_integer)) |
329 | | /// )(i) |
330 | | /// } |
331 | | /// |
332 | | /// # let empty = &b""[..]; |
333 | | /// # let bytes = [ 0x31, 0x0a, |
334 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
335 | | /// # 0x02, 0x03, 0x01, 0x00, 0x00, |
336 | | /// # ]; |
337 | | /// # let expected = BerObject::from_set(vec![ |
338 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
339 | | /// # BerObject::from_int_slice(b"\x01\x00\x00"), |
340 | | /// # ]); |
341 | | /// # assert_eq!(localparse_seq(&bytes), Ok((empty, expected))); |
342 | | /// let (rem, v) = localparse_seq(&bytes).expect("parsing failed"); |
343 | | /// ``` |
344 | | /// |
345 | | /// Parsing a defined set with different types: |
346 | | /// |
347 | | /// ```rust |
348 | | /// # use der_parser::ber::*; |
349 | | /// # use der_parser::error::BerResult; |
350 | | /// use nom::combinator::map; |
351 | | /// use nom::sequence::tuple; |
352 | | /// |
353 | | /// /// Read a DER-encoded object: |
354 | | /// /// SET { |
355 | | /// /// a INTEGER, |
356 | | /// /// b OCTETSTRING |
357 | | /// /// } |
358 | | /// fn localparse_set(i:&[u8]) -> BerResult { |
359 | | /// parse_ber_set_defined( |
360 | | /// // the nom `tuple` combinator returns a tuple, so we have to map it |
361 | | /// // to a list |
362 | | /// map( |
363 | | /// tuple((parse_ber_integer, parse_ber_octetstring)), |
364 | | /// |(a, b)| vec![a, b] |
365 | | /// ) |
366 | | /// )(i) |
367 | | /// } |
368 | | /// |
369 | | /// # let empty = &b""[..]; |
370 | | /// # let bytes = [ 0x31, 0x0a, |
371 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
372 | | /// # 0x04, 0x03, 0x01, 0x00, 0x00, |
373 | | /// # ]; |
374 | | /// # let expected = BerObject::from_set(vec![ |
375 | | /// # BerObject::from_int_slice(b"\x01\x00\x01"), |
376 | | /// # BerObject::from_obj(BerObjectContent::OctetString(b"\x01\x00\x00")), |
377 | | /// # ]); |
378 | | /// # assert_eq!(localparse_set(&bytes), Ok((empty, expected))); |
379 | | /// let (rem, v) = localparse_set(&bytes).expect("parsing failed"); |
380 | | /// ``` |
381 | 0 | pub fn parse_ber_set_defined<'a, F>(mut f: F) -> impl FnMut(&'a [u8]) -> BerResult |
382 | 0 | where |
383 | 0 | F: FnMut(&'a [u8]) -> BerResult<Vec<BerObject>>, |
384 | | { |
385 | 0 | map( |
386 | 0 | parse_ber_set_defined_g(move |data, _| f(data)), Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined::<_>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined::<_>::{closure#0} |
387 | | BerObject::from_set, |
388 | | ) |
389 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined::<_> Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined::<_> |
390 | | |
391 | | /// Parse a defined SET object (generic version) |
392 | | /// |
393 | | /// Given a parser for set content, apply it to build a DER set and |
394 | | /// return the remaining bytes and the built object. |
395 | | /// |
396 | | /// The remaining bytes point *after* the set: any bytes that are part of the sequence but not |
397 | | /// parsed are ignored. |
398 | | /// The nom combinator `all_consuming` can be used to ensure all the content is parsed. |
399 | | /// |
400 | | /// Unlike `parse_ber_set_defined`, this function allows returning any object or error type, |
401 | | /// and also passes the object header to the callback. |
402 | | /// |
403 | | /// # Examples |
404 | | /// |
405 | | /// Parsing a defined set with different types: |
406 | | /// |
407 | | /// ```rust |
408 | | /// # use der_parser::ber::*; |
409 | | /// # use der_parser::error::BerResult; |
410 | | /// # |
411 | | /// # #[derive(Debug, PartialEq)] |
412 | | /// pub struct MyObject<'a> { |
413 | | /// a: u32, |
414 | | /// b: &'a [u8], |
415 | | /// } |
416 | | /// |
417 | | /// /// Read a DER-encoded object: |
418 | | /// /// SET { |
419 | | /// /// a INTEGER (0..4294967295), |
420 | | /// /// b OCTETSTRING |
421 | | /// /// } |
422 | | /// fn parse_myobject(i: &[u8]) -> BerResult<MyObject> { |
423 | | /// parse_ber_set_defined_g( |
424 | | /// |i:&[u8], _| { |
425 | | /// let (i, a) = parse_ber_u32(i)?; |
426 | | /// let (i, obj) = parse_ber_octetstring(i)?; |
427 | | /// let b = obj.as_slice().unwrap(); |
428 | | /// Ok((i, MyObject{ a, b })) |
429 | | /// } |
430 | | /// )(i) |
431 | | /// } |
432 | | /// |
433 | | /// # let empty = &b""[..]; |
434 | | /// # let bytes = [ 0x31, 0x0a, |
435 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
436 | | /// # 0x04, 0x03, 0x01, 0x00, 0x00, |
437 | | /// # ]; |
438 | | /// # let expected = MyObject { |
439 | | /// # a: 0x010001, |
440 | | /// # b: &[01, 00, 00] |
441 | | /// # }; |
442 | | /// # assert_eq!(parse_myobject(&bytes), Ok((empty, expected))); |
443 | | /// let (rem, v) = parse_myobject(&bytes).expect("parsing failed"); |
444 | | /// ``` |
445 | 0 | pub fn parse_ber_set_defined_g<'a, O, F, E>( |
446 | 0 | mut f: F, |
447 | 0 | ) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> |
448 | 0 | where |
449 | 0 | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, |
450 | 0 | E: ParseError<&'a [u8]> + From<BerError>, |
451 | | { |
452 | 0 | parse_ber_container(move |i, hdr| { |
453 | 0 | hdr.assert_tag(Tag::Set).map_err(|e| Err::Error(e.into()))?; Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _>::{closure#0}::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _>::{closure#0}::{closure#0} |
454 | 0 | f(i, hdr) |
455 | 0 | }) Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _>::{closure#0} |
456 | 0 | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _> Unexecuted instantiation: der_parser::ber::multi::parse_ber_set_defined_g::<_, _, _> |
457 | | |
458 | | /// Parse a BER object and apply provided function to content |
459 | | /// |
460 | | /// Given a parser for content, read BER object header and apply parser to |
461 | | /// return the remaining bytes and the parser result. |
462 | | /// |
463 | | /// The remaining bytes point *after* the content: any bytes that are part of the content but not |
464 | | /// parsed are ignored. |
465 | | /// The nom combinator `all_consuming` can be used to ensure all the content is parsed. |
466 | | /// |
467 | | /// This function is mostly intended for constructed objects, but can be used for any valid BER |
468 | | /// object. |
469 | | /// |
470 | | /// # Examples |
471 | | /// |
472 | | /// Parsing a defined sequence with different types: |
473 | | /// |
474 | | /// ```rust |
475 | | /// # use der_parser::ber::*; |
476 | | /// # use der_parser::error::{BerError, BerResult}; |
477 | | /// # |
478 | | /// # #[derive(Debug, PartialEq)] |
479 | | /// pub struct MyObject<'a> { |
480 | | /// a: u32, |
481 | | /// b: &'a [u8], |
482 | | /// } |
483 | | /// |
484 | | /// /// Read a DER-encoded object: |
485 | | /// /// SEQUENCE { |
486 | | /// /// a INTEGER (0..4294967295), |
487 | | /// /// b OCTETSTRING |
488 | | /// /// } |
489 | | /// fn parse_myobject(i: &[u8]) -> BerResult<MyObject> { |
490 | | /// parse_ber_container( |
491 | | /// |i: &[u8], hdr: Header| { |
492 | | /// if hdr.tag() != Tag::Sequence { |
493 | | /// return Err(nom::Err::Error(BerError::BerTypeError.into())); |
494 | | /// } |
495 | | /// let (i, a) = parse_ber_u32(i)?; |
496 | | /// let (i, obj) = parse_ber_octetstring(i)?; |
497 | | /// let b = obj.as_slice().unwrap(); |
498 | | /// Ok((i, MyObject{ a, b })) |
499 | | /// } |
500 | | /// )(i) |
501 | | /// } |
502 | | /// |
503 | | /// # let empty = &b""[..]; |
504 | | /// # let bytes = [ 0x30, 0x0a, |
505 | | /// # 0x02, 0x03, 0x01, 0x00, 0x01, |
506 | | /// # 0x04, 0x03, 0x01, 0x00, 0x00, |
507 | | /// # ]; |
508 | | /// # let expected = MyObject { |
509 | | /// # a: 0x010001, |
510 | | /// # b: &[01, 00, 00] |
511 | | /// # }; |
512 | | /// # assert_eq!(parse_myobject(&bytes), Ok((empty, expected))); |
513 | | /// let (rem, v) = parse_myobject(&bytes).expect("parsing failed"); |
514 | | /// ``` |
515 | 45.7k | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> |
516 | 45.7k | where |
517 | 45.7k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, |
518 | 45.7k | E: ParseError<&'a [u8]> + From<BerError>, |
519 | | { |
520 | 45.7k | move |i: &[u8]| { |
521 | 45.7k | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; |
522 | 42.7k | let (i, data) = match hdr.length() { |
523 | 38.1k | Length::Definite(len) => take(len)(i)?, |
524 | | Length::Indefinite => { |
525 | 4.63k | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? |
526 | | } |
527 | | }; |
528 | 36.2k | let (_rest, v) = f(data, hdr)?; |
529 | 27.2k | Ok((i, v)) |
530 | 45.7k | } der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 520 | 1 | move |i: &[u8]| { | 521 | 1 | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | 1 | let (i, data) = match hdr.length() { | 523 | 1 | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | 0 | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | 1 | let (_rest, v) = f(data, hdr)?; | 529 | 1 | Ok((i, v)) | 530 | 1 | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 520 | 6.81k | move |i: &[u8]| { | 521 | 6.81k | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | 5.24k | let (i, data) = match hdr.length() { | 523 | 2.74k | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | 2.49k | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | 2.59k | let (_rest, v) = f(data, hdr)?; | 529 | 499 | Ok((i, v)) | 530 | 6.81k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<_, _, _>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit_g<asn1_rs::tag::Tag, der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit<u32, der_parser::der::parser::parse_der_content::{closure#0}>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 520 | 27.4k | move |i: &[u8]| { | 521 | 27.4k | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | 26.9k | let (i, data) = match hdr.length() { | 523 | 26.4k | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | 518 | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | 24.5k | let (_rest, v) = f(data, hdr)?; | 529 | 22.7k | Ok((i, v)) | 530 | 27.4k | } |
der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 520 | 111 | move |i: &[u8]| { | 521 | 111 | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | 111 | let (i, data) = match hdr.length() { | 523 | 111 | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | 0 | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | 110 | let (_rest, v) = f(data, hdr)?; | 529 | 99 | Ok((i, v)) | 530 | 111 | } |
der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}Line | Count | Source | 520 | 11.3k | move |i: &[u8]| { | 521 | 11.3k | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | 10.4k | let (i, data) = match hdr.length() { | 523 | 8.83k | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | 1.61k | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | 8.94k | let (_rest, v) = f(data, hdr)?; | 529 | 3.89k | Ok((i, v)) | 530 | 11.3k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<_, _, _>::{closure#0}Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit_g<asn1_rs::tag::Tag, der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit<u32, der_parser::der::parser::parse_der_content::{closure#0}>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0} |
531 | 45.7k | } Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit_g<asn1_rs::tag::Tag, der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit<u32, der_parser::der::parser::parse_der_content::{closure#0}>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 515 | 1 | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 516 | 1 | where | 517 | 1 | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 518 | 1 | E: ParseError<&'a [u8]> + From<BerError>, | 519 | | { | 520 | | move |i: &[u8]| { | 521 | | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | | let (i, data) = match hdr.length() { | 523 | | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | | let (_rest, v) = f(data, hdr)?; | 529 | | Ok((i, v)) | 530 | | } | 531 | 1 | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 515 | 6.81k | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 516 | 6.81k | where | 517 | 6.81k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 518 | 6.81k | E: ParseError<&'a [u8]> + From<BerError>, | 519 | | { | 520 | | move |i: &[u8]| { | 521 | | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | | let (i, data) = match hdr.length() { | 523 | | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | | let (_rest, v) = f(data, hdr)?; | 529 | | Ok((i, v)) | 530 | | } | 531 | 6.81k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<_, _, _> Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit_g<asn1_rs::tag::Tag, der_parser::ber::ber::BerObject, der_parser::ber::tagged::parse_ber_tagged_implicit<u32, der_parser::der::parser::parse_der_content::{closure#0}>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<alloc::string::String>, der_parser::ber::multi::parse_ber_sequence_of_v<alloc::string::String, kerberos_parser::krb5_parser::parse_kerberos_string, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 515 | 27.4k | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 516 | 27.4k | where | 517 | 27.4k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 518 | 27.4k | E: ParseError<&'a [u8]> + From<BerError>, | 519 | | { | 520 | | move |i: &[u8]| { | 521 | | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | | let (i, data) = match hdr.length() { | 523 | | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | | let (_rest, v) = f(data, hdr)?; | 529 | | Ok((i, v)) | 530 | | } | 531 | 27.4k | } |
der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::HostAddress>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::HostAddress, <kerberos_parser::krb5::HostAddress as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 515 | 111 | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 516 | 111 | where | 517 | 111 | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 518 | 111 | E: ParseError<&'a [u8]> + From<BerError>, | 519 | | { | 520 | | move |i: &[u8]| { | 521 | | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | | let (i, data) = match hdr.length() { | 523 | | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | | let (_rest, v) = f(data, hdr)?; | 529 | | Ok((i, v)) | 530 | | } | 531 | 111 | } |
der_parser::ber::multi::parse_ber_container::<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_defined_g<alloc::vec::Vec<kerberos_parser::krb5::PAData>, der_parser::ber::multi::parse_ber_sequence_of_v<kerberos_parser::krb5::PAData, <kerberos_parser::krb5::PAData as asn1_rs::traits::FromDer>::from_der, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>::{closure#0}, asn1_rs::error::Error>Line | Count | Source | 515 | 11.3k | pub fn parse_ber_container<'a, O, F, E>(mut f: F) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E> | 516 | 11.3k | where | 517 | 11.3k | F: FnMut(&'a [u8], Header<'a>) -> IResult<&'a [u8], O, E>, | 518 | 11.3k | E: ParseError<&'a [u8]> + From<BerError>, | 519 | | { | 520 | | move |i: &[u8]| { | 521 | | let (i, hdr) = ber_read_element_header(i).map_err(nom::Err::convert)?; | 522 | | let (i, data) = match hdr.length() { | 523 | | Length::Definite(len) => take(len)(i)?, | 524 | | Length::Indefinite => { | 525 | | ber_get_object_content(i, &hdr, MAX_RECURSION).map_err(nom::Err::convert)? | 526 | | } | 527 | | }; | 528 | | let (_rest, v) = f(data, hdr)?; | 529 | | Ok((i, v)) | 530 | | } | 531 | 11.3k | } |
Unexecuted instantiation: der_parser::ber::multi::parse_ber_container::<_, _, _> |