]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
rust: Refactor Rust impl of protover_list_supports_protocol().
authorIsis Lovecruft <isis@torproject.org>
Wed, 21 Mar 2018 02:52:04 +0000 (02:52 +0000)
committerIsis Lovecruft <isis@torproject.org>
Mon, 2 Apr 2018 19:34:26 +0000 (19:34 +0000)
This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol()` to use new types
   and methods.

src/rust/protover/ffi.rs

index c176968032c84af87e36c836b97c2e5bb660da9a..d9365bdd769119fa14a650b94041789da00e83c3 100644 (file)
@@ -101,16 +101,18 @@ pub extern "C" fn protocol_list_supports_protocol(
         Ok(n) => n,
         Err(_) => return 1,
     };
-
-    let protocol = match translate_to_rust(c_protocol) {
-        Ok(n) => n,
+    let proto_entry: UnvalidatedProtoEntry = match protocol_list.parse() {
+        Ok(n)  => n,
         Err(_) => return 0,
     };
-
-    let is_supported =
-        protover_string_supports_protocol(protocol_list, protocol, version);
-
-    return if is_supported { 1 } else { 0 };
+    let protocol: UnknownProtocol = match translate_to_rust(c_protocol) {
+        Ok(n) => n.into(),
+        Err(_) => return 0,
+    };
+    match proto_entry.supports_protocol(&protocol, &version) {
+        false => return 0,
+        true  => return 1,
+    }
 }
 
 /// Provide an interface for C to translate arguments and return types for