diff options
author | Isis Lovecruft <isis@torproject.org> | 2018-03-27 02:41:25 +0000 |
---|---|---|
committer | Isis Lovecruft <isis@torproject.org> | 2018-04-02 19:59:12 +0000 |
commit | cd28b4c7f5cefd319d6ded635d25911b4323b50b (patch) | |
tree | 61ca64a3177759f0f7bceeb44ab03c3253b023ce /src/rust/protover/ffi.rs | |
parent | fd127bfbfa13d407e5fb5d22a567f51a30af4c2e (diff) | |
download | tor-cd28b4c7f5cefd319d6ded635d25911b4323b50b.tar.gz tor-cd28b4c7f5cefd319d6ded635d25911b4323b50b.zip |
rust: Refactor protover::compute_for_old_tor().
During code review and discussion with Chelsea Komlo, she pointed out
that protover::compute_for_old_tor() was a public function whose
return type was `&'static CStr`. We both agree that C-like parts of
APIs should:
1. not be exposed publicly (to other Rust crates),
2. only be called in the appropriate FFI code,
3. not expose types which are meant for FFI code (e.g. `*mut char`,
`CString`, `*const c_int`, etc.) to the pure-Rust code of other
crates.
4. FFI code (e.g. things in `ffi.rs` modules) should _never_ be called
from pure-Rust, not even from other modules in its own crate
(i.e. do not call `protover::ffi::*` from anywhere in
`protover::protoset::*`, etc).
With that in mind, this commit makes the following changes:
* CHANGE `protover::compute_for_old_tor()` to be
visible only at the `pub(crate)` level.
* RENAME `protover::compute_for_old_tor()` to
`protover::compute_for_old_tor_cstr()` to reflect the last change.
* ADD a new `protover::compute_for_old_tor()` function wrapper which
is public and intended for other Rust code to use, which returns a
`&str`.
Diffstat (limited to 'src/rust/protover/ffi.rs')
-rw-r--r-- | src/rust/protover/ffi.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs index 3632f5de8f..a40353eb13 100644 --- a/src/rust/protover/ffi.rs +++ b/src/rust/protover/ffi.rs @@ -246,7 +246,7 @@ pub extern "C" fn protover_compute_for_old_tor(version: *const c_char) -> *const Err(_) => return empty.as_ptr(), }; - elder_protocols = compute_for_old_tor(&version); + elder_protocols = compute_for_old_tor_cstr(&version); // If we're going to pass it to C, there cannot be any intermediate NUL // bytes. An assert is okay here, since changing the const byte slice |