str4d / rage

A simple, secure and modern file encryption tool (and Rust library) with small explicit keys, no config options, and UNIX-style composability.
https://age-encryption.org/v1
Apache License 2.0
2.53k stars 97 forks source link

implement AsyncSeek for StreamReader<R: AsyncRead + AsyncSeek + Unpin> #500

Open tgcGlaDius opened 2 months ago

tgcGlaDius commented 2 months ago

Simple porting of the sync Seek implementation of StreamReader to use async calls. The implementation adds a new field named seek_state to the StreamReader when the async feature is enabled. This field acts as a state machine state for the async poll_seek call.

One thing of note is that the current implementation puts the StreamReader in a "bad" state while a seek is being performed, after the seek is performed, then the reader is back into a good working state. This could lead to scenarios where a seek future has been created and polled a few times, but then for some reason gets dropped, if that happens then the stream is left in a non-working bad state. I dont think this really needs fixing as i would expect performing a "half" seek would lead to unexpected behaviour anyway, but it is something that should be documented

I have also copied over the sync seeking tests to use async seeks and reads instead. This is the only real testing of my implementation that i have performed, so if more tests are in order then give a heads up and i will try to implement it