1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use super::{der, Error};
#[derive(Debug, Copy, Clone)]
pub struct ExtensionIterator<'a>(pub(crate) SequenceIterator<'a>);
#[derive(Debug, Copy, Clone)]
pub struct SequenceIterator<'a> {
inner: untrusted::Input<'a>,
}
impl<'a> SequenceIterator<'a> {
pub fn read(input: &mut untrusted::Reader<'a>) -> Self {
Self {
inner: input.read_bytes_to_end(),
}
}
pub fn iterate<
E: Copy + core::fmt::Debug,
T: FnMut(&mut untrusted::Reader<'a>) -> Result<(), E>,
>(
&self, error: E, cb: &mut T,
) -> Result<(), E> {
self.inner.read_all(error, |input| {
while !input.at_end() {
der::nested(input, der::Tag::Sequence, error, &mut *cb)?
}
Ok(())
})
}
}
impl<'a> ExtensionIterator<'a> {
pub fn iterate<T: FnMut(&'a [u8], bool, untrusted::Input<'a>) -> Result<(), Error>>(
&self, cb: &mut T,
) -> Result<(), Error> {
self.0.iterate(Error::BadDER, &mut |input| {
let oid =
der::expect_tag_and_get_value(input, der::Tag::OID).map_err(|_| Error::BadDER)?;
let mut critical = false;
if input.peek(der::Tag::Boolean as _) {
critical = match input
.read_bytes(3)
.map_err(|_| Error::BadDER)?
.as_slice_less_safe()
{
b"\x01\x01\xFF" => true,
b"\x01\x01\0" => false,
_ => return Err(Error::BadDER),
}
}
let value = der::expect_tag_and_get_value(input, der::Tag::OctetString)
.map_err(|_| Error::BadDER)?;
cb(oid.as_slice_less_safe(), critical, value)
})
}
}