|
2 | 2 | //! library-level length limitation i.e. `Length::max()`. |
3 | 3 |
|
4 | 4 | use crate::{ |
5 | | - BytesRef, Decode, DecodeValue, DerOrd, EncodeValue, Error, ErrorKind, Header, Length, Reader, |
6 | | - Result, StrRef, Writer, referenced::OwnedToRef, |
| 5 | + BytesRef, DecodeValue, DerOrd, EncodeValue, Error, Header, Length, Reader, Result, StrRef, |
| 6 | + Writer, reader::read_constructed_vec, referenced::OwnedToRef, |
7 | 7 | }; |
8 | 8 | use alloc::{boxed::Box, vec::Vec}; |
9 | 9 | use core::cmp::Ordering; |
@@ -66,28 +66,7 @@ impl<'a> DecodeValue<'a> for BytesOwned { |
66 | 66 | fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> { |
67 | 67 | // Reassemble indefinite length string types |
68 | 68 | if header.length.is_indefinite() && !header.tag.is_constructed() { |
69 | | - // Parse constructed indefinite length data |
70 | | - // TODO(tarcieri): extract this somewhere reusable |
71 | | - let mut bytes = Vec::with_capacity(header.length.try_into()?); |
72 | | - let mut offset = 0; |
73 | | - |
74 | | - while !reader.is_finished() { |
75 | | - let h = Header::decode(reader)?; |
76 | | - h.tag.assert_eq(header.tag)?; |
77 | | - |
78 | | - // Indefinite length headers can't be indefinite |
79 | | - if h.length.is_indefinite() { |
80 | | - return Err(reader.error(ErrorKind::IndefiniteLength)); |
81 | | - } |
82 | | - |
83 | | - // Add enough zeroes into the `Vec` to store the chunk |
84 | | - let l = usize::try_from(h.length)?; |
85 | | - bytes.extend(core::iter::repeat_n(0, l)); |
86 | | - reader.read_into(&mut bytes[offset..(offset + l)])?; |
87 | | - offset += l; |
88 | | - } |
89 | | - |
90 | | - return Self::new(bytes); |
| 69 | + return Self::new(read_constructed_vec(reader, header)?); |
91 | 70 | } |
92 | 71 |
|
93 | 72 | reader.read_vec(header.length).and_then(Self::new) |
|
0 commit comments