Uh oh!
There was an error while loading. Please reload this page.
Explicit Message Padding for OnionRealm0HopData - #469
Conversation
jkczyz
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround! Looks good.
| pub(crate) amt_to_forward: u64, | ||
| pub(crate) outgoing_cltv_value: u32, | ||
| // 12 bytes of 0-padding | ||
| pub(crate) padding: PhantomData<[u8; 12]>, |
There was a problem hiding this comment.
It's too bad RFC 2000 (rust-lang/rust#44580) isn't in the stable Rust release yet. Then we could type alias this as:
pub(crate)typeBytePadding<constN:usize> = ::std::marker::PhantomData<[u8;N]>;So this should be fine for now.
There was a problem hiding this comment.
We should probably do something like this anyway without generic constants. PhantomData has a somewhat specific meaning in Rust (that we have a template type that we're not going to instantiate). We probably just want a new type in ser.rs like (but with better names):
pub(crate) struct PaddingData<T: Default + std::convert::AsRef<[u8]>> {
t: std::marker::PhantomData<T>,
}
impl<T: Default + std::convert::AsRef<[u8]>> Writeable for PaddingData<T> {
#[inline]
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
let nt: T = Default::default();
w.write_all(nt.as_ref())
}
}
| impl Writeable for PhantomData<[u8; 12]> { | ||
| fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> { | ||
| w.write_all(&[0;12])?; |
9a0a3b7 to
1b2a1baCompare
TheBlueMatt
left a comment
There was a problem hiding this comment.
Happy to take this before 434, since it looks like that may get delayed a few days.
| pub(crate) amt_to_forward: u64, | ||
| pub(crate) outgoing_cltv_value: u32, | ||
| // 12 bytes of 0-padding | ||
| pub(crate) padding: PhantomData<[u8; 12]>, |
There was a problem hiding this comment.
We should probably do something like this anyway without generic constants. PhantomData has a somewhat specific meaning in Rust (that we have a template type that we're not going to instantiate). We probably just want a new type in ser.rs like (but with better names):
pub(crate) struct PaddingData<T: Default + std::convert::AsRef<[u8]>> {
t: std::marker::PhantomData<T>,
}
impl<T: Default + std::convert::AsRef<[u8]>> Writeable for PaddingData<T> {
#[inline]
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
let nt: T = Default::default();
w.write_all(nt.as_ref())
}
}
jkczyz
commented
Feb 18, 2020
@varunsrin#434 has been merged, so you should be able to rebase now. |
varunsrin
commented
Feb 21, 2020
perfect, ill get to this by early next week |
TheBlueMatt
commented
Mar 8, 2021
Closing as abandoned. If you want to pick this back up just respond here and we can open it again :) |
Fixes#467