From c5d72ad7cb264bc725cd687739e93fa3831d2c47 Mon Sep 17 00:00:00 2001 From: mp-bw <59324545+mp-bw@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:44:45 -0500 Subject: [PATCH] State migration storage key refinement (#2379) --- src/Core/Constants.cs | 46 +-- src/Core/Services/StateMigrationService.cs | 96 +++-- src/Core/Services/StateService.cs | 430 ++++++++------------- 3 files changed, 259 insertions(+), 313 deletions(-) diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index f41b2b7c2..7357ffbfb 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -7,29 +7,29 @@ public const string AndroidAppProtocol = "androidapp://"; public const string iOSAppProtocol = "iosapp://"; public const string DefaultUsernameGenerated = "-"; - public static string StateVersionKey = "stateVersion"; - public static string StateKey = "state"; - public static string PreAuthEnvironmentUrlsKey = "preAuthEnvironmentUrls"; - public static string LastFileCacheClearKey = "lastFileCacheClear"; - public static string AutofillTileAdded = "autofillTileAdded"; - public static string PushRegisteredTokenKey = "pushRegisteredToken"; - public static string PushInitialPromptShownKey = "pushInitialPromptShown"; - public static string PushInstallationRegistrationErrorKey = "pushInstallationRegistrationError"; - public static string LastBuildKey = "lastBuild"; - public static string AddSitePromptShownKey = "addSitePromptShown"; - public static string ClearCiphersCacheKey = "clearCiphersCache"; - public static string BiometricIntegrityKey = "biometricIntegrityState"; - public static string iOSAutoFillClearCiphersCacheKey = "iOSAutoFillClearCiphersCache"; - public static string iOSAutoFillBiometricIntegrityKey = "iOSAutoFillBiometricIntegrityState"; - public static string iOSExtensionClearCiphersCacheKey = "iOSExtensionClearCiphersCache"; - public static string iOSExtensionBiometricIntegrityKey = "iOSExtensionBiometricIntegrityState"; - public static string iOSShareExtensionClearCiphersCacheKey = "iOSShareExtensionClearCiphersCache"; - public static string iOSShareExtensionBiometricIntegrityKey = "iOSShareExtensionBiometricIntegrityState"; - public static string iOSExtensionActiveUserIdKey = "iOSExtensionActiveUserId"; - public static string EventCollectionKey = "eventCollection"; - public static string RememberedEmailKey = "rememberedEmail"; - public static string RememberedOrgIdentifierKey = "rememberedOrgIdentifier"; - public static string PasswordlessLoginNotificationKey = "passwordlessLoginNotificationKey"; + public const string StateVersionKey = "stateVersion"; + public const string StateKey = "state"; + public const string PreAuthEnvironmentUrlsKey = "preAuthEnvironmentUrls"; + public const string LastFileCacheClearKey = "lastFileCacheClear"; + public const string AutofillTileAdded = "autofillTileAdded"; + public const string PushRegisteredTokenKey = "pushRegisteredToken"; + public const string PushInitialPromptShownKey = "pushInitialPromptShown"; + public const string PushInstallationRegistrationErrorKey = "pushInstallationRegistrationError"; + public const string LastBuildKey = "lastBuild"; + public const string AddSitePromptShownKey = "addSitePromptShown"; + public const string ClearCiphersCacheKey = "clearCiphersCache"; + public const string BiometricIntegrityKey = "biometricIntegrityState"; + public const string iOSAutoFillClearCiphersCacheKey = "iOSAutoFillClearCiphersCache"; + public const string iOSAutoFillBiometricIntegrityKey = "iOSAutoFillBiometricIntegrityState"; + public const string iOSExtensionClearCiphersCacheKey = "iOSExtensionClearCiphersCache"; + public const string iOSExtensionBiometricIntegrityKey = "iOSExtensionBiometricIntegrityState"; + public const string iOSShareExtensionClearCiphersCacheKey = "iOSShareExtensionClearCiphersCache"; + public const string iOSShareExtensionBiometricIntegrityKey = "iOSShareExtensionBiometricIntegrityState"; + public const string iOSExtensionActiveUserIdKey = "iOSExtensionActiveUserId"; + public const string EventCollectionKey = "eventCollection"; + public const string RememberedEmailKey = "rememberedEmail"; + public const string RememberedOrgIdentifierKey = "rememberedOrgIdentifier"; + public const string PasswordlessLoginNotificationKey = "passwordlessLoginNotificationKey"; public const string ThemeKey = "theme"; public const string AutoDarkThemeKey = "autoDarkTheme"; public const string DisableFaviconKey = "disableFavicon"; diff --git a/src/Core/Services/StateMigrationService.cs b/src/Core/Services/StateMigrationService.cs index 31bc62c40..29f0a2ea1 100644 --- a/src/Core/Services/StateMigrationService.cs +++ b/src/Core/Services/StateMigrationService.cs @@ -62,12 +62,11 @@ namespace Bit.Core.Services } } - // v1 to v2 Migration + #region v1 to v2 Migration private class V1Keys { internal const string EnvironmentUrlsKey = "environmentUrls"; - } private async Task MigrateFrom1To2Async() @@ -87,7 +86,9 @@ namespace Bit.Core.Services await RemoveValueAsync(Storage.LiteDb, V1Keys.EnvironmentUrlsKey); } - // v2 to v3 Migration + #endregion + + #region v2 to v3 Migration private class V2Keys { @@ -203,72 +204,72 @@ namespace Bit.Core.Services // migrate user-specific non-state data var syncOnRefresh = await GetValueAsync(Storage.LiteDb, V2Keys.SyncOnRefreshKey); - await SetValueAsync(Storage.LiteDb, Constants.SyncOnRefreshKey(userId), syncOnRefresh); + await SetValueAsync(Storage.LiteDb, V3Keys.SyncOnRefreshKey(userId), syncOnRefresh); var lastActiveTime = await GetValueAsync(Storage.Prefs, V2Keys.LastActiveTimeKey); - await SetValueAsync(Storage.LiteDb, Constants.LastActiveTimeKey(userId), lastActiveTime); + await SetValueAsync(Storage.LiteDb, V3Keys.LastActiveTimeKey(userId), lastActiveTime); var biometricUnlock = await GetValueAsync(Storage.LiteDb, V2Keys.BiometricUnlockKey); - await SetValueAsync(Storage.LiteDb, Constants.BiometricUnlockKey(userId), biometricUnlock); + await SetValueAsync(Storage.LiteDb, V3Keys.BiometricUnlockKey(userId), biometricUnlock); var protectedPin = await GetValueAsync(Storage.LiteDb, V2Keys.ProtectedPin); - await SetValueAsync(Storage.LiteDb, Constants.ProtectedPinKey(userId), protectedPin); + await SetValueAsync(Storage.LiteDb, V3Keys.ProtectedPinKey(userId), protectedPin); var pinProtectedKey = await GetValueAsync(Storage.LiteDb, V2Keys.PinProtectedKey); - await SetValueAsync(Storage.LiteDb, Constants.PinProtectedKey(userId), pinProtectedKey); + await SetValueAsync(Storage.LiteDb, V3Keys.PinProtectedKey(userId), pinProtectedKey); var defaultUriMatch = await GetValueAsync(Storage.Prefs, V2Keys.DefaultUriMatch); - await SetValueAsync(Storage.LiteDb, Constants.DefaultUriMatchKey(userId), defaultUriMatch); + await SetValueAsync(Storage.LiteDb, V3Keys.DefaultUriMatchKey(userId), defaultUriMatch); var disableAutoTotpCopy = await GetValueAsync(Storage.Prefs, V2Keys.DisableAutoTotpCopyKey); - await SetValueAsync(Storage.LiteDb, Constants.DisableAutoTotpCopyKey(userId), disableAutoTotpCopy); + await SetValueAsync(Storage.LiteDb, V3Keys.DisableAutoTotpCopyKey(userId), disableAutoTotpCopy); var autofillDisableSavePrompt = await GetValueAsync(Storage.Prefs, V2Keys.AutofillDisableSavePromptKey); - await SetValueAsync(Storage.LiteDb, Constants.AutofillDisableSavePromptKey(userId), + await SetValueAsync(Storage.LiteDb, V3Keys.AutofillDisableSavePromptKey(userId), autofillDisableSavePrompt); var autofillBlacklistedUris = await GetValueAsync>(Storage.LiteDb, V2Keys.AutofillBlacklistedUrisKey); - await SetValueAsync(Storage.LiteDb, Constants.AutofillBlacklistedUrisKey(userId), autofillBlacklistedUris); + await SetValueAsync(Storage.LiteDb, V3Keys.AutofillBlacklistedUrisKey(userId), autofillBlacklistedUris); var disableFavicon = await GetValueAsync(Storage.Prefs, V2Keys.DisableFaviconKey); await SetValueAsync(Storage.LiteDb, V3Keys.DisableFaviconKey(userId), disableFavicon); var theme = await GetValueAsync(Storage.Prefs, V2Keys.ThemeKey); await SetValueAsync(Storage.LiteDb, V3Keys.ThemeKey(userId), theme); var clearClipboard = await GetValueAsync(Storage.Prefs, V2Keys.ClearClipboardKey); - await SetValueAsync(Storage.LiteDb, Constants.ClearClipboardKey(userId), clearClipboard); + await SetValueAsync(Storage.LiteDb, V3Keys.ClearClipboardKey(userId), clearClipboard); var previousPage = await GetValueAsync(Storage.LiteDb, V2Keys.PreviousPageKey); - await SetValueAsync(Storage.LiteDb, Constants.PreviousPageKey(userId), previousPage); + await SetValueAsync(Storage.LiteDb, V3Keys.PreviousPageKey(userId), previousPage); var inlineAutofillEnabled = await GetValueAsync(Storage.Prefs, V2Keys.InlineAutofillEnabledKey); - await SetValueAsync(Storage.LiteDb, Constants.InlineAutofillEnabledKey(userId), inlineAutofillEnabled); + await SetValueAsync(Storage.LiteDb, V3Keys.InlineAutofillEnabledKey(userId), inlineAutofillEnabled); var invalidUnlockAttempts = await GetValueAsync(Storage.Prefs, V2Keys.InvalidUnlockAttempts); - await SetValueAsync(Storage.LiteDb, Constants.InvalidUnlockAttemptsKey(userId), invalidUnlockAttempts); + await SetValueAsync(Storage.LiteDb, V3Keys.InvalidUnlockAttemptsKey(userId), invalidUnlockAttempts); var passwordRepromptAutofill = await GetValueAsync(Storage.LiteDb, V2Keys.PasswordRepromptAutofillKey); - await SetValueAsync(Storage.LiteDb, Constants.PasswordRepromptAutofillKey(userId), + await SetValueAsync(Storage.LiteDb, V3Keys.PasswordRepromptAutofillKey(userId), passwordRepromptAutofill); var passwordVerifiedAutofill = await GetValueAsync(Storage.LiteDb, V2Keys.PasswordVerifiedAutofillKey); - await SetValueAsync(Storage.LiteDb, Constants.PasswordVerifiedAutofillKey(userId), + await SetValueAsync(Storage.LiteDb, V3Keys.PasswordVerifiedAutofillKey(userId), passwordVerifiedAutofill); var cipherLocalData = await GetValueAsync>>(Storage.LiteDb, V2Keys.Keys_LocalData); - await SetValueAsync(Storage.LiteDb, Constants.LocalDataKey(userId), cipherLocalData); + await SetValueAsync(Storage.LiteDb, V3Keys.LocalDataKey(userId), cipherLocalData); var neverDomains = await GetValueAsync>(Storage.LiteDb, V2Keys.Keys_NeverDomains); - await SetValueAsync(Storage.LiteDb, Constants.NeverDomainsKey(userId), neverDomains); + await SetValueAsync(Storage.LiteDb, V3Keys.NeverDomainsKey(userId), neverDomains); var key = await GetValueAsync(Storage.Secure, V2Keys.Keys_Key); - await SetValueAsync(Storage.Secure, Constants.KeyKey(userId), key); + await SetValueAsync(Storage.Secure, V3Keys.KeyKey(userId), key); var encOrgKeys = await GetValueAsync>(Storage.LiteDb, V2Keys.Keys_EncOrgKeys); - await SetValueAsync(Storage.LiteDb, Constants.EncOrgKeysKey(userId), encOrgKeys); + await SetValueAsync(Storage.LiteDb, V3Keys.EncOrgKeysKey(userId), encOrgKeys); var encPrivateKey = await GetValueAsync(Storage.LiteDb, V2Keys.Keys_EncPrivateKey); - await SetValueAsync(Storage.LiteDb, Constants.EncPrivateKeyKey(userId), encPrivateKey); + await SetValueAsync(Storage.LiteDb, V3Keys.EncPrivateKeyKey(userId), encPrivateKey); var encKey = await GetValueAsync(Storage.LiteDb, V2Keys.Keys_EncKey); - await SetValueAsync(Storage.LiteDb, Constants.EncKeyKey(userId), encKey); + await SetValueAsync(Storage.LiteDb, V3Keys.EncKeyKey(userId), encKey); var keyHash = await GetValueAsync(Storage.LiteDb, V2Keys.Keys_KeyHash); - await SetValueAsync(Storage.LiteDb, Constants.KeyHashKey(userId), keyHash); + await SetValueAsync(Storage.LiteDb, V3Keys.KeyHashKey(userId), keyHash); var usesKeyConnector = await GetValueAsync(Storage.LiteDb, V2Keys.Keys_UsesKeyConnector); - await SetValueAsync(Storage.LiteDb, Constants.UsesKeyConnectorKey(userId), usesKeyConnector); + await SetValueAsync(Storage.LiteDb, V3Keys.UsesKeyConnectorKey(userId), usesKeyConnector); var passGenOptions = await GetValueAsync(Storage.LiteDb, V2Keys.Keys_PassGenOptions); - await SetValueAsync(Storage.LiteDb, Constants.PassGenOptionsKey(userId), passGenOptions); + await SetValueAsync(Storage.LiteDb, V3Keys.PassGenOptionsKey(userId), passGenOptions); var passGenHistory = await GetValueAsync>(Storage.LiteDb, V2Keys.Keys_PassGenHistory); - await SetValueAsync(Storage.LiteDb, Constants.PassGenHistoryKey(userId), passGenHistory); + await SetValueAsync(Storage.LiteDb, V3Keys.PassGenHistoryKey(userId), passGenHistory); // migrate global non-state data - await SetValueAsync(Storage.Prefs, Constants.PreAuthEnvironmentUrlsKey, environmentUrls); + await SetValueAsync(Storage.Prefs, V3Keys.PreAuthEnvironmentUrlsKey, environmentUrls); // Update stored version await SetLastStateVersionAsync(3); @@ -318,10 +319,43 @@ namespace Bit.Core.Services await RemoveValueAsync(Storage.LiteDb, V2Keys.Keys_PassGenHistory); } - // v3 to v4 Migration + #endregion + + #region v3 to v4 Migration private class V3Keys { + internal const string PreAuthEnvironmentUrlsKey = "preAuthEnvironmentUrls"; + internal static string LocalDataKey(string userId) => $"ciphersLocalData_{userId}"; + internal static string NeverDomainsKey(string userId) => $"neverDomains_{userId}"; + internal static string KeyKey(string userId) => $"key_{userId}"; + internal static string EncOrgKeysKey(string userId) => $"encOrgKeys_{userId}"; + internal static string EncPrivateKeyKey(string userId) => $"encPrivateKey_{userId}"; + internal static string EncKeyKey(string userId) => $"encKey_{userId}"; + internal static string KeyHashKey(string userId) => $"keyHash_{userId}"; + internal static string PinProtectedKey(string userId) => $"pinProtectedKey_{userId}"; + internal static string PassGenOptionsKey(string userId) => $"passwordGenerationOptions_{userId}"; + internal static string PassGenHistoryKey(string userId) => $"generatedPasswordHistory_{userId}"; + internal static string LastActiveTimeKey(string userId) => $"lastActiveTime_{userId}"; + internal static string InvalidUnlockAttemptsKey(string userId) => $"invalidUnlockAttempts_{userId}"; + internal static string InlineAutofillEnabledKey(string userId) => $"inlineAutofillEnabled_{userId}"; + internal static string AutofillDisableSavePromptKey(string userId) => $"autofillDisableSavePrompt_{userId}"; + internal static string AutofillBlacklistedUrisKey(string userId) => $"autofillBlacklistedUris_{userId}"; + internal static string ClearClipboardKey(string userId) => $"clearClipboard_{userId}"; + internal static string SyncOnRefreshKey(string userId) => $"syncOnRefresh_{userId}"; + internal static string DefaultUriMatchKey(string userId) => $"defaultUriMatch_{userId}"; + internal static string DisableAutoTotpCopyKey(string userId) => $"disableAutoTotpCopy_{userId}"; + internal static string PreviousPageKey(string userId) => $"previousPage_{userId}"; + + internal static string PasswordRepromptAutofillKey(string userId) => + $"passwordRepromptAutofillKey_{userId}"; + + internal static string PasswordVerifiedAutofillKey(string userId) => + $"passwordVerifiedAutofillKey_{userId}"; + + internal static string UsesKeyConnectorKey(string userId) => $"usesKeyConnector_{userId}"; + internal static string ProtectedPinKey(string userId) => $"protectedPin_{userId}"; + internal static string BiometricUnlockKey(string userId) => $"biometricUnlock_{userId}"; internal static string ThemeKey(string userId) => $"theme_{userId}"; internal static string AutoDarkThemeKey(string userId) => $"autoDarkTheme_{userId}"; internal static string DisableFaviconKey(string userId) => $"disableFavicon_{userId}"; @@ -398,6 +432,8 @@ namespace Bit.Core.Services internal const string DisableFaviconKey = "disableFavicon"; } + #endregion + // Helpers private async Task GetLastStateVersionAsync() diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index 75a903cc9..238d79b06 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -240,16 +240,15 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.BiometricUnlockKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.BiometricUnlockKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetBiometricUnlockAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.BiometricUnlockKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.BiometricUnlockKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetBiometricLockedAsync(string userId = null) @@ -309,32 +308,28 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ProtectedPinKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.ProtectedPinKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetProtectedPinAsync(string value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ProtectedPinKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.ProtectedPinKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPinProtectedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PinProtectedKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.PinProtectedKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetPinProtectedAsync(string value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PinProtectedKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PinProtectedKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPinProtectedKeyAsync(string userId = null) @@ -369,16 +364,14 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultSecureStorageOptionsAsync()); - var key = Constants.KeyKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.KeyKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetKeyEncryptedAsync(string value, string userId) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultSecureStorageOptionsAsync()); - var key = Constants.KeyKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.KeyKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetKeyDecryptedAsync(string userId = null) @@ -401,94 +394,83 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.KeyHashKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.KeyHashKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetKeyHashAsync(string value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.KeyHashKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.KeyHashKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetEncKeyEncryptedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncKeyKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.EncKeyKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetEncKeyEncryptedAsync(string value, string userId) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncKeyKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.EncKeyKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetOrgKeysEncryptedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncOrgKeysKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.EncOrgKeysKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetOrgKeysEncryptedAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncOrgKeysKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.EncOrgKeysKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPrivateKeyEncryptedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncPrivateKeyKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.EncPrivateKeyKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetPrivateKeyEncryptedAsync(string value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.EncPrivateKeyKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.EncPrivateKeyKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetAutofillBlacklistedUrisAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AutofillBlacklistedUrisKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.AutofillBlacklistedUrisKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetAutofillBlacklistedUrisAsync(List value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AutofillBlacklistedUrisKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.AutofillBlacklistedUrisKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task GetAutofillTileAddedAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.AutofillTileAdded; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.AutofillTileAdded, await GetDefaultStorageOptionsAsync()); } public async Task SetAutofillTileAddedAsync(bool? value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.AutofillTileAdded; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.AutofillTileAdded, value, await GetDefaultStorageOptionsAsync()); } public async Task GetEmailAsync(string userId = null) @@ -525,330 +507,300 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LastActiveTimeKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.LastActiveTimeKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetLastActiveTimeAsync(long? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LastActiveTimeKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.LastActiveTimeKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetVaultTimeoutAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.VaultTimeoutKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? Constants.VaultTimeoutDefault; + return await GetValueAsync(Constants.VaultTimeoutKey(reconciledOptions.UserId), reconciledOptions) ?? + Constants.VaultTimeoutDefault; } public async Task SetVaultTimeoutAsync(int? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.VaultTimeoutKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.VaultTimeoutKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetVaultTimeoutActionAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.VaultTimeoutActionKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? VaultTimeoutAction.Lock; + return await GetValueAsync(Constants.VaultTimeoutActionKey(reconciledOptions.UserId), + reconciledOptions) ?? VaultTimeoutAction.Lock; } public async Task SetVaultTimeoutActionAsync(VaultTimeoutAction? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.VaultTimeoutActionKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.VaultTimeoutActionKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetScreenCaptureAllowedAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ScreenCaptureAllowedKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? CoreHelpers.InDebugMode(); + return await GetValueAsync(Constants.ScreenCaptureAllowedKey(reconciledOptions.UserId), + reconciledOptions) ?? CoreHelpers.InDebugMode(); } public async Task SetScreenCaptureAllowedAsync(bool value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ScreenCaptureAllowedKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.ScreenCaptureAllowedKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetLastFileCacheClearAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastFileCacheClearKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.LastFileCacheClearKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetLastFileCacheClearAsync(DateTime? value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastFileCacheClearKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.LastFileCacheClearKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetPreviousPageInfoAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PreviousPageKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.PreviousPageKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetPreviousPageInfoAsync(PreviousPageInfo value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PreviousPageKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PreviousPageKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetInvalidUnlockAttemptsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.InvalidUnlockAttemptsKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.InvalidUnlockAttemptsKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetInvalidUnlockAttemptsAsync(int? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.InvalidUnlockAttemptsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.InvalidUnlockAttemptsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetLastBuildAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastBuildKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.LastBuildKey, await GetDefaultStorageOptionsAsync()); } public async Task SetLastBuildAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastBuildKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.LastBuildKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetDisableFaviconAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.DisableFaviconKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.DisableFaviconKey, await GetDefaultStorageOptionsAsync()); } public async Task SetDisableFaviconAsync(bool? value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.DisableFaviconKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.DisableFaviconKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetDisableAutoTotpCopyAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.DisableAutoTotpCopyKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.DisableAutoTotpCopyKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetDisableAutoTotpCopyAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.DisableAutoTotpCopyKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.DisableAutoTotpCopyKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetInlineAutofillEnabledAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.InlineAutofillEnabledKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.InlineAutofillEnabledKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetInlineAutofillEnabledAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.InlineAutofillEnabledKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.InlineAutofillEnabledKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetAutofillDisableSavePromptAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AutofillDisableSavePromptKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.AutofillDisableSavePromptKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetAutofillDisableSavePromptAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AutofillDisableSavePromptKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.AutofillDisableSavePromptKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task>> GetLocalDataAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LocalDataKey(reconciledOptions.UserId); - return await GetValueAsync>>(key, reconciledOptions); + return await GetValueAsync>>( + Constants.LocalDataKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetLocalDataAsync(Dictionary> value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LocalDataKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.LocalDataKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEncryptedCiphersAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.CiphersKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.CiphersKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetEncryptedCiphersAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.CiphersKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.CiphersKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetDefaultUriMatchAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.DefaultUriMatchKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.DefaultUriMatchKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetDefaultUriMatchAsync(int? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.DefaultUriMatchKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.DefaultUriMatchKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetNeverDomainsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.NeverDomainsKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.NeverDomainsKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetNeverDomainsAsync(HashSet value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.NeverDomainsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.NeverDomainsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetClearClipboardAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ClearClipboardKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.ClearClipboardKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetClearClipboardAsync(int? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ClearClipboardKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.ClearClipboardKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEncryptedCollectionsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.CollectionsKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>( + Constants.CollectionsKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetEncryptedCollectionsAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.CollectionsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.CollectionsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPasswordRepromptAutofillAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PasswordRepromptAutofillKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.PasswordRepromptAutofillKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetPasswordRepromptAutofillAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PasswordRepromptAutofillKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PasswordRepromptAutofillKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task GetPasswordVerifiedAutofillAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PasswordVerifiedAutofillKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.PasswordVerifiedAutofillKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetPasswordVerifiedAutofillAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PasswordVerifiedAutofillKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PasswordVerifiedAutofillKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task GetLastSyncAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LastSyncKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.LastSyncKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetLastSyncAsync(DateTime? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.LastSyncKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.LastSyncKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetSecurityStampAsync(string userId = null) @@ -887,276 +839,243 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SyncOnRefreshKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.SyncOnRefreshKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetSyncOnRefreshAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SyncOnRefreshKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.SyncOnRefreshKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetRememberedEmailAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.RememberedEmailKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.RememberedEmailKey, await GetDefaultStorageOptionsAsync()); } public async Task SetRememberedEmailAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.RememberedEmailKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.RememberedEmailKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetRememberedOrgIdentifierAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.RememberedOrgIdentifierKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.RememberedOrgIdentifierKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetRememberedOrgIdentifierAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.RememberedOrgIdentifierKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.RememberedOrgIdentifierKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetThemeAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.ThemeKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.ThemeKey, await GetDefaultStorageOptionsAsync()); } public async Task SetThemeAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.ThemeKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.ThemeKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetAutoDarkThemeAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.AutoDarkThemeKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.AutoDarkThemeKey, await GetDefaultStorageOptionsAsync()); } public async Task SetAutoDarkThemeAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.AutoDarkThemeKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.AutoDarkThemeKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetAddSitePromptShownAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AddSitePromptShownKey; - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.AddSitePromptShownKey, reconciledOptions); } public async Task SetAddSitePromptShownAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.AddSitePromptShownKey; - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.AddSitePromptShownKey, value, reconciledOptions); } public async Task GetPushInitialPromptShownAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushInitialPromptShownKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.PushInitialPromptShownKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetPushInitialPromptShownAsync(bool? value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushInitialPromptShownKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.PushInitialPromptShownKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetPushLastRegistrationDateAsync(string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PushLastRegistrationDateKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + return await GetValueAsync(Constants.PushLastRegistrationDateKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetPushLastRegistrationDateAsync(DateTime? value, string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PushLastRegistrationDateKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + await SetValueAsync(Constants.PushLastRegistrationDateKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task GetPushInstallationRegistrationErrorAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushInstallationRegistrationErrorKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.PushInstallationRegistrationErrorKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetPushInstallationRegistrationErrorAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushInstallationRegistrationErrorKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.PushInstallationRegistrationErrorKey, value, + await GetDefaultStorageOptionsAsync()); } public async Task GetPushCurrentTokenAsync(string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PushCurrentTokenKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + return await GetValueAsync(Constants.PushCurrentTokenKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetPushCurrentTokenAsync(string value, string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PushCurrentTokenKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + await SetValueAsync(Constants.PushCurrentTokenKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEventCollectionAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.EventCollectionKey; - return await GetValueAsync>(key, options); + return await GetValueAsync>(Constants.EventCollectionKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetEventCollectionAsync(List value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.EventCollectionKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.EventCollectionKey, value, await GetDefaultStorageOptionsAsync()); } public async Task> GetEncryptedFoldersAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.FoldersKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.FoldersKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetEncryptedFoldersAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.FoldersKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.FoldersKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEncryptedPoliciesAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PoliciesKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.PoliciesKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetEncryptedPoliciesAsync(Dictionary value, string userId) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PoliciesKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PoliciesKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPushRegisteredTokenAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushRegisteredTokenKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.PushRegisteredTokenKey, await GetDefaultStorageOptionsAsync()); } public async Task SetPushRegisteredTokenAsync(string value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PushRegisteredTokenKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.PushRegisteredTokenKey, value, await GetDefaultStorageOptionsAsync()); } public async Task GetUsesKeyConnectorAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.UsesKeyConnectorKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.UsesKeyConnectorKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetUsesKeyConnectorAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.UsesKeyConnectorKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.UsesKeyConnectorKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetOrganizationsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.OrganizationsKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>( + Constants.OrganizationsKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetOrganizationsAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.OrganizationsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.OrganizationsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetPasswordGenerationOptionsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PassGenOptionsKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.PassGenOptionsKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetPasswordGenerationOptionsAsync(PasswordGenerationOptions value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PassGenOptionsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PassGenOptionsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetUsernameGenerationOptionsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.UsernameGenOptionsKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync( + Constants.UsernameGenOptionsKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetUsernameGenerationOptionsAsync(UsernameGenerationOptions value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.UsernameGenOptionsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.UsernameGenOptionsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEncryptedPasswordGenerationHistory(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PassGenHistoryKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>( + Constants.PassGenHistoryKey(reconciledOptions.UserId), reconciledOptions); } public async Task SetEncryptedPasswordGenerationHistoryAsync(List value, @@ -1164,40 +1083,37 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.PassGenHistoryKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.PassGenHistoryKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetEncryptedSendsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SendsKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.SendsKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetEncryptedSendsAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SendsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.SendsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task> GetSettingsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SettingsKey(reconciledOptions.UserId); - return await GetValueAsync>(key, reconciledOptions); + return await GetValueAsync>(Constants.SettingsKey(reconciledOptions.UserId), + reconciledOptions); } public async Task SetSettingsAsync(Dictionary value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.SettingsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.SettingsKey(reconciledOptions.UserId), value, reconciledOptions); } public async Task GetAccessTokenAsync(string userId = null) @@ -1238,46 +1154,42 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { Email = email }, await GetDefaultStorageOptionsAsync()); - var key = Constants.TwoFactorTokenKey(reconciledOptions.Email); - return await GetValueAsync(key, reconciledOptions); + return await GetValueAsync(Constants.TwoFactorTokenKey(reconciledOptions.Email), reconciledOptions); } public async Task SetTwoFactorTokenAsync(string value, string email = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { Email = email }, await GetDefaultStorageOptionsAsync()); - var key = Constants.TwoFactorTokenKey(reconciledOptions.Email); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.TwoFactorTokenKey(reconciledOptions.Email), value, reconciledOptions); } public async Task GetApprovePasswordlessLoginsAsync(string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ApprovePasswordlessLoginsKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.ApprovePasswordlessLoginsKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetApprovePasswordlessLoginsAsync(bool? value, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ApprovePasswordlessLoginsKey(reconciledOptions.UserId); - await SetValueAsync(key, value, reconciledOptions); + await SetValueAsync(Constants.ApprovePasswordlessLoginsKey(reconciledOptions.UserId), value, + reconciledOptions); } public async Task GetPasswordlessLoginNotificationAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PasswordlessLoginNotificationKey; - return await GetValueAsync(key, options); + return await GetValueAsync(Constants.PasswordlessLoginNotificationKey, + await GetDefaultStorageOptionsAsync()); } public async Task SetPasswordlessLoginNotificationAsync(PasswordlessRequestNotification value) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.PasswordlessLoginNotificationKey; - await SetValueAsync(key, value, options); + await SetValueAsync(Constants.PasswordlessLoginNotificationKey, value, + await GetDefaultStorageOptionsAsync()); } public async Task SetAvatarColorAsync(string value, string userId = null) @@ -1618,31 +1530,29 @@ namespace Bit.Core.Services { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ShouldConnectToWatchKey(reconciledOptions.UserId); - return await GetValueAsync(key, reconciledOptions) ?? false; + return await GetValueAsync(Constants.ShouldConnectToWatchKey(reconciledOptions.UserId), + reconciledOptions) ?? false; } public async Task SetShouldConnectToWatchAsync(bool shouldConnect, string userId = null) { var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync()); - var key = Constants.ShouldConnectToWatchKey(reconciledOptions.UserId); - await SetValueAsync(key, shouldConnect, reconciledOptions); + await SetValueAsync(Constants.ShouldConnectToWatchKey(reconciledOptions.UserId), shouldConnect, + reconciledOptions); await SetLastUserShouldConnectToWatchAsync(shouldConnect); } public async Task GetLastUserShouldConnectToWatchAsync() { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastUserShouldConnectToWatchKey; - return await GetValueAsync(key, options) ?? false; + return await GetValueAsync(Constants.LastUserShouldConnectToWatchKey, + await GetDefaultStorageOptionsAsync()) ?? false; } private async Task SetLastUserShouldConnectToWatchAsync(bool? shouldConnect = null) { - var options = await GetDefaultStorageOptionsAsync(); - var key = Constants.LastUserShouldConnectToWatchKey; - await SetValueAsync(key, shouldConnect ?? await GetShouldConnectToWatchAsync(), options); + await SetValueAsync(Constants.LastUserShouldConnectToWatchKey, + shouldConnect ?? await GetShouldConnectToWatchAsync(), await GetDefaultStorageOptionsAsync()); } } }