Update to support the latest KeePassXC

This commit is contained in:
varjolintu
2021-01-16 14:39:56 +02:00
parent 211ae91e36
commit 338735e6f4
4 changed files with 90 additions and 90 deletions
+34 -34
View File
@@ -14,58 +14,58 @@ use proxy_socket::ProxySocket;
const BUFFER_SIZE: u32 = 1024 ^ 2; // 1024 ^ 2 is the maximum
fn valid_length(length: u32) -> bool {
return length > 0 && length <= BUFFER_SIZE;
return length > 0 && length <= BUFFER_SIZE;
}
fn read_header() -> u32 {
let stdin = io::stdin();
let mut buf = vec![0; 4];
let mut handle = stdin.lock();
let stdin = io::stdin();
let mut buf = vec![0; 4];
let mut handle = stdin.lock();
handle.read_exact(&mut buf).unwrap();
NativeEndian::read_u32(&buf)
handle.read_exact(&mut buf).unwrap();
NativeEndian::read_u32(&buf)
}
fn read_body<T: Read + Write>(length: u32, socket: &mut ProxySocket<T>) {
let mut buffer = vec![0; length as usize];
let stdin = io::stdin();
let mut handle = stdin.lock();
let mut buffer = vec![0; length as usize];
let stdin = io::stdin();
let mut handle = stdin.lock();
if let Ok(_) = handle.read_exact(&mut buffer) {
if valid_length(length) {
socket.write(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
}
if let Ok(_) = handle.read_exact(&mut buffer) {
if valid_length(length) {
socket.write(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
}
}
fn read_response<T: Read>(socket: &mut ProxySocket<T>) {
let mut buf = vec![0; BUFFER_SIZE as usize];
if let Ok(len) = socket.read(&mut buf) {
write_response(&buf[0..len]);
}
let mut buf = vec![0; BUFFER_SIZE as usize];
if let Ok(len) = socket.read(&mut buf) {
write_response(&buf[0..len]);
}
}
fn write_response(buf: &[u8]) {
let stdout = io::stdout();
let mut out = stdout.lock();
let stdout = io::stdout();
let mut out = stdout.lock();
out.write_u32::<NativeEndian>(buf.len() as u32).unwrap();
out.write(buf).unwrap();
out.flush().unwrap();
out.write_u32::<NativeEndian>(buf.len() as u32).unwrap();
out.write(buf).unwrap();
out.flush().unwrap();
}
fn main() {
let mut socket = proxy_socket::connect(BUFFER_SIZE).unwrap();
let mut socket = proxy_socket::connect(BUFFER_SIZE).unwrap();
// Start thread for user input reading
let ui = thread::spawn(move || {
loop {
let length = read_header();
read_body(length, &mut socket);
}
});
// Start thread for user input reading
let ui = thread::spawn(move || {
loop {
let length = read_header();
read_body(length, &mut socket);
}
});
let _ui_res = ui.join().unwrap();
let _ui_res = ui.join().unwrap();
}