diff --git a/src/imp/openssl.rs b/src/imp/openssl.rs index 389caa5e..0bcc5ccb 100644 --- a/src/imp/openssl.rs +++ b/src/imp/openssl.rs @@ -184,6 +184,10 @@ impl Identity { let chain = cert_chain.collect(); Ok(Identity { pkey, cert, chain }) } + + pub fn from_raw(context: RawType) -> Identity { + Identity { pkey: context.0, cert: context.1, chain: context.2 } + } } #[derive(Clone)] diff --git a/src/imp/schannel.rs b/src/imp/schannel.rs index 62e5042f..392b9a34 100644 --- a/src/imp/schannel.rs +++ b/src/imp/schannel.rs @@ -14,6 +14,8 @@ use {TlsAcceptorBuilder, TlsConnectorBuilder}; const SEC_E_NO_CREDENTIALS: u32 = 0x8009030E; +pub type RawType = self::schannel::cert_context::CertContext; + static PROTOCOLS: &'static [Protocol] = &[ Protocol::Ssl3, Protocol::Tls10, @@ -140,6 +142,12 @@ impl Identity { } Ok(Identity { cert: context }) } + + + pub fn from_raw(context: CertContext) -> Identity { + Identity { cert: context } + } + } // The name of the container must be unique to have multiple active keys. diff --git a/src/imp/security_framework.rs b/src/imp/security_framework.rs index 0b417722..a6666788 100644 --- a/src/imp/security_framework.rs +++ b/src/imp/security_framework.rs @@ -52,6 +52,8 @@ fn convert_protocol(protocol: Protocol) -> SslProtocol { } } +pub type RawType = (SecIdentity, Vec); + pub struct Error(base::Error); impl error::Error for Error { @@ -148,6 +150,10 @@ impl Identity { }) } + pub fn from_raw(context: RawType) -> Identity { + Identity { identity: context.0, chain: context.1 } + } + #[cfg(not(target_os = "ios"))] fn import_options(buf: &[u8], pass: &str) -> Result, Error> { SET_AT_EXIT.call_once(|| { diff --git a/src/lib.rs b/src/lib.rs index 14dabb7b..2c2f0de7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,11 @@ impl Identity { let identity = imp::Identity::from_pkcs8(pem, key)?; Ok(Identity(identity)) } + + /// Creates a certificate context out of the raw type available on the platform + pub fn from_raw(context: imp::RawType) -> Identity { + Identity(imp::Identity::from_raw(context)) + } } /// An X509 certificate.