Basic message de/serialisation test passes. (Value -> Message -> SerializedMessage -> Bytes -> SerializedMessage -> Message -> Value). No encryption tests yet.

TODO: Better size checks.

TODO: Test message de/serialisation with encryption and/or signing enabled.

Fortune for rsh's current commit: Half curse − 半凶
specialisation
Avril 3 years ago
parent 3e59440609
commit 1f2655a7f2
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -260,10 +260,13 @@ impl<V: ?Sized + MessageValue> SerializedMessage<V>
};
(: $ser:expr) => {
{
let ser = serde_cbor::to_vec($ser)?;
write!(u64::try_from(ser.len())?.to_be_bytes());
write!(ser);
/*
let mut w2 = WriteCounter(0, &mut writer);
serde_cbor::to_writer(&mut w2, $ser)?;
w+=w2.0;
w+=w2.0;*/
}
};
}
@ -305,10 +308,18 @@ impl<V: ?Sized + MessageValue> SerializedMessage<V>
}
};
(: $ser:ty) => {
serde_cbor::from_reader::<$ser, _>(&mut reader).wrap_err(eyre!("Failed to deserialise {} from reader", std::any::type_name::<$ser>()))?
};
(:) => {
serde_cbor::from_reader(&mut reader).wrap_err(eyre!("Failed to deserialise type from reader"))?
{
let mut len = [0u8; std::mem::size_of::<u64>()];
read!(&mut len[..]);
let len = usize::try_from(u64::from_be_bytes(len))?;
//TODO: Find realistic max size for `$ser`.
if len > MAX_ALLOC_SIZE {
return Err(eyre!("Invalid length read: {}", len));
}
let mut de = Vec::with_capacity(len);
read!(&mut de, len);
serde_cbor::from_slice::<$ser>(&de[..]).wrap_err(eyre!("Failed to deserialise {} from reader", std::any::type_name::<$ser>()))?
}
};
($into:expr, $num:expr) => {
{

Loading…
Cancel
Save