summaryrefslogtreecommitdiff
path: root/crates/tor-bytes/src/reader.rs
Commit message (Collapse)AuthorAgeFilesLines
* tor-proto: Use Reader::take_all_but().Nick Mathewson2024-09-161-13/+14
|
* tor-bytes: Add a new take_all_but method.Nick Mathewson2024-09-161-0/+73
|
* tor-bytes: Fix Truncated refs in various docs.Ian Jackson2024-09-121-4/+5
| | | | | | Use "throws" terminology to avoid having to clutter the description with Err(). Many of these doc comments contain otiose text such as "returns Ok(()) on success" but let's not deal with that now.
* tor-bytes: Rename OnIncomplete to Completeness (fmt)Ian Jackson2024-09-121-1/+1
|
* tor-bytes: Rename OnIncomplete to CompletenessIan Jackson2024-09-121-11/+20
| | | | | | | | And rename its variants and update the docs to contemplate wider use, as suggested in #1620. As discussed here https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2407#note_3075658
* tor_bytes: Clarify a method docIan Jackson2024-09-121-2/+3
| | | | | Apropos https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2407#note_3075638
* tor_bytes: Rename new_truncated_for_test to new_incomplete_for_testIan Jackson2024-09-121-12/+12
| | | | No semver implications since this wasn't in the last release.
* tor-bytes: Add test case for from_possibly_incomplete_sliceIan Jackson2024-09-121-0/+8
| | | | | Prompted by https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2407#note_3075486
* tor-bytes: Fix a doc comment about error reportingIan Jackson2024-09-111-1/+1
| | | | This was a leftover from before I invented Error::MissingData.
* tor-bytes: Do many missed renames of Truncated to IncompleteIan Jackson2024-09-111-6/+6
|
* tor-bytes: Add warning about sub-readers (adjust to new name)Ian Jackson2024-09-111-1/+1
| | | | | Fix semantic conflict of the suggested edit with the rename later in the branch.
* tor-bytes: Add warning about sub-readersIan Jackson2024-09-111-0/+9
| | | | | Suggestion from here https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2407#note_3075481
* tor-bytes: Rename Truncated to Incomplete, and restore old Truncated as ↵Ian Jackson2024-09-111-3/+2
| | | | | | | | | deprecated Incomplete is a better name. This lets us use Truncated for the old, deprecated, conflation of "Incomplete" with what is now "MissingData".
* tor-bytes: Only report Truncated for errors at the outer level (fmt)Ian Jackson2024-09-111-2/+10
|
* tor-bytes: Only report Truncated for errors at the outer levelIan Jackson2024-09-111-9/+22
| | | | | | | | | | | This is item 1 from https://gitlab.torproject.org/tpo/core/arti/-/issues/1614#note_3074562 and the alternative to item 2 presented in the 2nd half of https://gitlab.torproject.org/tpo/core/arti/-/issues/1614#note_3074648 (Item 3 was done earlier, but now we change the behaviour.) Fixes #1614.
* tor-bytes: Error: provide and call Error::incomplete_error (fmt)Ian Jackson2024-09-111-7/+8
|
* tor-bytes: Error: provide and call Error::incomplete_errorIan Jackson2024-09-111-4/+19
| | | | | | | | | | | | | | | | | | | We introduce the new constructor and call it at the error generation sites. But there is still not yet any functional change. Change the type of Truncated's field to be Sensitive. The original reason for not doing this no longer applies, since we don't generally want to open-code construction of this variant. Conveniently, changing the type means we get to find all the sites where one *is* constructed and adjust them. In reader.rs and tor-proto we can just call incomplete_error. In tor-cell, there's a call site where we previously provided an underestimate, and where the Reader isn't available. We adjust that ad-hoc but this is fine because the error variant will change. (relaycell is using a Reader from from_slice.)
* tor-bytes: Add a Reader constructor for tor-socksproto's use caseIan Jackson2024-09-111-3/+23
| | | | | | | Here we add the constructor, and document it, and change the call sites. No functional change yet.
* tor-bytes: Add a test case with missing inner dataIan Jackson2024-09-111-0/+9
| | | | Some tests in other crates test this, but none in tor-bytes!
* tor-bytes: Add a Reader constructor for use in testsIan Jackson2024-09-111-14/+26
| | | | | | | | | | | | We could call from_possibly_incomplete_slice in these, but that's confusing and distracting. Here we add this constructor, and document it (in terms of the constructor to come), and change the call sites. No functional change. Doing this now will prevent unwanted changes to test behaviours when we change the behaviour of Readers made by Reader::from_slice.
* Change tor_bytes::Readable name to `b` in many placesIan Jackson2024-09-111-99/+99
| | | | | | | | | | | | | | | The codebase uses `r` sometimes and `b` at other times. Making this consistent makes widespread changes easier, and is clearer for humans. I think `b` is better than `r` because `r` might be "return". It is indeed used that way in a couple of places in reader.rs, even. I haven't changed *everywhere*, just Readable impls (where `r` is particularly likely to be "return value") and occurrences in tor-bytes. No functional change.
* tor-bytes: Add a deficit field to Error::Truncated (fmt)Ian Jackson2024-09-101-1/+3
|
* tor-bytes: Add a deficit field to Error::TruncatedIan Jackson2024-09-101-3/+6
| | | | This will allow us to fix #1592, but it doesn't do so yet.
* Introduce and use tor_bytes::Error::new_truncated_for_testIan Jackson2024-09-101-11/+11
| | | | | | | | This is going to want to do something more complicated (as described in the docs). In this commit we change all the tests that are expecting Truncated errors. That reduces noise in the next commit.
* tor-bytes: advance: Call peek for the error checkIan Jackson2024-09-101-3/+1
| | | | | This removes one construction site of Error::Truncated. We are about to make constructing one of those more fiddly.
* tor-bytes: Remove use of arrayrefNick Mathewson2023-05-251-9/+8
| | | | | Part of #872: Now that const generics are in, we have better ways to express converting slices into array-references.
* tor-bytes: defend against misuse of extract_n().Nick Mathewson2023-03-061-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | Previously, if somebody wrote this code, an attacker could easily use it to cause an OOM panic: ``` let n = r.take_u64(); let items: Vec<Foo> = r.extract_n(n as usize)?; ``` The first line of defense here is not to write protocols like that: we don't actually _have_ any 32-bit counters in our protocol AFAICT. The second line of defense is to pre-check `n` for reasonableness before calling `extract_n`. Here we add a third line of defense: whereas previously we would do `Vec::with_capacity(n)` in `extract_n`, we now allocate an initial capacity of `min(n, r.remaining())`. This ensures that the size of the allocation can't exceed the remaining length of the message, which (for our cell types at least) should prevent it from overflowing or running OOM.
* tor-bytes: Clarify that Cursor is not a good thing, and could be neater.Nick Mathewson2023-03-011-2/+11
|
* clarify results of misusing cursorsIan Jackson2023-03-011-2/+2
|
* tor-bytes: Add cursor functionality to ReaderNick Mathewson2023-02-281-0/+61
| | | | | We'll use this to implement signature and MAC checking for EstablishIntro cells.
* tor-bytes: Avoid redundant allocationEmil Engler2022-10-251-1/+1
| | | | See c489e1d9118edd842f80b76a636037524a45ee45
* tor-bytes: read_nested_*: rustfmtIan Jackson2022-06-101-13/+23
| | | | I disagree with almost all of these layout decisions...
* tor-bytes: read_nested_*: Take a closureIan Jackson2022-06-101-25/+40
| | | | | | | | | | This eliminates the possibility of writing the bug of failing to call `should_be_exhausted`. As per this discussion https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/572#note_2811464 Fixes #498
* Fix typos in docs and commentsNick Mathewson2022-06-091-2/+2
|
* tor-bytes: Provide nested readersIan Jackson2022-06-091-0/+69
|
* tor-bytes: Reader: Provide take_restIan Jackson2022-06-091-0/+19
| | | | We'll want this in a moment.
* Fix/suppress a few more clippy lints in tests.Nick Mathewson2021-09-081-0/+1
| | | | | I'm alright with allowing cognitive-complexity violations in the tests.
* fix/silence clippy lints in test modulesDaniel Eades2021-09-081-0/+1
|
* Improvements to array-of-u8 handling in tor-bytes.Nick Mathewson2021-09-071-0/+28
| | | | | | | | | | | | Now that we have const generics, we can use them. We can also avoid an extra clone in the implementation for [u8; N]. Nothing in our codebase requires that we use Reader or Writer on a GenericArray holding anything other than u8, so I've switched back to the more efficient implementation there. I've added a fuzzer case for the new method, but apparently rustc nightly isn't working too well with fuzzers for me; I'm going to try it tomorrow.
* Move all crates into a `crates` subdirectory.Nick Mathewson2021-08-271-0/+433
This will cause some pain for now, but now is really the best time to do this kind of thing.