@@ -25,13 +25,14 @@ use crate::{
2525 utils:: BASE64_RELAXED ,
2626 ServiceIdExt ,
2727} ;
28+
2829/// Decrypts incoming messages and encrypts outgoing messages.
2930///
3031/// Equivalent of SignalServiceCipher in Java.
3132#[ derive( Clone ) ]
3233pub struct ServiceCipher < S > {
3334 protocol_store : S ,
34- trust_root : PublicKey ,
35+ trust_roots : Vec < PublicKey > ,
3536 local_uuid : Uuid ,
3637 local_device_id : DeviceId ,
3738}
@@ -74,13 +75,13 @@ where
7475{
7576 pub fn new (
7677 protocol_store : S ,
77- trust_root : PublicKey ,
78+ trust_roots : Vec < PublicKey > ,
7879 local_uuid : Uuid ,
7980 local_device_id : DeviceId ,
8081 ) -> Self {
8182 Self {
8283 protocol_store,
83- trust_root ,
84+ trust_roots ,
8485 local_uuid,
8586 local_device_id,
8687 }
@@ -309,7 +310,8 @@ where
309310 mut message,
310311 } = sealed_sender_decrypt (
311312 ciphertext,
312- & self . trust_root ,
313+ // Turn Vec<PublicKey> into Vec<&PublicKey> and then coerce into &[&PublicKey]
314+ & self . trust_roots . iter ( ) . collect :: < Vec < _ > > ( ) ,
313315 Timestamp :: from_epoch_millis ( envelope. timestamp ( ) ) ,
314316 None ,
315317 self . local_uuid . to_string ( ) ,
@@ -528,7 +530,7 @@ pub async fn get_preferred_protocol_address<S: SessionStore>(
528530#[ tracing:: instrument(
529531 skip(
530532 ciphertext,
531- trust_root ,
533+ trust_roots ,
532534 identity_store,
533535 session_store,
534536 pre_key_store,
@@ -542,7 +544,7 @@ pub async fn get_preferred_protocol_address<S: SessionStore>(
542544) ]
543545async fn sealed_sender_decrypt (
544546 ciphertext : & [ u8 ] ,
545- trust_root : & PublicKey ,
547+ trust_roots : & [ & PublicKey ] ,
546548 timestamp : Timestamp ,
547549 local_e164 : Option < String > ,
548550 local_uuid : String ,
@@ -557,7 +559,10 @@ async fn sealed_sender_decrypt(
557559 let usmc =
558560 sealed_sender_decrypt_to_usmc ( ciphertext, identity_store) . await ?;
559561
560- if !usmc. sender ( ) ?. validate ( trust_root, timestamp) ? {
562+ if !usmc
563+ . sender ( ) ?
564+ . validate_with_trust_roots ( trust_roots, timestamp) ?
565+ {
561566 return Err ( SignalProtocolError :: InvalidSealedSenderMessage (
562567 "trust root validation failed" . to_string ( ) ,
563568 ) ) ;
0 commit comments