summaryrefslogtreecommitdiffstats
path: root/ffi/src
diff options
context:
space:
mode:
Diffstat (limited to 'ffi/src')
-rw-r--r--ffi/src/lib.rs29
-rw-r--r--ffi/src/sequoia.h32
2 files changed, 60 insertions, 1 deletions
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs
index b4f20eee..7ba09b10 100644
--- a/ffi/src/lib.rs
+++ b/ffi/src/lib.rs
@@ -42,7 +42,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};
+use sequoia_core::{Config, Context, NetworkPolicy};
use sequoia_net::KeyServer;
/* sequoia::Context. */
@@ -118,6 +118,19 @@ pub extern "system" fn sq_context_lib(ctx: Option<&Context>) -> *const c_char {
ctx.unwrap().lib().to_string_lossy().as_bytes().as_ptr() as *const c_char
}
+/// Returns the network policy.
+#[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,
+ }
+}
+
+
/* sequoia::Config. */
/// Finalizes the configuration and return a `Context`.
@@ -160,6 +173,20 @@ pub extern "system" fn sq_config_lib(cfg: Option<&mut Config>,
cfg.unwrap().set_lib(&lib.as_ref())
}
+/// Sets the network policy.
+#[no_mangle]
+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),
+ });
+}
+
/* openpgp::types. */
/// Returns a KeyID with the given `id`.
diff --git a/ffi/src/sequoia.h b/ffi/src/sequoia.h
index c3b3db04..c19db967 100644
--- a/ffi/src/sequoia.h
+++ b/ffi/src/sequoia.h
@@ -25,6 +25,27 @@ struct sq_context;
struct sq_config;
/*/
+/// Network policy for Sequoia.
+///
+/// With this policy you can control how Sequoia accesses remote
+/// systems.
+/*/
+
+/* Do not contact remote systems. */
+#define SQ_NETWORK_POLICY_OFFLINE 0
+
+/* Only contact remote systems using anonymization techniques
+ * like TOR. */
+#define SQ_NETWORK_POLICY_ANONYMIZED 1
+
+/* Only contact remote systems using transports offering
+ * encryption and authentication like TLS. */
+#define SQ_NETWORK_POLICY_ENCRYPTED 2
+
+/* Contact remote systems even with insecure transports. */
+#define SQ_NETWORK_POLICY_INSECURE 3
+
+/*/
/// Creates a Context with reasonable defaults.
///
/// `domain` should uniquely identify your application, it is strongly
@@ -68,6 +89,11 @@ const char *sq_context_home(const struct sq_context *ctx);
/*/
const char *sq_context_lib(const struct sq_context *ctx);
+/*/
+/// Returns the network policy.
+/*/
+uint8_t sq_context_network_policy(const struct sq_context *ctx);
+
/* sequoia::Config. */
@@ -88,6 +114,12 @@ void sq_config_home(struct sq_config *cfg, const char *home);
/*/
void sq_config_lib(struct sq_config *cfg, const char *lib);
+/*/
+/// Sets the network policy.
+/*/
+void sq_config_network_policy(struct sq_config *cfg, uint8_t policy);
+
+
/* sequoia::openpgp::types. */
/*/