-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
require explicit conversions to and from address::DeviceId #289
require explicit conversions to and from address::DeviceId #289
Conversation
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 you've made a very strong case for why strong types are a good idea. ;-)
7bd9093
to
4896397
Compare
4896397
to
4227315
Compare
@jrose-signal I've split up this change into three logically separate commits to make it easier to review. |
8a01414
to
9a5a2ab
Compare
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.
Looks like the split up commits aren't quite split up right anyway, so I just reviewed this all together.
rust/protocol/src/state/session.rs
Outdated
let pending = session_structure::PendingPreKey { | ||
pre_key_id: pre_key_id.unwrap_or(0), | ||
pre_key_id: pre_key_id.unwrap_or(0.into()).into(), |
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.
Maybe pre_key_id.map(|id| id.into()).unwrap_or(0)
? I know it's both equivalent and a little longer, but it does make it clear that "0" is a placeholder rather than a real pre-key with ID #0.
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.
That makes much more sense!
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.
Looks like this missed the rebase.
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.
Still shows up in at least one other spot!
I double-checked and the message versions for SenderKeyMessage and SenderKeyDistributionMessage should be the same, as should SignalMessage and PreKeySignalMessage, but they are two different message families and so they should not be the same as each other. I'll put in a PR to record the SK(D)M version in the stored state like we do for 1-1 sessions. |
(That was #293.) |
44184fd
to
2648530
Compare
Thanks so much for fixing the |
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.
This is looking pretty good, but let's leave out some of the more complicated ones: MessageVersion (and the HKDF changes), and SignedPreKeyTimestamp
b5371c5
to
df2a1e0
Compare
1db6d8a
to
d6da511
Compare
Was having lots of difficulty making the bridge tests pass and would probably like your assistance on those changes independently, so have reverted the |
d6da511
to
1993ce6
Compare
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.
This one's pretty straightforward, so I picked it up first. Only a few comments.
rust/protocol/src/state/session.rs
Outdated
let pending = session_structure::PendingPreKey { | ||
pre_key_id: pre_key_id.unwrap_or(0), | ||
pre_key_id: pre_key_id.unwrap_or(0.into()).into(), |
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.
Looks like this missed the rebase.
2294852
to
9aa600f
Compare
9aa600f
to
27a64b7
Compare
dcbd8c3
to
7d55f25
Compare
Ok, one of the CI runs is failing reliably, and I can't reproduce it locally. I'm running ---- src/support/mod.rs - support::bridge_get (line 162) stdout ----
error: cannot find macro `bridge_get` in this scope
--> src/support/mod.rs:172:1
|
12 | bridge_get!(Foo::bar as GetBar -> &str, ffi = "foo_get_bar", jni = "Foo_GetBar", node = "Foo_GetBar");
| ^^^^^^^^^^ |
Hm, it looks like that exact failure is happening for all the other PRs I have open right now as well. It seems like the CI might be wonky. |
7d55f25
to
8b1112c
Compare
Ah, right, because doctests now get run on macro docs! We have a fix for this privately (because we updated our pinned nightly). Don't worry about it here; since I'll be cherry-picking things to the private branch, I'll make sure it works there before merging and closing the public branch. |
Cherry-picked as ec3c2d3, will be in the next release! |
Problem
See https://github.com/signalapp/libsignal-client/pull/286/files#r625970592 from #286 for motivation. We currently use
u32
to mean different things in different places, including in the.device_id()
method ofaddress::ProtocolAddress
. We would prefer instead to require an explicit.into()
from an intermediate struct that looks like:So note that this is not part of the documentation push in #285, but rather a separate type of refactoring change.
Solution
(all of the below also have docstrings)
address::DeviceId
wrappingu32
.storage::prekey::PreKeyId
wrappingu32
.storage::signed_prekey::SignedPreKeyId
wrappingu32
..into()
calls to convert to and fromu32
as necessary to make tests pass.Result
We don't accidentally mistake a device id for a chain counter!