"Fossies" - the Fresh Open Source Software Archive

Member "tor-0.4.1.6/src/rust/external/external.rs" (10 Jun 2019, 1049 Bytes) of package /linux/misc/tor-0.4.1.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Rust source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright (c) 2016-2019, The Tor Project, Inc. */
    2 // See LICENSE for licensing information */
    3 
    4 use libc::{c_char, c_int};
    5 use std::ffi::CString;
    6 
    7 extern "C" {
    8     fn tor_version_as_new_as(platform: *const c_char, cutoff: *const c_char) -> c_int;
    9 }
   10 
   11 /// Wrap calls to tor_version_as_new_as, defined in routerparse.c
   12 pub fn c_tor_version_as_new_as(platform: &str, cutoff: &str) -> bool {
   13     // CHK: These functions should log a warning if an error occurs. This
   14     // can be added when integration with tor's logger is added to rust
   15     let c_platform = match CString::new(platform) {
   16         Ok(n) => n,
   17         Err(_) => return false,
   18     };
   19 
   20     let c_cutoff = match CString::new(cutoff) {
   21         Ok(n) => n,
   22         Err(_) => return false,
   23     };
   24 
   25     let result: c_int = unsafe { tor_version_as_new_as(c_platform.as_ptr(), c_cutoff.as_ptr()) };
   26 
   27     result == 1
   28 }
   29 
   30 extern "C" {
   31     fn tor_is_using_nss() -> c_int;
   32 }
   33 
   34 /// Return true if Tor was built to use NSS.
   35 pub fn c_tor_is_using_nss() -> bool {
   36     0 != unsafe { tor_is_using_nss() }
   37 }