diff options
-rw-r--r-- | core/src/lib.rs | 25 | ||||
-rwxr-xr-x | ffi/examples/dump | bin | 0 -> 17400 bytes | |||
-rwxr-xr-x | ffi/examples/example | bin | 0 -> 17416 bytes | |||
-rwxr-xr-x | ffi/examples/keyserver | bin | 0 -> 18256 bytes | |||
-rw-r--r-- | ffi/src/lib.rs | 17 |
5 files changed, 28 insertions, 14 deletions
diff --git a/core/src/lib.rs b/core/src/lib.rs index 1451bcc3..78242206 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -258,6 +258,31 @@ impl NetworkPolicy { } } +impl<'a> From<&'a NetworkPolicy> for u8 { + fn from(policy: &NetworkPolicy) -> Self { + match policy { + &NetworkPolicy::Offline => 0, + &NetworkPolicy::Anonymized => 1, + &NetworkPolicy::Encrypted => 2, + &NetworkPolicy::Insecure => 3, + } + } +} + + +// XXX: TryFrom would be nice. +impl From<u8> for NetworkPolicy { + fn from(policy: u8) -> Self { + match policy { + 0 => NetworkPolicy::Offline, + 1 => NetworkPolicy::Anonymized, + 2 => NetworkPolicy::Encrypted, + 3 => NetworkPolicy::Insecure, + n => panic!("Bad policy: {}", n), + } + } +} + #[macro_export] macro_rules! assert_match { ( $error: pat = $expr:expr ) => { diff --git a/ffi/examples/dump b/ffi/examples/dump Binary files differnew file mode 100755 index 00000000..98870ba6 --- /dev/null +++ b/ffi/examples/dump diff --git a/ffi/examples/example b/ffi/examples/example Binary files differnew file mode 100755 index 00000000..5a6d8e6f --- /dev/null +++ b/ffi/examples/example diff --git a/ffi/examples/keyserver b/ffi/examples/keyserver Binary files differnew file mode 100755 index 00000000..3164ef97 --- /dev/null +++ b/ffi/examples/keyserver diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 08a64c30..eade52fe 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -41,7 +41,7 @@ use openpgp::tpk::TPK; use openpgp::types::KeyId; use self::libc::{uint8_t, uint64_t, c_char, size_t}; use self::native_tls::Certificate; -use sequoia_core::{Config, Context, NetworkPolicy}; +use sequoia_core::{Config, Context}; use sequoia_net::KeyServer; /* sequoia::Context. */ @@ -121,12 +121,7 @@ pub extern "system" fn sq_context_lib(ctx: Option<&Context>) -> *const c_char { #[no_mangle] pub extern "system" fn sq_context_network_policy(ctx: Option<&Context>) -> uint8_t { assert!(ctx.is_some()); - match ctx.unwrap().network_policy() { - &NetworkPolicy::Offline => 0, - &NetworkPolicy::Anonymized => 1, - &NetworkPolicy::Encrypted => 2, - &NetworkPolicy::Insecure => 3, - } + ctx.unwrap().network_policy().into() } /// Returns whether or not this is an ephemeral context. @@ -184,13 +179,7 @@ pub extern "system" fn sq_config_lib(cfg: Option<&mut Config>, pub extern "system" fn sq_config_network_policy(cfg: Option<&mut Config>, policy: uint8_t) { assert!(cfg.is_some()); - cfg.unwrap().set_network_policy(match policy { - 0 => NetworkPolicy::Offline, - 1 => NetworkPolicy::Anonymized, - 2 => NetworkPolicy::Encrypted, - 3 => NetworkPolicy::Insecure, - n => panic!("Bad policy: {}", n), - }); + cfg.unwrap().set_network_policy(policy.into()); } /// Makes this context ephemeral. |