From a68fd8b44fdad8c81c24d948c02fa31f85110df9 Mon Sep 17 00:00:00 2001 From: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:12:03 -0400 Subject: [PATCH] [PM-24721] Refactor AccountKeys to top-level common model (#5693) --- .../auth/datasource/disk/AuthDiskSource.kt | 5 +- .../datasource/disk/AuthDiskSourceImpl.kt | 5 +- .../datasource/disk/AuthDiskSourceTest.kt | 8 +- .../disk/util/FakeAuthDiskSource.kt | 7 +- .../auth/repository/AuthRepositoryTest.kt | 2 + .../util/GetTokenResponseExtensionsTest.kt | 2 + .../network/model/AccountKeysJson.kt | 75 ++++++++++++++++++ .../network/model/GetTokenResponseJson.kt | 12 +++ .../network/model/SyncResponseJson.kt | 78 ++----------------- .../network/service/IdentityServiceTest.kt | 19 +++++ .../network/model/AccountKeysJsonUtil.kt | 55 +++++++++++++ .../network/model/SyncResponseProfileUtil.kt | 56 +------------ 12 files changed, 185 insertions(+), 139 deletions(-) create mode 100644 network/src/main/kotlin/com/bitwarden/network/model/AccountKeysJson.kt create mode 100644 network/src/testFixtures/kotlin/com/bitwarden/network/model/AccountKeysJsonUtil.kt diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSource.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSource.kt index ac9e5aab86..ef19e6a847 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSource.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSource.kt @@ -1,5 +1,6 @@ package com.x8bit.bitwarden.data.auth.datasource.disk +import com.bitwarden.network.model.AccountKeysJson import com.bitwarden.network.model.SyncResponseJson import com.bitwarden.network.provider.AppIdProvider import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson @@ -144,14 +145,14 @@ interface AuthDiskSource : AppIdProvider { /** * Returns the profile account keys for the given [userId]. */ - fun getAccountKeys(userId: String): SyncResponseJson.Profile.AccountKeys? + fun getAccountKeys(userId: String): AccountKeysJson? /** * Stores the profile account keys for the given [userId]. */ fun storeAccountKeys( userId: String, - accountKeys: SyncResponseJson.Profile.AccountKeys?, + accountKeys: AccountKeysJson?, ) /** diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt index 3d3c2ee8f1..68d4032e48 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt @@ -4,6 +4,7 @@ import android.content.SharedPreferences import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow import com.bitwarden.core.data.util.decodeFromStringOrNull import com.bitwarden.data.datasource.disk.BaseEncryptedDiskSource +import com.bitwarden.network.model.AccountKeysJson import com.bitwarden.network.model.SyncResponseJson import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus @@ -242,13 +243,13 @@ class AuthDiskSourceImpl( ) } - override fun getAccountKeys(userId: String): SyncResponseJson.Profile.AccountKeys? = + override fun getAccountKeys(userId: String): AccountKeysJson? = getEncryptedString(key = PROFILE_ACCOUNT_KEYS_KEY.appendIdentifier(userId)) ?.let { json.decodeFromStringOrNull(it) } override fun storeAccountKeys( userId: String, - accountKeys: SyncResponseJson.Profile.AccountKeys?, + accountKeys: AccountKeysJson?, ) { putEncryptedString( key = PROFILE_ACCOUNT_KEYS_KEY.appendIdentifier(userId), diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt index 5dde1d5731..8d460330e8 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt @@ -10,9 +10,9 @@ import com.bitwarden.network.model.KdfTypeJson import com.bitwarden.network.model.KeyConnectorUserDecryptionOptionsJson import com.bitwarden.network.model.TrustedDeviceUserDecryptionOptionsJson import com.bitwarden.network.model.UserDecryptionOptionsJson +import com.bitwarden.network.model.createMockAccountKeysJson import com.bitwarden.network.model.createMockOrganization import com.bitwarden.network.model.createMockPolicy -import com.bitwarden.network.model.createMockPrivateKeys import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountJson import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason @@ -283,7 +283,7 @@ class AuthDiskSourceTest { authDiskSource.storePrivateKey(userId = userId, privateKey = "privateKey") authDiskSource.storeAccountKeys( userId = userId, - accountKeys = createMockPrivateKeys(number = 1), + accountKeys = createMockAccountKeysJson(number = 1), ) authDiskSource.storeOrganizationKeys( userId = userId, @@ -486,7 +486,7 @@ class AuthDiskSourceTest { fun `getAccountKeys should pull from SharedPreferences`() { val accountKeysBaseKey = "bwSecureStorage:profileAccountKeys" val mockUserId = "mockUserId" - val mockAccountKeys = createMockPrivateKeys(number = 1) + val mockAccountKeys = createMockAccountKeysJson(number = 1) fakeEncryptedSharedPreferences.edit { putString( "${accountKeysBaseKey}_$mockUserId", @@ -504,7 +504,7 @@ class AuthDiskSourceTest { fun `storeAccountKeys should update sharedPreferences`() { val accountKeysBaseKey = "bwSecureStorage:profileAccountKeys" val mockUserId = "mockUserId" - val mockAccountKeys = createMockPrivateKeys(number = 1) + val mockAccountKeys = createMockAccountKeysJson(number = 1) authDiskSource.storeAccountKeys( userId = mockUserId, accountKeys = mockAccountKeys, diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/util/FakeAuthDiskSource.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/util/FakeAuthDiskSource.kt index afe29c747c..f8307e05b0 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/util/FakeAuthDiskSource.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/util/FakeAuthDiskSource.kt @@ -1,6 +1,7 @@ package com.x8bit.bitwarden.data.auth.datasource.disk.util import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow +import com.bitwarden.network.model.AccountKeysJson import com.bitwarden.network.model.SyncResponseJson import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson @@ -63,7 +64,7 @@ class FakeAuthDiskSource : AuthDiskSource { private val storedOnboardingStatus = mutableMapOf() private val storedShowImportLogins = mutableMapOf() private val storedLastLockTimestampState = mutableMapOf() - private val storedAccountKeys = mutableMapOf() + private val storedAccountKeys = mutableMapOf() override var userState: UserStateJson? = null set(value) { @@ -146,12 +147,12 @@ class FakeAuthDiskSource : AuthDiskSource { storedPrivateKeys[userId] = privateKey } - override fun getAccountKeys(userId: String): SyncResponseJson.Profile.AccountKeys? = + override fun getAccountKeys(userId: String): AccountKeysJson? = storedAccountKeys[userId] override fun storeAccountKeys( userId: String, - accountKeys: SyncResponseJson.Profile.AccountKeys?, + accountKeys: AccountKeysJson?, ) { storedAccountKeys[userId] = accountKeys } diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt index 4f03fc1673..e6472173fb 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt @@ -51,6 +51,7 @@ import com.bitwarden.network.model.UserDecryptionOptionsJson import com.bitwarden.network.model.VerifiedOrganizationDomainSsoDetailsResponse import com.bitwarden.network.model.VerifyEmailTokenRequestJson import com.bitwarden.network.model.VerifyEmailTokenResponseJson +import com.bitwarden.network.model.createMockAccountKeysJson import com.bitwarden.network.model.createMockOrganization import com.bitwarden.network.model.createMockPolicy import com.bitwarden.network.service.AccountsService @@ -6714,6 +6715,7 @@ class AuthRepositoryTest { kdfMemory = 16, kdfParallelism = 4, privateKey = "privateKey", + accountKeys = createMockAccountKeysJson(number = 1), shouldForcePasswordReset = true, shouldResetMasterPassword = true, twoFactorToken = null, diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensionsTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensionsTest.kt index 5c03e62696..2dadfa8fdf 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensionsTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensionsTest.kt @@ -6,6 +6,7 @@ import com.bitwarden.network.model.JwtTokenDataJson import com.bitwarden.network.model.KdfTypeJson import com.bitwarden.network.model.TrustedDeviceUserDecryptionOptionsJson import com.bitwarden.network.model.UserDecryptionOptionsJson +import com.bitwarden.network.model.createMockAccountKeysJson import com.bitwarden.network.util.parseJwtTokenDataOrNull import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountJson import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason @@ -109,6 +110,7 @@ private val GET_TOKEN_RESPONSE_SUCCESS = GetTokenResponseJson.Success( kdfMemory = 16, kdfParallelism = 4, privateKey = "privateKey", + accountKeys = createMockAccountKeysJson(number = 1), shouldForcePasswordReset = false, shouldResetMasterPassword = true, twoFactorToken = null, diff --git a/network/src/main/kotlin/com/bitwarden/network/model/AccountKeysJson.kt b/network/src/main/kotlin/com/bitwarden/network/model/AccountKeysJson.kt new file mode 100644 index 0000000000..45f9cf22e5 --- /dev/null +++ b/network/src/main/kotlin/com/bitwarden/network/model/AccountKeysJson.kt @@ -0,0 +1,75 @@ +package com.bitwarden.network.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents private keys in the vault response. + * + * @property signatureKeyPair The signature key pair of the profile. + * @property publicKeyEncryptionKeyPair The public key encryption key pair of the profile. + * @property securityState The security state of the profile (nullable). + */ +@Serializable +data class AccountKeysJson( + @SerialName("signatureKeyPair") + val signatureKeyPair: SignatureKeyPair?, + + @SerialName("publicKeyEncryptionKeyPair") + val publicKeyEncryptionKeyPair: PublicKeyEncryptionKeyPair, + + @SerialName("securityState") + val securityState: SecurityState?, +) { + + /** + * Represents a signature key pair in the vault response. + * + * @property wrappedSigningKey The wrapped signing key of the signature key pair. + * @property verifyingKey The verifying key of the signature key pair. + */ + @Serializable + data class SignatureKeyPair( + @SerialName("wrappedSigningKey") + val wrappedSigningKey: String, + + @SerialName("verifyingKey") + val verifyingKey: String, + ) + + /** + * Represents a public key encryption key pair in the vault response. + * + * @property wrappedPrivateKey The wrapped private key of the public key encryption key + * pair. + * @property publicKey The public key of the public key encryption key pair. + * @property signedPublicKey The signed public key of the public key encryption key pair + * (nullable). + */ + @Serializable + data class PublicKeyEncryptionKeyPair( + @SerialName("wrappedPrivateKey") + val wrappedPrivateKey: String, + + @SerialName("publicKey") + val publicKey: String, + + @SerialName("signedPublicKey") + val signedPublicKey: String?, + ) + + /** + * Represents security state in the vault response. + * + * @property securityState The security state of the profile. + * @property securityVersion The security version of the profile. + */ + @Serializable + data class SecurityState( + @SerialName("securityState") + val securityState: String, + + @SerialName("securityVersion") + val securityVersion: Int, + ) +} diff --git a/network/src/main/kotlin/com/bitwarden/network/model/GetTokenResponseJson.kt b/network/src/main/kotlin/com/bitwarden/network/model/GetTokenResponseJson.kt index 26bac11b4f..15721d0b34 100644 --- a/network/src/main/kotlin/com/bitwarden/network/model/GetTokenResponseJson.kt +++ b/network/src/main/kotlin/com/bitwarden/network/model/GetTokenResponseJson.kt @@ -23,6 +23,9 @@ sealed class GetTokenResponseJson { * @property kdfIterations The number of iterations when calculating a user's password. * @property kdfMemory The amount of memory to use when calculating a password hash (MB). * @property kdfParallelism The number of threads to use when calculating a password hash. + * @property accountKeys The user's account keys, which include the signature key pair and + * public key encryption key pair. This is temporarily nullable to support older accounts that + * have not been upgraded to use account keys instead of the deprecated `PrivateKey` field. * @property shouldForcePasswordReset Whether or not the app must force a password reset. * @property shouldResetMasterPassword Whether or not the user is required to reset their * master password. @@ -49,6 +52,12 @@ sealed class GetTokenResponseJson { @SerialName("Key") val key: String?, + @Deprecated( + message = "Use `accountKeys` instead.", + replaceWith = ReplaceWith( + "loginResponse.accountKeys?.publicKeyEncryptionKeyPair?.wrappedPrivateKey", + ), + ) @SerialName("PrivateKey") val privateKey: String?, @@ -64,6 +73,9 @@ sealed class GetTokenResponseJson { @SerialName("KdfParallelism") val kdfParallelism: Int?, + @SerialName("AccountKeys") + val accountKeys: AccountKeysJson?, + @SerialName("ForcePasswordReset") val shouldForcePasswordReset: Boolean, diff --git a/network/src/main/kotlin/com/bitwarden/network/model/SyncResponseJson.kt b/network/src/main/kotlin/com/bitwarden/network/model/SyncResponseJson.kt index 999d0b2574..2ebca7df6b 100644 --- a/network/src/main/kotlin/com/bitwarden/network/model/SyncResponseJson.kt +++ b/network/src/main/kotlin/com/bitwarden/network/model/SyncResponseJson.kt @@ -177,12 +177,15 @@ data class SyncResponseJson( @SerialName("twoFactorEnabled") val isTwoFactorEnabled: Boolean, - @Deprecated("Use accountKeys instead", ReplaceWith("accountKeys")) + @Deprecated( + message = "Use `accountKeys` instead", + ReplaceWith("profile.accountKeys?.publicKeyEncryptionKeyPair?.wrappedPrivateKey"), + ) @SerialName("privateKey") val privateKey: String?, @SerialName("accountKeys") - val accountKeys: AccountKeys?, + val accountKeys: AccountKeysJson?, @SerialName("premium") val isPremium: Boolean, @@ -416,77 +419,6 @@ data class SyncResponseJson( @SerialName("managePolicies") val shouldManagePolicies: Boolean, ) - - /** - * Represents private keys in the vault response. - * - * @property signatureKeyPair The signature key pair of the profile. - * @property publicKeyEncryptionKeyPair The public key encryption key pair of the profile. - * @property securityState The security state of the profile (nullable). - */ - @Serializable - data class AccountKeys( - @SerialName("signatureKeyPair") - val signatureKeyPair: SignatureKeyPair?, - - @SerialName("publicKeyEncryptionKeyPair") - val publicKeyEncryptionKeyPair: PublicKeyEncryptionKeyPair, - - @SerialName("securityState") - val securityState: SecurityState?, - ) { - - /** - * Represents a signature key pair in the vault response. - * - * @property wrappedSigningKey The wrapped signing key of the signature key pair. - * @property verifyingKey The verifying key of the signature key pair. - */ - @Serializable - data class SignatureKeyPair( - @SerialName("wrappedSigningKey") - val wrappedSigningKey: String, - - @SerialName("verifyingKey") - val verifyingKey: String, - ) - - /** - * Represents a public key encryption key pair in the vault response. - * - * @property wrappedPrivateKey The wrapped private key of the public key encryption key - * pair. - * @property publicKey The public key of the public key encryption key pair. - * @property signedPublicKey The signed public key of the public key encryption key pair - * (nullable). - */ - @Serializable - data class PublicKeyEncryptionKeyPair( - @SerialName("wrappedPrivateKey") - val wrappedPrivateKey: String, - - @SerialName("publicKey") - val publicKey: String, - - @SerialName("signedPublicKey") - val signedPublicKey: String?, - ) - - /** - * Represents security state in the vault response. - * - * @property securityState The security state of the profile. - * @property securityVersion The security version of the profile. - */ - @Serializable - data class SecurityState( - @SerialName("securityState") - val securityState: String, - - @SerialName("securityVersion") - val securityVersion: Int, - ) - } } /** diff --git a/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt b/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt index b619bddc60..e21988cc74 100644 --- a/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt +++ b/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt @@ -21,6 +21,7 @@ import com.bitwarden.network.model.TwoFactorAuthMethod import com.bitwarden.network.model.UserDecryptionOptionsJson import com.bitwarden.network.model.VerifyEmailTokenRequestJson import com.bitwarden.network.model.VerifyEmailTokenResponseJson +import com.bitwarden.network.model.createMockAccountKeysJson import com.bitwarden.network.util.DeviceModelProvider import io.mockk.every import io.mockk.mockk @@ -539,6 +540,23 @@ private const val LOGIN_SUCCESS_JSON = """ "token_type": "Bearer", "refresh_token": "refreshToken", "PrivateKey": "privateKey", + "AccountKeys": { + "signatureKeyPair": { + "wrappedSigningKey": "mockWrappedSigningKey-1", + "verifyingKey": "mockVerifyingKey-1" + }, + "publicKeyEncryptionKeyPair": { + "wrappedPrivateKey": "mockWrappedPrivateKey-1", + "publicKey": "mockPublicKey-1", + "signedPublicKey": "mockSignedPublicKey-1", + "object": "publicKeyEncryptionKeyPair" + }, + "securityState": { + "securityState": "mockSecurityState-1", + "securityVersion": 1 + }, + "object": "privateKeys" + }, "Key": "key", "MasterPasswordPolicy": { "MinComplexity": 10, @@ -583,6 +601,7 @@ private val LOGIN_SUCCESS = GetTokenResponseJson.Success( kdfMemory = 16, kdfParallelism = 4, privateKey = "privateKey", + accountKeys = createMockAccountKeysJson(number = 1), shouldForcePasswordReset = true, shouldResetMasterPassword = true, twoFactorToken = null, diff --git a/network/src/testFixtures/kotlin/com/bitwarden/network/model/AccountKeysJsonUtil.kt b/network/src/testFixtures/kotlin/com/bitwarden/network/model/AccountKeysJsonUtil.kt new file mode 100644 index 0000000000..11b9c23762 --- /dev/null +++ b/network/src/testFixtures/kotlin/com/bitwarden/network/model/AccountKeysJsonUtil.kt @@ -0,0 +1,55 @@ +package com.bitwarden.network.model + +/** + * Create a mock set of private keys with a given [number]. + */ +fun createMockAccountKeysJson( + number: Int, +): AccountKeysJson = + AccountKeysJson( + signatureKeyPair = createMockSignatureKeyPair(number = number), + publicKeyEncryptionKeyPair = createMockPublicKeyEncryptionKeyPair(number = number), + securityState = createMockSecurityState(number = number), + ) + +/** + * Create a mock [AccountKeysJson.SecurityState] with a given [number]. + */ +fun createMockSecurityState( + number: Int, + securityState: String = "mockSecurityState-$number", + securityVersion: Int = number, +): AccountKeysJson.SecurityState = + AccountKeysJson.SecurityState( + securityState = securityState, + securityVersion = securityVersion, + ) + +/** + * Create a mock [AccountKeysJson.PublicKeyEncryptionKeyPair] with a given + * number. + */ +fun createMockPublicKeyEncryptionKeyPair( + number: Int, + publicKey: String = "mockPublicKey-$number", + wrappedPrivateKey: String = "mockWrappedPrivateKey-$number", + signedPublicKey: String? = "mockSignedPublicKey-$number", +): AccountKeysJson.PublicKeyEncryptionKeyPair = + AccountKeysJson.PublicKeyEncryptionKeyPair( + publicKey = publicKey, + wrappedPrivateKey = wrappedPrivateKey, + signedPublicKey = signedPublicKey, + ) + +/** + * Create a mock [AccountKeysJson.SignatureKeyPair] with a given number. + */ +fun createMockSignatureKeyPair( + number: Int, + wrappedSigningKey: String = "mockWrappedSigningKey-$number", + verifyingKey: String = "mockVerifyingKey-$number", +): AccountKeysJson.SignatureKeyPair = + AccountKeysJson.SignatureKeyPair( + wrappedSigningKey = wrappedSigningKey, + verifyingKey = verifyingKey, + ) diff --git a/network/src/testFixtures/kotlin/com/bitwarden/network/model/SyncResponseProfileUtil.kt b/network/src/testFixtures/kotlin/com/bitwarden/network/model/SyncResponseProfileUtil.kt index 80bc753c2f..dcb7fc75bb 100644 --- a/network/src/testFixtures/kotlin/com/bitwarden/network/model/SyncResponseProfileUtil.kt +++ b/network/src/testFixtures/kotlin/com/bitwarden/network/model/SyncResponseProfileUtil.kt @@ -18,7 +18,7 @@ fun createMockProfile( isEmailVerified: Boolean = false, isTwoFactorEnabled: Boolean = false, privateKey: String? = "mockPrivateKey-$number", - accountKeys: SyncResponseJson.Profile.AccountKeys? = createMockPrivateKeys(number = number), + accountKeys: AccountKeysJson? = createMockAccountKeysJson(number = number), isPremium: Boolean = false, culture: String? = "mockCulture-$number", name: String? = "mockName-$number", @@ -59,60 +59,6 @@ fun createMockProfile( creationDate = creationDate, ) -/** - * Create a mock set of private keys with a given [number]. - */ -fun createMockPrivateKeys( - number: Int, -): SyncResponseJson.Profile.AccountKeys = - SyncResponseJson.Profile.AccountKeys( - signatureKeyPair = createMockSignatureKeyPair(number = number), - publicKeyEncryptionKeyPair = createMockPublicKeyEncryptionKeyPair(number = number), - securityState = createMockSecurityState(number = number), - ) - -/** - * Create a mock [SyncResponseJson.Profile.AccountKeys.SecurityState] with a given [number]. - */ -fun createMockSecurityState( - number: Int, - securityState: String = "mockSecurityState-$number", - securityVersion: Int = number, -): SyncResponseJson.Profile.AccountKeys.SecurityState = - SyncResponseJson.Profile.AccountKeys.SecurityState( - securityState = securityState, - securityVersion = securityVersion, - ) - -/** - * Create a mock [SyncResponseJson.Profile.AccountKeys.PublicKeyEncryptionKeyPair] with a given - * number. - */ -fun createMockPublicKeyEncryptionKeyPair( - number: Int, - publicKey: String = "mockPublicKey-$number", - wrappedPrivateKey: String = "mockWrappedPrivateKey-$number", - signedPublicKey: String? = "mockSignedPublicKey-$number", -): SyncResponseJson.Profile.AccountKeys.PublicKeyEncryptionKeyPair = - SyncResponseJson.Profile.AccountKeys.PublicKeyEncryptionKeyPair( - publicKey = publicKey, - wrappedPrivateKey = wrappedPrivateKey, - signedPublicKey = signedPublicKey, - ) - -/** - * Create a mock [SyncResponseJson.Profile.AccountKeys.SignatureKeyPair] with a given number. - */ -fun createMockSignatureKeyPair( - number: Int, - wrappedSigningKey: String = "mockWrappedSigningKey-$number", - verifyingKey: String = "mockVerifyingKey-$number", -): SyncResponseJson.Profile.AccountKeys.SignatureKeyPair = - SyncResponseJson.Profile.AccountKeys.SignatureKeyPair( - wrappedSigningKey = wrappedSigningKey, - verifyingKey = verifyingKey, - ) - /** * Create a mock [SyncResponseJson.Profile.Organization] with a given [number]. */