diff options
author | Chelsea Holland Komlo <me@chelseakomlo.com> | 2017-09-27 19:48:07 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-10-27 10:02:08 -0400 |
commit | d1820c1516a31a149fc51a9e5126bf899e4c4e08 (patch) | |
tree | ea2ed5c2259f87ca078378eff4f78c9bf0aa50da /src/rust/external | |
parent | 5418aa84eec9f08af7ab7b68cbc9145750ad0a1b (diff) | |
download | tor-d1820c1516a31a149fc51a9e5126bf899e4c4e08.tar.gz tor-d1820c1516a31a149fc51a9e5126bf899e4c4e08.zip |
rust implementation of protover
Diffstat (limited to 'src/rust/external')
-rw-r--r-- | src/rust/external/Cargo.toml | 13 | ||||
-rw-r--r-- | src/rust/external/external.rs | 29 | ||||
-rw-r--r-- | src/rust/external/lib.rs | 14 |
3 files changed, 56 insertions, 0 deletions
diff --git a/src/rust/external/Cargo.toml b/src/rust/external/Cargo.toml new file mode 100644 index 0000000000..bccd7033a7 --- /dev/null +++ b/src/rust/external/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["The Tor Project"] +version = "0.0.1" +name = "external" + +[dependencies] +libc = "0.2.22" + +[lib] +name = "external" +path = "lib.rs" +crate_type = ["rlib", "staticlib"] + diff --git a/src/rust/external/external.rs b/src/rust/external/external.rs new file mode 100644 index 0000000000..0e8d1eb0d8 --- /dev/null +++ b/src/rust/external/external.rs @@ -0,0 +1,29 @@ +use libc::{c_char, c_int}; +use std::ffi::CString; + +extern "C" { + fn tor_version_as_new_as( + platform: *const c_char, + cutoff: *const c_char, + ) -> c_int; +} + +/// Wrap calls to tor_version_as_new_as, defined in src/or/routerparse.c +pub fn c_tor_version_as_new_as(platform: &str, cutoff: &str) -> bool { + // CHK: These functions should log a warning if an error occurs. This + // can be added when integration with tor's logger is added to rust + let c_platform = match CString::new(platform) { + Ok(n) => n, + Err(_) => return false, + }; + let c_cutoff = match CString::new(cutoff) { + Ok(n) => n, + Err(_) => return false, + }; + + let result: c_int; + unsafe { + result = tor_version_as_new_as(c_platform.as_ptr(), c_cutoff.as_ptr()); + result == 1 + } +} diff --git a/src/rust/external/lib.rs b/src/rust/external/lib.rs new file mode 100644 index 0000000000..0af0d6452d --- /dev/null +++ b/src/rust/external/lib.rs @@ -0,0 +1,14 @@ +//! Copyright (c) 2016-2017, The Tor Project, Inc. */ +//! See LICENSE for licensing information */ + +//! Interface for external calls to tor C ABI +//! +//! The purpose of this module is to provide a clean interface for when Rust +//! modules need to interact with functionality in tor C code rather than each +//! module implementing this functionality repeatedly. + +extern crate libc; + +mod external; + +pub use external::*; |