diff --git a/src/imp/openssl.rs b/src/imp/openssl.rs index 8fc4362..41ba103 100644 --- a/src/imp/openssl.rs +++ b/src/imp/openssl.rs @@ -201,6 +201,11 @@ impl Certificate { let der = self.0.to_der()?; Ok(der) } + + pub fn to_pem(&self) -> Result, Error> { + let pem = self.0.to_pem()?; + Ok(pem) + } } pub struct MidHandshakeTlsStream(MidHandshakeSslStream); diff --git a/src/imp/schannel.rs b/src/imp/schannel.rs index 62e5042..462ee64 100644 --- a/src/imp/schannel.rs +++ b/src/imp/schannel.rs @@ -175,6 +175,10 @@ impl Certificate { pub fn to_der(&self) -> Result, Error> { Ok(self.0.to_der().to_vec()) } + + pub fn to_pem(&self) -> Result, Error> { + Ok(self.0.to_pem().into_bytes()) + } } pub struct MidHandshakeTlsStream(tls_stream::MidHandshakeTlsStream); diff --git a/src/imp/security_framework.rs b/src/imp/security_framework.rs index 511badf..36c97f3 100644 --- a/src/imp/security_framework.rs +++ b/src/imp/security_framework.rs @@ -225,6 +225,10 @@ impl Certificate { pub fn to_der(&self) -> Result, Error> { Ok(self.0.to_der()) } + + pub fn to_pem(&self) -> Result, Error> { + panic!("Not implemented on macOS/iOS"); + } } pub enum HandshakeError { diff --git a/src/lib.rs b/src/lib.rs index 267679d..9a05754 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,6 +210,12 @@ impl Certificate { let der = self.0.to_der()?; Ok(der) } + + /// Returns the PEM-encoded representation of this certificate + pub fn to_pem(&self) -> Result> { + let pem = self.0.to_pem()?; + Ok(pem) + } } /// A TLS stream which has been interrupted midway through the handshake process.