external.rs 1.0 KB

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