mirror of
https://github.com/ivabus/lonelyradio
synced 2025-04-23 14:07:16 +03:00
- Optional XOR encryption is now available in lonelyradio and monolib - lonelyradio was optimized to use less TCP calls and less memory copies - New program: monoloader - music downloader for lonelyradio - New monolib function - get_track() for downloading track (as samples), not playing - lonelyradio and monolib are using extensible Writer and Reader enums to provide ability to use lonelyradio with different transport protocols or encryption - Add lonelyradio_types crate to share types Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
25 lines
507 B
Rust
25 lines
507 B
Rust
use std::{io, net::TcpStream};
|
|
|
|
pub(crate) enum Reader {
|
|
Unencrypted(TcpStream),
|
|
XorEncrypted(TcpStream, Vec<u8>, u64),
|
|
}
|
|
|
|
impl io::Read for Reader {
|
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
|
match self {
|
|
Self::Unencrypted(s) => s.read(buf),
|
|
Self::XorEncrypted(s, key, n) => {
|
|
let out = s.read(buf);
|
|
if let Ok(i) = &out {
|
|
for k in buf.iter_mut().take(*i) {
|
|
*k ^= key[*n as usize];
|
|
*n += 1;
|
|
*n %= key.len() as u64;
|
|
}
|
|
}
|
|
out
|
|
}
|
|
}
|
|
}
|
|
}
|