@@ -499,37 +499,6 @@ impl PrivateCrossSigningIdentity {
499499 . sign ( message) )
500500 }
501501
502- /// Create a new identity for the given Olm Account.
503- ///
504- /// Returns the new identity, the upload signing keys request and a
505- /// signature upload request that contains the signature of the account
506- /// signed by the self signing key.
507- ///
508- /// # Arguments
509- ///
510- /// * `account` - The Olm account that is creating the new identity. The
511- /// account will sign the master key and the self signing key will sign
512- /// the account.
513- pub ( crate ) async fn with_account (
514- account : & Account ,
515- ) -> ( Self , UploadSigningKeysRequest , SignatureUploadRequest ) {
516- let mut master = MasterSigning :: new ( account. user_id ( ) . into ( ) ) ;
517-
518- account
519- . sign_cross_signing_key ( master. public_key_mut ( ) . as_mut ( ) )
520- . expect ( "Can't sign our freshly created master key with our account" ) ;
521-
522- let identity = Self :: new_helper ( account. user_id ( ) , master) ;
523- let signature_request = identity
524- . sign_account ( account. static_data ( ) )
525- . await
526- . expect ( "Can't sign own device with new cross signing keys" ) ;
527-
528- let request = identity. as_upload_request ( ) . await ;
529-
530- ( identity, request, signature_request)
531- }
532-
533502 fn new_helper ( user_id : & UserId , master : MasterSigning ) -> Self {
534503 let ( user, self_signing) = master. new_subkeys ( ) ;
535504
@@ -551,6 +520,32 @@ impl PrivateCrossSigningIdentity {
551520 Self :: new_helper ( & user_id, master)
552521 }
553522
523+ /**
524+ * Create a new private identity, suitable for the given [`Account`].
525+ *
526+ * The identity will be created with a fresh set of cross-signing keys.
527+ * The master key will be signed by the `OlmAccount` (i.e. the device).
528+ * The user-signing and self-signing keys will be signed by the
529+ * master key.
530+ *
531+ * Note that after creating a new identity, the device will need to be
532+ * signed by the self-signing key. This can be done via
533+ * [`PrivateCrossSigningIdentity::sign_account`].
534+ *
535+ * # Arguments
536+ *
537+ * * `account` - The Olm account that is creating the new identity.
538+ */
539+ pub ( crate ) fn for_account ( account : & Account ) -> PrivateCrossSigningIdentity {
540+ let mut master = MasterSigning :: new ( account. user_id ( ) . into ( ) ) ;
541+
542+ account
543+ . sign_cross_signing_key ( master. public_key_mut ( ) . as_mut ( ) )
544+ . expect ( "Can't sign our freshly created master key with our account" ) ;
545+
546+ Self :: new_helper ( account. user_id ( ) , master)
547+ }
548+
554549 #[ cfg( any( test, feature = "testing" ) ) ]
555550 #[ allow( dead_code) ]
556551 /// Testing helper to reset this CrossSigning with a fresh one using the
@@ -726,7 +721,7 @@ mod tests {
726721 #[ async_test]
727722 async fn test_private_identity_signed_by_account ( ) {
728723 let account = Account :: with_device_id ( user_id ( ) , device_id ! ( "DEVICEID" ) ) ;
729- let ( identity, _ , _ ) = PrivateCrossSigningIdentity :: with_account ( & account) . await ;
724+ let identity = PrivateCrossSigningIdentity :: for_account ( & account) ;
730725 let master = identity. master_key . lock ( ) . await ;
731726 let master = master. as_ref ( ) . unwrap ( ) ;
732727
@@ -749,7 +744,7 @@ mod tests {
749744 #[ async_test]
750745 async fn test_sign_device ( ) {
751746 let account = Account :: with_device_id ( user_id ( ) , device_id ! ( "DEVICEID" ) ) ;
752- let ( identity, _ , _ ) = PrivateCrossSigningIdentity :: with_account ( & account) . await ;
747+ let identity = PrivateCrossSigningIdentity :: for_account ( & account) ;
753748
754749 let mut device = DeviceData :: from_account ( & account) ;
755750 let self_signing = identity. self_signing_key . lock ( ) . await ;
@@ -766,11 +761,11 @@ mod tests {
766761 #[ async_test]
767762 async fn test_sign_user_identity ( ) {
768763 let account = Account :: with_device_id ( user_id ( ) , device_id ! ( "DEVICEID" ) ) ;
769- let ( identity, _ , _ ) = PrivateCrossSigningIdentity :: with_account ( & account) . await ;
764+ let identity = PrivateCrossSigningIdentity :: for_account ( & account) ;
770765
771766 let bob_account =
772767 Account :: with_device_id ( user_id ! ( "@bob:localhost" ) , device_id ! ( "DEVICEID" ) ) ;
773- let ( bob_private, _ , _ ) = PrivateCrossSigningIdentity :: with_account ( & bob_account) . await ;
768+ let bob_private = PrivateCrossSigningIdentity :: for_account ( & bob_account) ;
774769 let mut bob_public = OtherUserIdentityData :: from_private ( & bob_private) . await ;
775770
776771 let user_signing = identity. user_signing_key . lock ( ) . await ;
0 commit comments