@@ -30,30 +30,37 @@ use crate::proto::sync_message::PniChangeNumber;
3030use crate :: proto:: { DeviceName , SyncMessage } ;
3131use crate :: provisioning:: generate_registration_id;
3232use crate :: push_service:: {
33- AvatarWrite , CaptchaAttributes , DeviceActivationRequest , DeviceInfo ,
34- HttpAuthOverride , RegistrationMethod , ReqwestExt , VerifyAccountResponse ,
35- DEFAULT_DEVICE_ID ,
33+ AvatarWrite , HttpAuthOverride , ReqwestExt , DEFAULT_DEVICE_ID ,
3634} ;
3735use crate :: sender:: OutgoingPushMessage ;
3836use crate :: service_address:: ServiceIdExt ;
3937use crate :: session_store:: SessionStoreExt ;
4038use crate :: timestamp:: TimestampExt as _;
4139use crate :: utils:: { random_length_padding, BASE64_RELAXED } ;
40+ use crate :: websocket:: account:: DeviceInfo ;
41+ use crate :: websocket:: keys:: PreKeyStatus ;
42+ use crate :: websocket:: registration:: {
43+ CaptchaAttributes , DeviceActivationRequest , RegistrationMethod ,
44+ VerifyAccountResponse ,
45+ } ;
46+ use crate :: websocket:: { self , SignalWebSocket } ;
4247use crate :: {
4348 configuration:: { Endpoint , ServiceCredentials } ,
4449 pre_keys:: PreKeyState ,
4550 profile_cipher:: { ProfileCipher , ProfileCipherError } ,
4651 profile_name:: ProfileName ,
4752 proto:: { ProvisionEnvelope , ProvisionMessage , ProvisioningVersion } ,
4853 provisioning:: { ProvisioningCipher , ProvisioningError } ,
49- push_service:: { AccountAttributes , PushService , ServiceError } ,
54+ push_service:: { PushService , ServiceError } ,
5055 utils:: serde_base64,
56+ websocket:: account:: AccountAttributes ,
5157} ;
5258
5359type Aes256Ctr128BE = ctr:: Ctr128BE < aes:: Aes256 > ;
5460
5561pub struct AccountManager {
5662 service : PushService ,
63+ websocket : SignalWebSocket < websocket:: Identified > ,
5764 profile_key : Option < ProfileKey > ,
5865}
5966
@@ -75,9 +82,14 @@ pub struct Profile {
7582}
7683
7784impl AccountManager {
78- pub fn new ( service : PushService , profile_key : Option < ProfileKey > ) -> Self {
85+ pub fn new (
86+ service : PushService ,
87+ websocket : SignalWebSocket < websocket:: Identified > ,
88+ profile_key : Option < ProfileKey > ,
89+ ) -> Self {
7990 Self {
8091 service,
92+ websocket,
8193 profile_key,
8294 }
8395 }
@@ -122,7 +134,7 @@ impl AccountManager {
122134 hash. update ( ( u32:: from ( kyber_prekey_id) as u64 ) . to_be_bytes ( ) ) ;
123135 hash. update ( kyber_prekey. public_key ( ) ?. serialize ( ) ) ;
124136
125- self . service
137+ self . websocket
126138 . check_pre_keys ( service_id_kind, hash. finalize ( ) . as_ref ( ) )
127139 . await
128140 }
@@ -134,16 +146,15 @@ impl AccountManager {
134146 ///
135147 /// Equivalent to Java's RefreshPreKeysJob
136148 #[ allow( clippy:: too_many_arguments) ]
137- #[ tracing:: instrument( skip( self , csprng , protocol_store) ) ]
138- pub async fn update_pre_key_bundle < R : Rng + CryptoRng , P : PreKeysStore > (
149+ #[ tracing:: instrument( skip( self , protocol_store) ) ]
150+ pub async fn update_pre_key_bundle < P : PreKeysStore > (
139151 & mut self ,
140152 protocol_store : & mut P ,
141153 service_id_kind : ServiceIdKind ,
142154 use_last_resort_key : bool ,
143- csprng : & mut R ,
144155 ) -> Result < ( ) , ServiceError > {
145156 let prekey_status = match self
146- . service
157+ . websocket
147158 . get_pre_key_status ( service_id_kind)
148159 . instrument ( tracing:: span!(
149160 tracing:: Level :: DEBUG ,
@@ -156,7 +167,7 @@ impl AccountManager {
156167 tracing:: info!( "Got Unauthorized when fetching pre-key status. Assuming first installment." ) ;
157168 // Additionally, the second PUT request will fail if this really comes down to an
158169 // authorization failure.
159- crate :: push_service :: PreKeyStatus {
170+ PreKeyStatus {
160171 count : 0 ,
161172 pq_count : 0 ,
162173 }
@@ -218,7 +229,7 @@ impl AccountManager {
218229 let ( pre_keys, signed_pre_key, pq_pre_keys, pq_last_resort_key) =
219230 crate :: pre_keys:: replenish_pre_keys (
220231 protocol_store,
221- csprng ,
232+ & mut rand :: rng ( ) ,
222233 & identity_key_pair,
223234 use_last_resort_key && !has_last_resort_key,
224235 PRE_KEY_BATCH_SIZE ,
@@ -266,7 +277,7 @@ impl AccountManager {
266277 pq_last_resort_key,
267278 } ;
268279
269- self . service
280+ self . websocket
270281 . register_pre_keys ( service_id_kind, pre_key_state)
271282 . instrument ( tracing:: span!(
272283 tracing:: Level :: DEBUG ,
@@ -425,7 +436,7 @@ impl AccountManager {
425436 & mut self ,
426437 aci_identity_store : & dyn IdentityKeyStore ,
427438 ) -> Result < Vec < DeviceInfo > , ServiceError > {
428- let device_infos = self . service . devices ( ) . await ?;
439+ let device_infos = self . websocket . devices ( ) . await ?;
429440 let aci_identity_keypair =
430441 aci_identity_store. get_identity_key_pair ( ) . await ?;
431442
@@ -520,7 +531,7 @@ impl AccountManager {
520531 } ;
521532
522533 let result = self
523- . service
534+ . websocket
524535 . submit_registration_request (
525536 registration_method,
526537 account_attributes,
@@ -580,7 +591,7 @@ impl AccountManager {
580591 self . profile_key . expect ( "set profile key in AccountManager" ) ;
581592
582593 let encrypted_profile = self
583- . service
594+ . websocket
584595 . retrieve_profile_by_id ( address, Some ( profile_key) )
585596 . await ?;
586597
@@ -630,7 +641,7 @@ impl AccountManager {
630641 let profile_key_version = profile_key. get_profile_key_version ( aci) ;
631642
632643 Ok ( self
633- . service
644+ . websocket
634645 . write_profile :: < C , S > (
635646 & profile_key_version,
636647 & name,
@@ -649,7 +660,7 @@ impl AccountManager {
649660 & mut self ,
650661 attributes : AccountAttributes ,
651662 ) -> Result < ( ) , ServiceError > {
652- self . service . set_account_attributes ( attributes) . await
663+ self . websocket . set_account_attributes ( attributes) . await
653664 }
654665
655666 /// Update (encrypted) device name
@@ -910,7 +921,7 @@ impl AccountManager {
910921 device_messages. push ( msg) ;
911922 }
912923
913- self . service
924+ self . websocket
914925 . distribute_pni_keys (
915926 pni_identity_key,
916927 device_messages,
@@ -925,7 +936,6 @@ impl AccountManager {
925936 }
926937}
927938
928- #[ expect( clippy:: result_large_err) ]
929939fn calculate_hmac256 (
930940 mac_key : & [ u8 ] ,
931941 ciphertext : & [ u8 ] ,
@@ -936,7 +946,6 @@ fn calculate_hmac256(
936946 Ok ( mac. finalize ( ) . into_bytes ( ) )
937947}
938948
939- #[ expect( clippy:: result_large_err) ]
940949pub fn encrypt_device_name < R : rand:: Rng + rand:: CryptoRng > (
941950 csprng : & mut R ,
942951 device_name : & str ,
@@ -973,7 +982,6 @@ pub fn encrypt_device_name<R: rand::Rng + rand::CryptoRng>(
973982 Ok ( device_name)
974983}
975984
976- #[ expect( clippy:: result_large_err) ]
977985fn decrypt_device_name_from_device_info (
978986 string : & str ,
979987 aci : & IdentityKeyPair ,
@@ -983,7 +991,6 @@ fn decrypt_device_name_from_device_info(
983991 crate :: decrypt_device_name ( aci. private_key ( ) , & name)
984992}
985993
986- #[ expect( clippy:: result_large_err) ]
987994pub fn decrypt_device_name (
988995 private_key : & PrivateKey ,
989996 device_name : & DeviceName ,
0 commit comments