@ -104,22 +104,13 @@ impl KeyHeader
#[ instrument(err, skip(out)) ]
#[ instrument(err, skip(out)) ]
pub async fn write_text < T : AsyncWrite + Unpin + ? Sized > ( & self , out : & mut T ) -> Result < usize , eyre ::Report >
pub async fn write_text < T : AsyncWrite + Unpin + ? Sized > ( & self , out : & mut T ) -> Result < usize , eyre ::Report >
{
{
let vec = serde_json ::to_vec ( self )
todo! ( )
. wrap_err_with ( | | eyre ::eyre ! ( "Failed to serialise self to JSON" ) )
. with_section ( | | format! ( "{:?}" , self ) . header ( "Self was" ) ) ? ;
out . write_all ( & vec [ .. ] ) . await ? ;
Ok ( vec . len ( ) )
}
}
/// Read a superheader as text bytes from this stream
/// Read a superheader as text bytes from this stream
#[ instrument(err, skip(input)) ]
#[ instrument(err, skip(input)) ]
pub async fn read_text < T : AsyncRead + Unpin + ? Sized > ( input : & mut T ) -> Result < Self , eyre ::Report >
pub async fn read_text < T : AsyncRead + Unpin + ? Sized > ( input : & mut T ) -> Result < Self , eyre ::Report >
{
{
let whole = input . read_whole_stream ( MAX_TEXT_SZ ) . await
todo! ( )
. wrap_err_with ( | | eyre ::eyre ! ( "Failed to read text stream into memory" ) ) ? ;
Ok ( serde_json ::from_slice ( & whole [ .. ] )
. wrap_err_with ( | | eyre ::eyre ! ( "Failed to deserialise JSON to value" ) )
. with_section ( move | | String ::from_utf8_lossy ( & whole [ .. ] ) . into_owned ( ) . header ( "Read text was" ) ) ? )
}
}
/// Write this key header as bytes to this stream
/// Write this key header as bytes to this stream
#[ instrument(err, skip(out)) ]
#[ instrument(err, skip(out)) ]
@ -269,7 +260,7 @@ mod tests
//color_eyre::install()?;
//color_eyre::install()?;
panic! ( "We're going to have to write our own text serialisation to get around the `read_whole_buffer` thingy..." ) ;
panic! ( "We're going to have to write our own text serialisation to get around the `read_whole_buffer` thingy..." ) ;
/*
let header = KeyHeader ::new_now ( KeyHeaderKind ::Aes , Default ::default ( ) , Default ::default ( ) ) ;
let header = KeyHeader ::new_now ( KeyHeaderKind ::Aes , Default ::default ( ) , Default ::default ( ) ) ;
let mut ser = Vec ::new ( ) ;
let mut ser = Vec ::new ( ) ;
let superheader = SuperHeader ::< KeyHeader > ::new_for ( & header ) ;
let superheader = SuperHeader ::< KeyHeader > ::new_for ( & header ) ;
@ -290,6 +281,6 @@ mod tests
assert_eq! ( readheader , header ) ;
assert_eq! ( readheader , header ) ;
assert_eq! ( reads , superheader ) ;
assert_eq! ( reads , superheader ) ;
Ok ( ( ) )
Ok ( ( ) ) * /
}
}
}
}