Skip to content

Commit b73944b

Browse files
committed
Make Parser::peek_tag public
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
1 parent 0dc1d62 commit b73944b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/parser.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ impl<'a> Parser<'a> {
231231
Parser::new(self.data)
232232
}
233233

234-
pub(crate) fn peek_tag(&mut self) -> Option<Tag> {
234+
/// Returns the tag of the next element, without consuming it.
235+
pub fn peek_tag(&mut self) -> Option<Tag> {
235236
let (tag, _) = Tag::from_bytes(self.data).ok()?;
236237
Some(tag)
237238
}
@@ -562,6 +563,15 @@ mod tests {
562563
assert_eq!(result, Err(ParseError::new(ParseErrorKind::ExtraData)));
563564
}
564565

566+
#[test]
567+
fn test_peek_tag() {
568+
let result = crate::parse(b"\x02\x01\x7f", |p| {
569+
assert_eq!(p.peek_tag(), Some(Tag::primitive(0x02)));
570+
p.read_element::<u8>()
571+
});
572+
assert_eq!(result, Ok(127));
573+
}
574+
565575
#[test]
566576
fn test_errors() {
567577
#[derive(Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)