aboutsummaryrefslogtreecommitdiff
path: root/src/rust/protover/ffi.rs
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-21 02:45:41 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 19:20:31 +0000
commit2f3a7376c06e39942ac3c4d447ca94759f12a5c3 (patch)
tree39c6f6cfde2bbcbb96eb3bbd6a248e5de51fb780 /src/rust/protover/ffi.rs
parent15e59a1fedf47e7e689e06e5649849552d8b8c0d (diff)
downloadtor-2f3a7376c06e39942ac3c4d447ca94759f12a5c3.tar.gz
tor-2f3a7376c06e39942ac3c4d447ca94759f12a5c3.zip
rust: Refactor Rust impl of protover_all_supported().
This includes differences in behaviour to before, which should now more closely match the C version: - If parsing a protover `char*` from C, and the string is not parseable, this function will return 1 early, which matches the C behaviour when protocols are unparseable. Previously, we would parse it and its version numbers simultaneously, i.e. there was no fail early option, causing us to spend more time unnecessarily parsing versions. * REFACTOR `protover::ffi::protover_all_supported()` to use new types and methods.
Diffstat (limited to 'src/rust/protover/ffi.rs')
-rw-r--r--src/rust/protover/ffi.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs
index 5ecbc2969c..1588b2e4d3 100644
--- a/src/rust/protover/ffi.rs
+++ b/src/rust/protover/ffi.rs
@@ -56,19 +56,26 @@ pub extern "C" fn protover_all_supported(
Err(_) => return 1,
};
- let (is_supported, unsupported) = all_supported(relay_version);
+ let relay_proto_entry: UnvalidatedProtoEntry = match relay_version.parse() {
+ Ok(n) => n,
+ Err(_) => return 1,
+ };
+ let maybe_unsupported: Option<UnvalidatedProtoEntry> = relay_proto_entry.all_supported();
- if unsupported.len() > 0 {
- let c_unsupported = match CString::new(unsupported) {
+ if maybe_unsupported.is_some() {
+ let unsupported: UnvalidatedProtoEntry = maybe_unsupported.unwrap();
+ let c_unsupported: CString = match CString::new(unsupported.to_string()) {
Ok(n) => n,
Err(_) => return 1,
};
let ptr = c_unsupported.into_raw();
unsafe { *missing_out = ptr };
+
+ return 0;
}
- return if is_supported { 1 } else { 0 };
+ 1
}
/// Provide an interface for C to translate arguments and return types for