diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-01-15 09:51:27 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-01-15 11:34:49 +0100 |
commit | de649ea58966273392f4ab09f2bb72bb75650ae2 (patch) | |
tree | 794bc953ade0610d30c373d94b43ad06c8309944 /ffi | |
parent | 59a59ac5bf9cc9be2698eb35376c3b58fd483252 (diff) |
net: Make conversion from u8 to Policy fallible.
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/src/net.rs | 9 | ||||
-rw-r--r-- | ffi/src/store.rs | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/ffi/src/net.rs b/ffi/src/net.rs index f08a3ef0..906f1999 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -32,10 +32,11 @@ use libc::{c_char, size_t}; use native_tls::Certificate; +use std::convert::TryInto; use std::ptr; use std::slice; -use sequoia_net::KeyServer; +use sequoia_net::{KeyServer, Policy}; use super::error::Status; use super::core::Context; @@ -56,7 +57,7 @@ fn sq_keyserver_new(ctx: *mut Context, policy: u8, uri: *const c_char) -> *mut KeyServer { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let policy = policy.into(); + let policy: Policy = ffi_try!(policy.try_into()); let uri = ffi_param_cstr!(uri).to_string_lossy(); ffi_try_box!(KeyServer::new(policy, &uri)) @@ -76,7 +77,7 @@ fn sq_keyserver_with_cert(ctx: *mut Context, policy: u8, len: size_t) -> *mut KeyServer { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let policy = policy.into(); + let policy: Policy = ffi_try!(policy.try_into()); let uri = ffi_param_cstr!(uri).to_string_lossy(); if cert.is_null() { @@ -103,7 +104,7 @@ fn sq_keyserver_keys_openpgp_org(ctx: *mut Context, policy: u8) -> *mut KeyServer { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let policy = policy.into(); + let policy: Policy = ffi_try!(policy.try_into()); ffi_try_box!(KeyServer::keys_openpgp_org(policy)) } diff --git a/ffi/src/store.rs b/ffi/src/store.rs index 65372d78..e4082d5a 100644 --- a/ffi/src/store.rs +++ b/ffi/src/store.rs @@ -24,11 +24,13 @@ use libc::c_char; +use std::convert::TryInto; use std::ptr; use sequoia_store::{ self, Mapping, MappingIter, Binding, BundleIter, Key, KeyIter, LogIter, Store, }; +use sequoia_net as net; use super::error::Status; use super::core::Context; @@ -196,7 +198,7 @@ fn sq_mapping_open(ctx: *mut Context, -> *mut Mapping { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let policy = policy.into(); + let policy: net::Policy = ffi_try!(policy.try_into()); let realm = ffi_param_cstr!(realm).to_string_lossy(); let name = ffi_param_cstr!(name).to_string_lossy(); |