summaryrefslogtreecommitdiff
path: root/src/rust/protover/ffi.rs
AgeCommit message (Collapse)Author
2020-05-18rust/protover: Fix protocol version support error handlingteor
Make Rust protocol version support checks consistent with the undocumented error behaviour of the corresponding C code. Fixes bug 34251; bugfix on 0.3.3.5-rc.
2019-05-03sendme: Add FlowCtrl protover valueDavid Goulet
See proposal 289 section 4.3 for more details. It describes the flow control protocol at the circuit and stream level. If there is no FlowCtrl protocol version, tor supports the unauthenticated flow control features from its supported Relay protocols. At this commit, relay will start advertising FlowCtrl=1 meaning they support authenticated SENDMEs v1. Closes #30363 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-03-05protover: Add missing Padding to translate_to_rustDavid Goulet
This commit also explicitly set the value of the PRT enum so we can match/pin the C enum values to the Rust one in protover/ffi.rs. Fixes #29631 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-01-16Bump copyright date to 2019Nick Mathewson
2018-10-30Merge remote-tracking branch 'tor-github/pr/431' into bug27740_035_fixNick Mathewson
2018-10-30remove now-unused "use" statement.Nick Mathewson
2018-10-30Try to restore a proper fix for bug27740 in 0.3.5.Nick Mathewson
(I messed up the merge in 289a7dbac32a981897e12a3c250f0b6c67eec809.)
2018-10-23Merge branch 'maint-0.3.4' into maint-0.3.5Nick Mathewson
2018-10-23Merge branch 'maint-0.3.3' into maint-0.3.4Nick Mathewson
2018-09-21rust/protover: return C-allocated string in protover_all_supported()cypherpunks
The result of CString::into_raw() is not safe to free with free() except under finicky and fragile circumstances that we definitely don't meet right now. This was missed in be583a34a3815c2c10e86094ab0610e4b7f9c869.
2018-09-21rust/protover: fix null deref in protover_all_supported()cypherpunks
Fortunately with the current callers it couldn't happen in practice. Fix on d1820c1516a31a149fc51a9e5126bf899e4c4e08.
2018-09-18Merge remote-tracking branch 'nickm/bug27741_033' into bug27741_035teor
Resolve conflicts due to rustfmt, and run rustfmt on the merged code.
2018-09-17Remove extraneous argument from Rust protover_compute_vote()Nick Mathewson
This argument was added to match an older idea for the C api, but we decided not to do it that way in C. Fixes bug 27741; bugfix on 0.3.3.6 / TROVE-2018-005 fix.
2018-08-16rust: run rustfmtcypherpunks
2018-07-13Merge remote-tracking branch 'tor-github/pr/179'Nick Mathewson
2018-07-05Fix everything that previously referred to src/orNick Mathewson
2018-06-25Run rustfmt on 'src/rust/protover/ffi.rs'.Corey Farwell
2018-06-24Utilize type param in method invocation.Corey Farwell
2018-06-24Utilize `if..else` for switching on boolean values.Corey Farwell
2018-06-24Utilize `if let` construct instead of explicit unwrapping.Corey Farwell
2018-06-24Change `allocate_and_copy_string` to take a `&str` instead of `&String`.Corey Farwell
2018-06-20Update copyrights to 2018.Nick Mathewson
2018-05-22Merge branch 'maint-0.3.3'Nick Mathewson
2018-05-22Make the TROVE-2018-005 fix work with rust.Nick Mathewson
2018-05-22rust: Mirror TROVE-2018-005 fix in Rust protover implementation.Isis Lovecruft
* REFACTORS `UnvalidatedProtoEntry::from_str` to place the bulk of the splitting/parsing logic in to a new `UnvalidatedProtoEntry::parse_protocol_and_version_str()` method (so that both `from_str()` and `from_str_any_len()` can call it.) * ADD a new `UnvalidatedProtoEntry::from_str_any_len()` method in order to maintain compatibility with consensus methods older than 29. * ADD a limit on the number of characters in a protocol name. * FIXES part of #25517: https://bugs.torproject.org/25517
2018-05-22rust: Mirror TROVE-2018-005 fix in Rust protover implementation.Isis Lovecruft
* REFACTORS `UnvalidatedProtoEntry::from_str` to place the bulk of the splitting/parsing logic in to a new `UnvalidatedProtoEntry::parse_protocol_and_version_str()` method (so that both `from_str()` and `from_str_any_len()` can call it.) * ADD a new `UnvalidatedProtoEntry::from_str_any_len()` method in order to maintain compatibility with consensus methods older than 29. * ADD a limit on the number of characters in a protocol name. * FIXES part of #25517: https://bugs.torproject.org/25517
2018-04-02rust: Refactor protover::compute_for_old_tor().Isis Lovecruft
During code review and discussion with Chelsea Komlo, she pointed out that protover::compute_for_old_tor() was a public function whose return type was `&'static CStr`. We both agree that C-like parts of APIs should: 1. not be exposed publicly (to other Rust crates), 2. only be called in the appropriate FFI code, 3. not expose types which are meant for FFI code (e.g. `*mut char`, `CString`, `*const c_int`, etc.) to the pure-Rust code of other crates. 4. FFI code (e.g. things in `ffi.rs` modules) should _never_ be called from pure-Rust, not even from other modules in its own crate (i.e. do not call `protover::ffi::*` from anywhere in `protover::protoset::*`, etc). With that in mind, this commit makes the following changes: * CHANGE `protover::compute_for_old_tor()` to be visible only at the `pub(crate)` level. * RENAME `protover::compute_for_old_tor()` to `protover::compute_for_old_tor_cstr()` to reflect the last change. * ADD a new `protover::compute_for_old_tor()` function wrapper which is public and intended for other Rust code to use, which returns a `&str`.
2018-04-02rust: Refactor Rust implementation of protover_is_supported_here().Isis Lovecruft
It was changed to take borrows instead of taking ownership. * REFACTOR `protover::ffi::protover_is_supported_here()` to use changed method signature on `protover::is_supported_here()`.
2018-04-02rust: Refactor Rust impl of protover_compute_vote().Isis Lovecruft
This includes a subtle difference in behaviour to the previous Rust implementation, where, for each vote that we're computing over, if a single one fails to parse, we skip it. This now matches the current behaviour in the C implementation. * REFACTOR `protover::ffi::protover_compute_vote()` to use new types and methods.
2018-04-02rust: Refactor Rust impl of protover_list_supports_protocol_or_later().Isis Lovecruft
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.
2018-04-02rust: Refactor Rust impl of protover_list_supports_protocol().Isis Lovecruft
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.
2018-04-02rust: Refactor Rust impl of protover_all_supported().Isis Lovecruft
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.
2018-04-02rust: Add new protover::UnknownProtocol type.Isis Lovecruft
* ADD new type, protover::UnknownProtocol, so that we have greater type safety and our protover functionality which works with unsanitised protocol names is more clearly demarcated. * REFACTOR protover::Proto, renaming it protover::Protocol to mirror the new protover::UnknownProtocol type name. * ADD a utility conversion of `impl From<Protocol> for UnknownProtocol` so that we can easily with known protocols and unknown protocols simultaneously (e.g. doing comparisons, checking their version numbers), while not allowing UnknownProtocols to be accidentally used in functions which should only take Protocols. * FIXES part of #24031: https://bugs.torproject.org/24031
2018-04-02rust: Refactor protover::compute_for_old_tor().Isis Lovecruft
During code review and discussion with Chelsea Komlo, she pointed out that protover::compute_for_old_tor() was a public function whose return type was `&'static CStr`. We both agree that C-like parts of APIs should: 1. not be exposed publicly (to other Rust crates), 2. only be called in the appropriate FFI code, 3. not expose types which are meant for FFI code (e.g. `*mut char`, `CString`, `*const c_int`, etc.) to the pure-Rust code of other crates. 4. FFI code (e.g. things in `ffi.rs` modules) should _never_ be called from pure-Rust, not even from other modules in its own crate (i.e. do not call `protover::ffi::*` from anywhere in `protover::protoset::*`, etc). With that in mind, this commit makes the following changes: * CHANGE `protover::compute_for_old_tor()` to be visible only at the `pub(crate)` level. * RENAME `protover::compute_for_old_tor()` to `protover::compute_for_old_tor_cstr()` to reflect the last change. * ADD a new `protover::compute_for_old_tor()` function wrapper which is public and intended for other Rust code to use, which returns a `&str`.
2018-04-02rust: Refactor Rust implementation of protover_is_supported_here().Isis Lovecruft
It was changed to take borrows instead of taking ownership. * REFACTOR `protover::ffi::protover_is_supported_here()` to use changed method signature on `protover::is_supported_here()`.
2018-04-02rust: Refactor Rust impl of protover_compute_vote().Isis Lovecruft
This includes a subtle difference in behaviour to the previous Rust implementation, where, for each vote that we're computing over, if a single one fails to parse, we skip it. This now matches the current behaviour in the C implementation. * REFACTOR `protover::ffi::protover_compute_vote()` to use new types and methods.
2018-04-02rust: Refactor Rust impl of protover_list_supports_protocol_or_later().Isis Lovecruft
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.
2018-04-02rust: Refactor Rust impl of protover_list_supports_protocol().Isis Lovecruft
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.
2018-04-02rust: Refactor Rust impl of protover_all_supported().Isis Lovecruft
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.
2018-04-02rust: Add new protover::UnknownProtocol type.Isis Lovecruft
* ADD new type, protover::UnknownProtocol, so that we have greater type safety and our protover functionality which works with unsanitised protocol names is more clearly demarcated. * REFACTOR protover::Proto, renaming it protover::Protocol to mirror the new protover::UnknownProtocol type name. * ADD a utility conversion of `impl From<Protocol> for UnknownProtocol` so that we can easily with known protocols and unknown protocols simultaneously (e.g. doing comparisons, checking their version numbers), while not allowing UnknownProtocols to be accidentally used in functions which should only take Protocols. * FIXES part of #24031: https://bugs.torproject.org/24031
2018-03-19Merge remote-tracking branch 'isis/bug23881_r1'Nick Mathewson
2018-02-10rust: Remove now unused byte_slice_is_c_like() utility.Isis Lovecruft
2018-02-10rust: Remove empty_static_cstr() in favour of new cstr!() macro.Isis Lovecruft
2018-02-10rust: Use tor_util::strings utils for protover_compute_for_old_tor.Isis Lovecruft
2018-02-10rust: Use tor_util::strings utils for protover_get_supported_protocols.Isis Lovecruft
2018-02-10rust: Replace two `unwrap()`s in FFI code with `unwrap_or()`s.Isis Lovecruft
2018-02-08Remove new unsafe {} use.Nick Mathewson
Rationale: this helps for performance only, but we don't actually have any reason to think that the checks here are performance-critical. Let's not normalize the use of unsafe {}.
2018-02-07protover: Fix memleak in Rust impl of protover_compute_for_old_tor.Isis Lovecruft
* FIXES #25127: https://bugs.torproject.org/25127 * ADDS a new module to the Rust tor_util crate for small utilities for working with static strings between languages. * CHANGES the return type of protover_compute_for_old_tor to point to immutable data. * CHANGES the code from the previous commit to use the new static string utilities.
2018-02-06protover: Fix memleak in Rust implementation.Isis Lovecruft
* FIXES #25127: https://bugs.torproject.org/25127.
2017-12-21cargo fmt fixesChelsea Holland Komlo