fix(mobile): workspaces keychain

This commit is contained in:
Mo
2022-06-22 07:15:37 -05:00
parent d833df1b74
commit 112ef2a2c8
3 changed files with 23 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import {
ApplicationIdentifier,
DeviceInterface,
Environment,
LegacyMobileKeychainStructure,
LegacyRawKeychainValue,
NamespacedRootKeyInKeychain,
RawKeychainValue,
@@ -30,6 +31,12 @@ const isLegacyIdentifier = function (identifier: ApplicationIdentifier) {
return identifier && identifier === LEGACY_IDENTIFIER
}
function isLegacyMobileKeychain(
x: LegacyMobileKeychainStructure | RawKeychainValue,
): x is LegacyMobileKeychainStructure {
return x.ak != undefined
}
const showLoadFailForItemIds = (failedItemIds: string[]) => {
let text =
'The following items could not be loaded. This may happen if you are in low-memory conditions, or if the note is very large in size. We recommend breaking up large notes into smaller chunks using the desktop or web app.\n\nItems:\n'
@@ -227,25 +234,23 @@ export class MobileDeviceInterface implements DeviceInterface {
): Promise<NamespacedRootKeyInKeychain | undefined> {
const keychain = await this.getRawKeychainValue()
if (isLegacyIdentifier(identifier)) {
return keychain as unknown as NamespacedRootKeyInKeychain
}
if (!keychain) {
return
}
return keychain[identifier]
const namespacedValue = keychain[identifier]
if (!namespacedValue && isLegacyIdentifier(identifier)) {
return keychain as unknown as NamespacedRootKeyInKeychain
}
return namespacedValue
}
async setNamespacedKeychainValue(
value: NamespacedRootKeyInKeychain,
identifier: ApplicationIdentifier,
): Promise<void> {
if (isLegacyIdentifier(identifier)) {
await Keychain.setKeys(value)
}
let keychain = await this.getRawKeychainValue()
if (!keychain) {
@@ -259,16 +264,17 @@ export class MobileDeviceInterface implements DeviceInterface {
}
async clearNamespacedKeychainValue(identifier: ApplicationIdentifier): Promise<void> {
if (isLegacyIdentifier(identifier)) {
await this.clearRawKeychainValue()
}
const keychain = await this.getRawKeychainValue()
if (!keychain) {
return
}
if (!keychain[identifier] && isLegacyIdentifier(identifier) && isLegacyMobileKeychain(keychain)) {
await this.clearRawKeychainValue()
return
}
delete keychain[identifier]
await Keychain.setKeys(keychain)
}