summaryrefslogtreecommitdiff
path: root/src/rust/protover
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-21 02:59:25 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 19:36:25 +0000
commit269053a3801ebe925707db5a8e519836ad2242c9 (patch)
tree001aa32a91fa1a63f7f6da0da13bb435cc590245 /src/rust/protover
parent63eeda89ea11bf719ec6fddc7619994cc7f654ca (diff)
downloadtor-269053a3801ebe925707db5a8e519836ad2242c9.tar.gz
tor-269053a3801ebe925707db5a8e519836ad2242c9.zip
rust: Refactor Rust impl of protover_list_supports_protocol_or_later().
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_or_later()` to use new types and methods.
Diffstat (limited to 'src/rust/protover')
-rw-r--r--src/rust/protover/ffi.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs
index d9365bdd76..e7c8211161 100644
--- a/src/rust/protover/ffi.rs
+++ b/src/rust/protover/ffi.rs
@@ -141,11 +141,15 @@ pub extern "C" fn protocol_list_supports_protocol_or_later(
Err(_) => return 0,
};
- let is_supported =
- protover_string_supports_protocol_or_later(
- protocol_list, protocol, version);
+ let proto_entry: UnvalidatedProtoEntry = match protocol_list.parse() {
+ Ok(n) => n,
+ Err(_) => return 1,
+ };
- return if is_supported { 1 } else { 0 };
+ if proto_entry.supports_protocol_or_later(&protocol.into(), &version) {
+ return 1;
+ }
+ 0
}
/// Provide an interface for C to translate arguments and return types for