Skip to content

Commit 02fdf7d

Browse files
authored
der: make PemReader<'_> impl Reader<'static> (#2095)
The PEM reader does on-the-fly decoding and therefore can't borrow from its input at all. Having it impl `Reader<'static>` allows it to produce outputs that outlive its input buffer. In theory this means `Cow<'static, T>` should impl `DecodePem`.
1 parent 0c63159 commit 02fdf7d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

der/src/reader/pem.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::{EncodingRules, Error, ErrorKind, Length, Result};
55
use pem_rfc7468::Decoder;
66

77
/// `Reader` type which decodes PEM on-the-fly.
8-
#[cfg(feature = "pem")]
98
#[derive(Clone)]
109
pub struct PemReader<'i> {
1110
/// Inner PEM decoder.
@@ -18,7 +17,6 @@ pub struct PemReader<'i> {
1817
position: Position,
1918
}
2019

21-
#[cfg(feature = "pem")]
2220
impl<'i> PemReader<'i> {
2321
/// Create a new PEM reader which decodes data on-the-fly.
2422
///
@@ -41,8 +39,7 @@ impl<'i> PemReader<'i> {
4139
}
4240
}
4341

44-
#[cfg(feature = "pem")]
45-
impl<'i> Reader<'i> for PemReader<'i> {
42+
impl<'i> Reader<'static> for PemReader<'i> {
4643
const CAN_READ_SLICE: bool = false;
4744

4845
fn encoding_rules(&self) -> EncodingRules {
@@ -68,7 +65,7 @@ impl<'i> Reader<'i> for PemReader<'i> {
6865
ret
6966
}
7067

71-
fn read_slice(&mut self, _len: Length) -> Result<&'i [u8]> {
68+
fn read_slice(&mut self, _len: Length) -> Result<&'static [u8]> {
7269
// Can't borrow from PEM because it requires decoding
7370
Err(self.error(ErrorKind::Reader))
7471
}

0 commit comments

Comments
 (0)