|
|
|
@ -207,9 +207,8 @@ impl KeyHeader
|
|
|
|
|
out.write_u8(b'\n').await?;
|
|
|
|
|
written += bytes.len() + 1;
|
|
|
|
|
}
|
|
|
|
|
out.write_all(b"---\n>BEGIN\nBODY<\n").await?; // We can add a comment after > as long as it doesn't have any newlines.
|
|
|
|
|
// this is because of the retarded way i did read_text with mpsc.
|
|
|
|
|
Ok(written + 8 + 9)
|
|
|
|
|
out.write_all(b"---\n").await?;
|
|
|
|
|
Ok(written + 4)
|
|
|
|
|
}
|
|
|
|
|
/// Read a superheader as text bytes from this stream
|
|
|
|
|
#[instrument(err, skip(input, passwd))]
|
|
|
|
@ -266,21 +265,18 @@ impl KeyHeader
|
|
|
|
|
let line_sender = async move { //this causes the >\n<\n dumbness in the encoding. Rewrite this to not use mpsc pls
|
|
|
|
|
let mut buffer = String::new();
|
|
|
|
|
while input.read_line(&mut buffer).await? != 0 {
|
|
|
|
|
tx.send(buffer.clone()).await?;
|
|
|
|
|
buffer.clear();
|
|
|
|
|
}
|
|
|
|
|
Ok::<(), SendError>(())
|
|
|
|
|
};
|
|
|
|
|
let line_reader = async move {
|
|
|
|
|
macro_rules! take_one {
|
|
|
|
|
($msg:literal $($tt:tt)*) => {
|
|
|
|
|
loop {
|
|
|
|
|
if let Some(mut line) = rx.recv().await {
|
|
|
|
|
if line.trim().len() == 0 {
|
|
|
|
|
let bounds = {
|
|
|
|
|
let trimmed = buffer.trim();
|
|
|
|
|
if trimmed.len() == 0 {
|
|
|
|
|
continue;
|
|
|
|
|
} else if trimmed == "---" {
|
|
|
|
|
return Ok(true)
|
|
|
|
|
}
|
|
|
|
|
buffer.slice_bounds(trimmed)
|
|
|
|
|
};
|
|
|
|
|
buffer.slice_in_place(bounds);
|
|
|
|
|
if {
|
|
|
|
|
let bytes = line.as_bytes();
|
|
|
|
|
let bytes = buffer.as_bytes();
|
|
|
|
|
|
|
|
|
|
if bytes.len() > 0 && bytes[bytes.len()-1] == b'\n' {
|
|
|
|
|
true
|
|
|
|
@ -288,15 +284,24 @@ impl KeyHeader
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
} {
|
|
|
|
|
line.truncate(line.len()-1);
|
|
|
|
|
buffer.truncate(buffer.len()-1);
|
|
|
|
|
}
|
|
|
|
|
tx.send(buffer.clone()).await?;
|
|
|
|
|
buffer.clear();
|
|
|
|
|
}
|
|
|
|
|
break line;
|
|
|
|
|
warn!("Buffer contained no end-of-entry delimiter");
|
|
|
|
|
Ok::<bool, SendError>(false)
|
|
|
|
|
};
|
|
|
|
|
let line_reader = async move {
|
|
|
|
|
macro_rules! take_one {
|
|
|
|
|
($msg:literal $($tt:tt)*) => {
|
|
|
|
|
if let Some(line) = rx.recv().await {
|
|
|
|
|
line
|
|
|
|
|
} else {
|
|
|
|
|
return Err(eyre::eyre!(format!($msg $($tt)*))).wrap_err(eyre::eyre!("Failed to deserialise string"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trace!("Reading password");
|
|
|
|
@ -312,21 +317,9 @@ impl KeyHeader
|
|
|
|
|
};
|
|
|
|
|
trace!("Decoded hex");
|
|
|
|
|
let mut enc = String::new();
|
|
|
|
|
let mut had_delim =false;
|
|
|
|
|
while let Some(line) = rx.recv().await {
|
|
|
|
|
let line = line.trim();
|
|
|
|
|
if line.len() == 0 {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if line == "---" {
|
|
|
|
|
had_delim=true;
|
|
|
|
|
break;
|
|
|
|
|
} else if line.len()>0 {
|
|
|
|
|
enc.push_str(line)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !had_delim {
|
|
|
|
|
warn!("Buffer contained no end-of-entry delimiter");
|
|
|
|
|
debug_assert_eq!(&line[..], line.trim());
|
|
|
|
|
enc.push_str(&line[..]);
|
|
|
|
|
}
|
|
|
|
|
trace!("Done reading lines");
|
|
|
|
|
|
|
|
|
@ -361,12 +354,13 @@ impl KeyHeader
|
|
|
|
|
let (sres, rres) = tokio::join!(line_sender, line_reader);
|
|
|
|
|
match sres {
|
|
|
|
|
Err(x @ SendError::IO(_)) => Err(x).with_note(|| "In line reader"),
|
|
|
|
|
Err(_) => {
|
|
|
|
|
Err(_) | Ok(true) => {
|
|
|
|
|
trace!("We completed without reading whole file");
|
|
|
|
|
Ok(rres?)
|
|
|
|
|
},
|
|
|
|
|
_ => {
|
|
|
|
|
warn!("Header reading completed to EOF, there is no body in this stream.");
|
|
|
|
|
|
|
|
|
|
Ok(rres?)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|