Skip to content

Commit f7604db

Browse files
committed
pem: hold on to buffer while reading slice
1 parent 67e6eb8 commit f7604db

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/pem.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl<R: io::BufRead, T: PemObject> Iterator for ReadIter<R, T> {
134134
pub struct SliceIter<'a, T> {
135135
current: &'a [u8],
136136
_ty: PhantomData<T>,
137+
b64_buf: Vec<u8>,
137138
}
138139

139140
impl<'a, T: PemObject> SliceIter<'a, T> {
@@ -142,6 +143,7 @@ impl<'a, T: PemObject> SliceIter<'a, T> {
142143
Self {
143144
current,
144145
_ty: PhantomData,
146+
b64_buf: Vec::with_capacity(1024),
145147
}
146148
}
147149

@@ -152,9 +154,8 @@ impl<'a, T: PemObject> SliceIter<'a, T> {
152154
/// - Otherwise each decoded section is returned with a `Ok(Some((..., remainder)))` where
153155
/// `remainder` is the part of the `input` that follows the returned section
154156
fn read_section(&mut self) -> Result<Option<(SectionKind, Vec<u8>)>, Error> {
155-
let mut b64buf = Vec::with_capacity(1024);
157+
self.b64_buf.clear();
156158
let mut section = None;
157-
158159
loop {
159160
let next_line = if let Some(index) = self
160161
.current
@@ -172,7 +173,7 @@ impl<'a, T: PemObject> SliceIter<'a, T> {
172173
None
173174
};
174175

175-
match read(next_line, &mut section, &mut b64buf)? {
176+
match read(next_line, &mut section, &mut self.b64_buf)? {
176177
ControlFlow::Continue(()) => continue,
177178
ControlFlow::Break(item) => return Ok(item),
178179
}

0 commit comments

Comments
 (0)