From 66eff48e83854c894149562410c449e03a926e5f Mon Sep 17 00:00:00 2001 From: Joe Birr-Pixton Date: Fri, 27 Sep 2024 12:24:16 +0100 Subject: [PATCH] fixup --- Cargo.lock | 2 +- src/pemfile.rs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a991700..230d412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,4 +19,4 @@ dependencies = [ [[package]] name = "rustls-pki-types" version = "1.9.0" -source = "git+https://github.com/rustls/pki-types.git?branch=jbp-pem#d626094315571c52e6b5b7f5c6a7915314f4cc5f" +source = "git+https://github.com/rustls/pki-types.git?branch=jbp-pem#5786284c1a9b3e151e23b1dfe78cb0ef828b5323" diff --git a/src/pemfile.rs b/src/pemfile.rs index ac0875c..245cee0 100644 --- a/src/pemfile.rs +++ b/src/pemfile.rs @@ -66,21 +66,20 @@ impl Item { } } - fn from_slice(mut pem: &[u8]) -> Result, pem::Error> { - loop { - match pem::from_slice(pem) { - Ok(Some(((kind, data), remainder))) => { - pem = remainder; - - match Self::from_kind(kind, data) { - Some(item) => return Ok(Some((item, pem))), - None => continue, - } - } - Ok(None) => return Ok(None), + fn from_slice(pem: &[u8]) -> Result, pem::Error> { + let mut iter = <(pem::SectionKind, Vec) as pem::PemObject>::pem_slice_iter(pem); + + for found in iter.by_ref() { + match found { + Ok((kind, data)) => match Self::from_kind(kind, data) { + Some(item) => return Ok(Some((item, iter.remainder()))), + None => continue, + }, Err(err) => return Err(err.into()), } } + + Ok(None) } fn from_kind(kind: pem::SectionKind, data: Vec) -> Option {