diff options
author | Isis Lovecruft <isis@torproject.org> | 2018-03-21 02:59:25 +0000 |
---|---|---|
committer | Isis Lovecruft <isis@torproject.org> | 2018-04-02 19:20:33 +0000 |
commit | 0a5494b81df684109986354a3d31051b6f8d0bec (patch) | |
tree | 29fc0f24c74fde4f9f07e34e10a1d859a9c8334c /src/rust/protover/ffi.rs | |
parent | 52c3ea50454bcbcbcf5b18e628a1490441962b33 (diff) | |
download | tor-0a5494b81df684109986354a3d31051b6f8d0bec.tar.gz tor-0a5494b81df684109986354a3d31051b6f8d0bec.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/ffi.rs')
-rw-r--r-- | src/rust/protover/ffi.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/rust/protover/ffi.rs b/src/rust/protover/ffi.rs index 0d0376e528..7f8d86d048 100644 --- a/src/rust/protover/ffi.rs +++ b/src/rust/protover/ffi.rs @@ -138,13 +138,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 |