Browse Source

Change PepIdentity::as_mut to return a Result.

- If `PepIdentity::as_mut` is passed a NULL pointer, return an error.
main
Neal H. Walfield 2 months ago
parent
commit
64e5d7f7ce
2 changed files with 10 additions and 8 deletions
  1. +1
    -6
      src/lib.rs
  2. +9
    -2
      src/pep/identity.rs

+ 1
- 6
src/lib.rs View File

@ -1254,12 +1254,7 @@ ffi!(fn _pgp_generate_keypair(session: *mut Session,
let session = Session::as_mut(session)?;
let mm = session.mm();
let identity = if let Some(i) = PepIdentity::as_mut(identity) {
i
} else {
return Err(Error::IllegalValue(
"identity must not be NULL".into()));
};
let identity = PepIdentity::as_mut(identity)?;
t!("identity: {:?}", identity);
let is_group_identity


+ 9
- 2
src/pep/identity.rs View File

@ -34,6 +34,8 @@ use std::ptr;
use sequoia_openpgp as openpgp;
use openpgp::Fingerprint;
use crate::Error;
use crate::Result;
use crate::buffer::{
malloc_cleared,
rust_str_to_c_str,
@ -118,8 +120,13 @@ impl PepIdentity {
/// Converts the raw pointer to a Rust reference.
///
/// This does not take ownership of the object.
pub fn as_mut(ptr: *mut Self) -> Option<&'static mut Self> {
unsafe { ptr.as_mut() }
pub fn as_mut(ptr: *mut Self) -> Result<&'static mut Self> {
if let Some(identity) = unsafe { ptr.as_mut() } {
Ok(identity)
} else {
Err(Error::IllegalValue(
"PepIdentity may not be NULL".into()))
}
}
/// Returns the address.


Loading…
Cancel
Save