Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Firstyear committed Oct 31, 2023
1 parent fccf771 commit 1de489d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion openssl-sys/src/handwritten/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use super::super::*;
use libc::*;

Expand Down
28 changes: 12 additions & 16 deletions openssl/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use foreign_types::ForeignType;

use std::ffi::CString;
Expand All @@ -8,7 +7,7 @@ use crate::cvt_p;
use crate::error::ErrorStack;
use crate::pkey::{PKey, Private};

pub struct Store (*mut ffi::OSSL_STORE_CTX);
pub struct Store(*mut ffi::OSSL_STORE_CTX);

impl Drop for Store {
fn drop(&mut self) {
Expand All @@ -19,37 +18,34 @@ impl Drop for Store {
}

impl Store {
pub fn private_key_from_uri(
uri: &str
) -> Result<Option<PKey<Private>>, ErrorStack> {
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()))
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)
)?;
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)))
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)
)?;
store_info = cvt_p(ffi::OSSL_STORE_load(store.0))?;
}

// error?
Ok(None)
}
}
}

0 comments on commit 1de489d

Please sign in to comment.