-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make scp::Msg
derive(Digestible)
#127
make scp::Msg
derive(Digestible)
#127
Conversation
proc-macro2 = "0.4.4" | ||
quote = "0.6.3" | ||
syn = { version = "0.15", features = [ "extra-traits" ] } | ||
proc-macro2 = "1.0.8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually newer versions, but courtesy of mbedtls
and its dependency on an old bindgen
, we need to pin to these exact versions :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing is, there was a new version of cargo feature that can allow separating dependencies for build-time tools -- I don't know that we ever enabled it but it might help here? i'm not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sounds like it might not actually help yet anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is caused because we can only have one version of clang-sys
at a time. Right now grpc and mbedtls both need version 6, so that's the one we're stuck on.
.iter() | ||
.map(|variant| { | ||
let variant_ident = &variant.ident; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would want to add something like, variants.enumerate()
so that we know if this is the i
'th possibility, and then encode that number as a fixed width integer, e.g. a u32, and stick that in the hash before the other stuff. Something that is ensuring that there is a prefix-free representation of which variant it is before we start hitting the data associated to that value. Because the enum variant names are user generated and may not be fixed width or prefix free -- we'd like to ensure that there's no way that a hash from Option1 and Option2 can collide. that was the mechanism that I imagined would completely prevent that
This looks really good, thank you for doing this! |
let expanded = quote! { | ||
impl mc_crypto_digestible::Digestible for #ident { | ||
impl #impl_generics mc_crypto_digestible::Digestible for #ident #ty_generics #where_clause { | ||
fn digest<D: mc_crypto_digestible::Digest>(&self, hasher: &mut D) { | ||
hasher.input(stringify!(#ident).as_bytes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure you want to also inject the full path to each generic here as well, otherwise you can get hash collisions between, e.g. FlyingKite<Thing1>
and FlyingKite<Thing2>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value in the unit tests (L147) needs to include some indication of what the resolution of the generic is. i.e. Digestible derived for TestEnum<V>
needs to have some indication that V
is a u64
go into the hash.
I see, yeah, good point. |
This PR makes
scp::Msg
(and everything else that is needed in order to support that) deriveDigestible
. This would allow us to get rid of some hackish uses ofmcserial
, such as this one.This required making the derive macro support generics and enums, so there are a bunch of changes around that.