diff --git a/quinn-proto/src/crypto/types.rs b/quinn-proto/src/crypto/types.rs index 4382b6ce9..7490f3ed8 100644 --- a/quinn-proto/src/crypto/types.rs +++ b/quinn-proto/src/crypto/types.rs @@ -16,6 +16,16 @@ impl Certificate { }) } + /// Parse a PEM-formatted certificate + pub fn from_pem(pem: &[u8]) -> Result { + let certs = pemfile::certs(&mut &pem[..]).map_err(|()| ParseError("invalid pem cert"))?; + if let Some(pem) = certs.into_iter().next() { + return Ok(Self { inner: pem }); + } + + Err(ParseError("no cert found")) + } + /// View the certificate in DER format pub fn as_der(&self) -> &[u8] { &self.inner.0