forked from sfackler/rust-openssl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR: sfackler#2077 issue: sfackler#2059 It works! fmt
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use super::super::*; | ||
use libc::*; | ||
|
||
pub enum OSSL_STORE_CTX {} | ||
|
||
pub enum OSSL_STORE_INFO {} | ||
|
||
pub const OSSL_STORE_INFO_PUBKEY: c_int = 3; | ||
pub const OSSL_STORE_INFO_PKEY: c_int = 4; | ||
pub const OSSL_STORE_INFO_CERT: c_int = 5; | ||
pub const OSSL_STORE_INFO_CRL: c_int = 6; | ||
|
||
extern "C" { | ||
pub fn OSSL_STORE_open( | ||
uri: *const c_char, | ||
// const UI_METHOD *ui_method, | ||
ui_method: *const c_void, | ||
ui_data: *const c_void, | ||
// OSSL_STORE_post_process_info_fn post_process, | ||
post_process: *const c_void, | ||
post_process_data: *const c_void, | ||
) -> *mut OSSL_STORE_CTX; | ||
|
||
pub fn OSSL_STORE_load(ctx: *mut OSSL_STORE_CTX) -> *mut OSSL_STORE_INFO; | ||
|
||
pub fn OSSL_STORE_INFO_get_type(store_info: *mut OSSL_STORE_INFO) -> c_int; | ||
|
||
pub fn OSSL_STORE_INFO_get1_PUBKEY(store_info: *mut OSSL_STORE_INFO) -> *mut EVP_PKEY; | ||
|
||
pub fn OSSL_STORE_INFO_get1_PKEY(store_info: *mut OSSL_STORE_INFO) -> *mut EVP_PKEY; | ||
|
||
pub fn OSSL_STORE_INFO_free(store_info: *mut OSSL_STORE_INFO); | ||
|
||
pub fn OSSL_STORE_close(ctx: *mut OSSL_STORE_CTX) -> c_int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use foreign_types::ForeignType; | ||
|
||
use std::ffi::CString; | ||
use std::ptr; | ||
|
||
use crate::cvt_p; | ||
use crate::error::ErrorStack; | ||
use crate::pkey::{PKey, Private}; | ||
|
||
pub struct Store(*mut ffi::OSSL_STORE_CTX); | ||
|
||
impl Drop for Store { | ||
fn drop(&mut self) { | ||
unsafe { | ||
ffi::OSSL_STORE_close(self.0); | ||
} | ||
} | ||
} | ||
|
||
impl Store { | ||
pub fn private_key_from_uri(uri: &str) -> Result<Option<PKey<Private>>, ErrorStack> { | ||
let uri = CString::new(uri).unwrap(); | ||
unsafe { | ||
let store = cvt_p(ffi::OSSL_STORE_open( | ||
uri.as_ptr(), | ||
ptr::null(), | ||
ptr::null(), | ||
ptr::null(), | ||
ptr::null(), | ||
)) | ||
.map(|p| Store(p))?; | ||
|
||
let mut store_info = cvt_p(ffi::OSSL_STORE_load(store.0))?; | ||
|
||
while store_info != ptr::null_mut() { | ||
let type_ = ffi::OSSL_STORE_INFO_get_type(store_info); | ||
if type_ == ffi::OSSL_STORE_INFO_PKEY { | ||
let pkey_ptr = cvt_p(ffi::OSSL_STORE_INFO_get1_PKEY(store_info))?; | ||
return Ok(Some(PKey::from_ptr(pkey_ptr))); | ||
} | ||
|
||
ffi::OSSL_STORE_INFO_free(store_info); | ||
|
||
store_info = cvt_p(ffi::OSSL_STORE_load(store.0))?; | ||
} | ||
|
||
// error? | ||
Ok(None) | ||
} | ||
} | ||
} |