summaryrefslogtreecommitdiff
path: root/src/rust
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-21 02:52:04 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 19:20:32 +0000
commit52c3ea50454bcbcbcf5b18e628a1490441962b33 (patch)
treee0f8dd717fc1e6b0c2bfc6f4e9540f15095b1ca5 /src/rust
parent2f3a7376c06e39942ac3c4d447ca94759f12a5c3 (diff)
downloadtor-52c3ea50454bcbcbcf5b18e628a1490441962b33.tar.gz
tor-52c3ea50454bcbcbcf5b18e628a1490441962b33.zip
rust: Refactor Rust impl of protover_list_supports_protocol().
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.
Diffstat (limited to 'src/rust')
-rw-r--r--src/rust/protover/ffi.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs
index 1588b2e4d3..0d0376e528 100644
--- a/src/rust/protover/ffi.rs
+++ b/src/rust/protover/ffi.rs
@@ -98,16 +98,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