ctf_pwn/io/util/cache/
async_read_cache_ext.rs

1use crate::io::util::cache::read_until::{read_until, ReadUntil};
2use crate::io::{read_until_regex, AsyncCacheRead, ReadUntilRegex};
3
4pub trait AsyncCacheReadExt: AsyncCacheRead {
5    fn read_until<'a, T: AsRef<[u8]>>(
6        &'a mut self,
7        delim: T,
8        buf: &'a mut Vec<u8>,
9    ) -> ReadUntil<'a, Self, T>
10    where
11        Self: Unpin,
12    {
13        read_until(self, delim, buf)
14    }
15
16    fn read_line<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadUntil<'a, Self, &'static [u8]>
17    where
18        Self: Unpin,
19    {
20        read_until(self, b"\n", buf)
21    }
22
23    fn read_line_crlf<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadUntil<'a, Self, &'static [u8]>
24    where
25        Self: Unpin,
26    {
27        read_until(self, b"\r\n", buf)
28    }
29
30    async fn read_until_regex<'a>(
31        &'a mut self,
32        pattern: &str,
33        buf: &'a mut Vec<u8>,
34    ) -> Result<ReadUntilRegex<'a, Self>, regex::Error>
35    where
36        Self: Unpin,
37    {
38        read_until_regex(self, pattern, buf)
39    }
40}
41
42impl<R: AsyncCacheRead + ?Sized> AsyncCacheReadExt for R {}