Skip to content

Commit

Permalink
crypto: Mark all new SenderData info as non-legacy
Browse files Browse the repository at this point in the history
Since we now have a clear idea of the structure, and anything we create
now should be usable in future.
  • Loading branch information
andybalaam committed Jul 31, 2024
1 parent 25df9a1 commit 6df1b0c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ mod tests {
"signing_key":{"ed25519":"wTRTdz4rn4EY+68cKPzpMdQ6RAlg7T8cbTmEjaXuUww"},
"sender_data":{
"UnknownDevice":{
"legacy_session":true
"legacy_session":false
}
},
"room_id":"!test:localhost",
Expand Down
19 changes: 5 additions & 14 deletions crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,16 @@ pub enum SenderData {
}

impl SenderData {
/// Create a [`SenderData`] which contains no device info and will be
/// retried soon.
/// Create a [`SenderData`] which contains no device info.
pub fn unknown() -> Self {
Self::UnknownDevice {
// TODO: when we have implemented all of SenderDataFinder,
// legacy_session should be set to false, but for now we leave
// it as true because we might lose device info while
// this code is still in transition.
legacy_session: true,
owner_check_failed: false,
}
Self::UnknownDevice { legacy_session: false, owner_check_failed: false }
}

/// Create a [`SenderData`] which has the legacy flag set. Caution: messages
/// within sessions with this flag will be displayed in some contexts,
/// even when we are unable to verify the sender.
///
/// The returned struct contains no device info, and will be retried soon.
/// The returned struct contains no device info.
pub fn legacy() -> Self {
Self::UnknownDevice { legacy_session: true, owner_check_failed: false }
}
Expand All @@ -102,9 +94,8 @@ impl SenderData {
/// Used when deserialising and the sender_data property is missing.
/// If we are deserialising an InboundGroupSession session with missing
/// sender_data, this must be a legacy session (i.e. it was created before we
/// started tracking sender data). We set its legacy flag to true, and set it up
/// to be retried soon, so we can populate it with trust information if it is
/// available.
/// started tracking sender data). We set its legacy flag to true, so we can
/// populate it with trust information if it is available later.
impl Default for SenderData {
fn default() -> Self {
Self::legacy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ impl<'a> SenderDataFinder<'a> {
let sender_data = SenderData::UnknownDevice {
// This is not a legacy session since we did attempt to look
// up its sender data at the time of reception.
// legacy_session: false,
// TODO: we set legacy to true for now, since our implementation is incomplete, so
// we may not have had a proper chance to look up the sender data.
legacy_session: true,
legacy_session: false,
owner_check_failed: false,
};
Ok(sender_data)
Expand Down Expand Up @@ -247,10 +244,7 @@ impl<'a> SenderDataFinder<'a> {
(false, _) => {
// Step E (the device does not own the session)
// Give up: something is wrong with the session.
SenderData::UnknownDevice {
legacy_session: true, // TODO: change to false when all SenderData work is done
owner_check_failed: true,
}
SenderData::UnknownDevice { legacy_session: false, owner_check_failed: true }
}
})
}
Expand Down Expand Up @@ -420,10 +414,7 @@ mod tests {
// Then we get back no useful information at all
assert_let!(SenderData::UnknownDevice { legacy_session, owner_check_failed } = sender_data);

// TODO: This should not be marked as a legacy session, but for now it is
// because we haven't finished implementing the whole sender_data and
// retry mechanism.
assert!(legacy_session);
assert!(!legacy_session);
assert!(!owner_check_failed);
}

Expand Down Expand Up @@ -680,10 +671,7 @@ mod tests {
// Then we fail to find useful sender data
assert_let!(SenderData::UnknownDevice { legacy_session, owner_check_failed } = sender_data);

// TODO: This should not be marked as a legacy session, but for now it is
// because we haven't finished implementing the whole sender_data and
// retry mechanism.
assert!(legacy_session);
assert!(!legacy_session);

// And report that the owner_check_failed
assert!(owner_check_failed);
Expand Down

0 comments on commit 6df1b0c

Please sign in to comment.