@@ -1632,60 +1632,74 @@ impl Store {
16321632
16331633 tracing:: Span :: current ( ) . record ( "sender_data" , tracing:: field:: debug ( & sender_data) ) ;
16341634
1635- match sender_data {
1635+ if matches ! (
1636+ & sender_data,
16361637 SenderData :: UnknownDevice { .. }
1637- | SenderData :: VerificationViolation ( _)
1638- | SenderData :: DeviceInfo { .. } => {
1639- warn ! ( "Not accepting a historic room key bundle due to insufficient trust in the sender" ) ;
1640- Ok ( ( ) )
1638+ | SenderData :: VerificationViolation ( _)
1639+ | SenderData :: DeviceInfo { .. }
1640+ ) {
1641+ warn ! (
1642+ "Not accepting a historic room key bundle due to insufficient trust in the sender"
1643+ ) ;
1644+ return Ok ( ( ) ) ;
1645+ }
1646+
1647+ self . import_room_key_bundle_sessions ( bundle_info, & bundle, progress_listener) . await ?;
1648+
1649+ Ok ( ( ) )
1650+ }
1651+
1652+ async fn import_room_key_bundle_sessions (
1653+ & self ,
1654+ bundle_info : & StoredRoomKeyBundleData ,
1655+ bundle : & RoomKeyBundle ,
1656+ progress_listener : impl Fn ( usize , usize ) ,
1657+ ) -> Result < ( ) , CryptoStoreError > {
1658+ let ( good, bad) : ( Vec < _ > , Vec < _ > ) = bundle. room_keys . iter ( ) . partition_map ( |key| {
1659+ if key. room_id != bundle_info. bundle_data . room_id {
1660+ trace ! ( "Ignoring key for incorrect room {} in bundle" , key. room_id) ;
1661+ Either :: Right ( key)
1662+ } else {
1663+ Either :: Left ( key)
16411664 }
1642- SenderData :: SenderUnverified ( _) | SenderData :: SenderVerified ( _) => {
1643- let ( good, bad) : ( Vec < _ > , Vec < _ > ) = bundle. room_keys . iter ( ) . partition_map ( |key| {
1644- if key. room_id != bundle_info. bundle_data . room_id {
1645- trace ! ( "Ignoring key for incorrect room {} in bundle" , key. room_id) ;
1646- Either :: Right ( key)
1647- } else {
1648- Either :: Left ( key)
1649- }
1650- } ) ;
1665+ } ) ;
16511666
1652- match ( bad. is_empty ( ) , good. is_empty ( ) ) {
1653- // Case 1: Completely empty bundle.
1654- ( true , true ) => {
1655- warn ! ( "Received a completely empty room key bundle" ) ;
1656- }
1667+ match ( bad. is_empty ( ) , good. is_empty ( ) ) {
1668+ // Case 1: Completely empty bundle.
1669+ ( true , true ) => {
1670+ warn ! ( "Received a completely empty room key bundle" ) ;
1671+ }
16571672
1658- // Case 2: A bundle for the wrong room.
1659- ( false , true ) => {
1660- let bad_keys: Vec < _ > =
1661- bad. iter ( ) . map ( |& key| ( & key. room_id , & key. session_id ) ) . collect ( ) ;
1673+ // Case 2: A bundle for the wrong room.
1674+ ( false , true ) => {
1675+ let bad_keys: Vec < _ > =
1676+ bad. iter ( ) . map ( |& key| ( & key. room_id , & key. session_id ) ) . collect ( ) ;
16621677
1663- warn ! (
1678+ warn ! (
16641679 ?bad_keys,
16651680 "Received a room key bundle for the wrong room, ignoring all room keys from the bundle"
16661681 ) ;
1667- }
1682+ }
16681683
1669- // Case 3: A bundle containing useful room keys.
1670- ( _, false ) => {
1671- // We have at least some good keys, if we also have some bad ones let's
1672- // mention that here.
1673- if !bad. is_empty ( ) {
1674- warn ! (
1675- bad_key_count = bad. len( ) ,
1676- "The room key bundle contained some room keys \
1684+ // Case 3: A bundle containing useful room keys.
1685+ ( _, false ) => {
1686+ // We have at least some good keys, if we also have some bad ones let's
1687+ // mention that here.
1688+ if !bad. is_empty ( ) {
1689+ warn ! (
1690+ bad_key_count = bad. len( ) ,
1691+ "The room key bundle contained some room keys \
16771692 that were meant for a different room"
1678- ) ;
1679- }
1680-
1681- self . import_sessions_impl ( good, None , progress_listener) . await ?;
1682- }
1693+ ) ;
16831694 }
16841695
1685- Ok ( ( ) )
1696+ self . import_sessions_impl ( good , None , progress_listener ) . await ? ;
16861697 }
16871698 }
1699+
1700+ Ok ( ( ) )
16881701 }
1702+
16891703}
16901704
16911705impl Deref for Store {
0 commit comments