summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@pep-project.org>2018-01-09 12:19:23 +0100
committerJustus Winter <justus@pep-project.org>2018-01-09 12:19:23 +0100
commit598cdc97094f067c92f222d2038cf7b4b69cc7af (patch)
tree36ffd176434c65ed8de0712f62570b760371b76e
parentbcc668602092449fa53fe80341d73c34818821b7 (diff)
core,ffi: Convert 'core::NetworkPolicy' to and from u8.
- At some points, we need to convert the policy to a primitive type. It is better to just provide it. - Use it in the ffi glue.
-rw-r--r--core/src/lib.rs25
-rwxr-xr-xffi/examples/dumpbin0 -> 17400 bytes
-rwxr-xr-xffi/examples/examplebin0 -> 17416 bytes
-rwxr-xr-xffi/examples/keyserverbin0 -> 18256 bytes
-rw-r--r--ffi/src/lib.rs17
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
new file mode 100755
index 00000000..98870ba6
--- /dev/null
+++ b/ffi/examples/dump
Binary files differ
diff --git a/ffi/examples/example b/ffi/examples/example
new file mode 100755
index 00000000..5a6d8e6f
--- /dev/null
+++ b/ffi/examples/example
Binary files differ
diff --git a/ffi/examples/keyserver b/ffi/examples/keyserver
new file mode 100755
index 00000000..3164ef97
--- /dev/null
+++ b/ffi/examples/keyserver
Binary files differ
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.