chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -1,7 +1,6 @@
import {
AnyKeyParamsContent,
compareVersions,
ContentType,
leftVersionGreaterThanOrEqualToRight,
ProtocolVersion,
} from '@standardnotes/common'
@@ -39,6 +38,7 @@ import {
import { ClientDisplayableError } from '@standardnotes/responses'
import { extendArray } from '@standardnotes/utils'
import { EncryptionService } from './EncryptionService'
import { ContentType } from '@standardnotes/domain-core'
export class DecryptBackupFileUseCase {
constructor(private encryption: EncryptionService) {}
@@ -95,7 +95,7 @@ export class DecryptBackupFileUseCase {
} else {
const hasEncryptedItem = payloads.find(isEncryptedPayload)
const hasDecryptedItemsKey = payloads.find(
(payload) => payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload),
(payload) => payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload),
)
if (hasEncryptedItem && hasDecryptedItemsKey) {
@@ -149,7 +149,7 @@ export class DecryptBackupFileUseCase {
const encryptedPayloads: EncryptedPayloadInterface[] = []
payloads.forEach((payload) => {
if (payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload)) {
if (payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload)) {
decryptedItemsKeys.push(payload as DecryptedPayloadInterface<ItemsKeyContent>)
} else if (isEncryptedPayload(payload)) {
encryptedPayloads.push(payload)

View File

@@ -62,7 +62,6 @@ import {
AnyKeyParamsContent,
ApplicationIdentifier,
compareVersions,
ContentType,
isVersionLessThanOrEqualTo,
KeyParamsOrigination,
ProtocolVersion,
@@ -92,6 +91,7 @@ import { RootKeyEncryptPayloadWithKeyLookupUseCase } from './UseCase/RootEncrypt
import { RootKeyEncryptPayloadUseCase } from './UseCase/RootEncryption/EncryptPayload'
import { ValidateAccountPasswordResult } from './RootKey/ValidateAccountPasswordResult'
import { ValidatePasscodeResult } from './RootKey/ValidatePasscodeResult'
import { ContentType } from '@standardnotes/domain-core'
/**
* The encryption service is responsible for the encryption and decryption of payloads, and
@@ -746,7 +746,7 @@ export class EncryptionService
}
public createDecryptedBackupFile(): BackupFile {
const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.ItemsKey)
const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.TYPES.ItemsKey)
const data: BackupFile = {
version: ProtocolVersionLatest,

View File

@@ -1,4 +1,4 @@
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import {
DecryptedParameters,
ErrorDecryptingParameters,
@@ -32,6 +32,7 @@ import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { AbstractService } from '../Service/AbstractService'
import { StorageServiceInterface } from '../Storage/StorageServiceInterface'
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
import { ContentType } from '@standardnotes/domain-core'
export class ItemsEncryptionService extends AbstractService {
private removeItemsObserver!: () => void
@@ -47,7 +48,7 @@ export class ItemsEncryptionService extends AbstractService {
) {
super(internalEventBus)
this.removeItemsObserver = this.itemManager.addObserver([ContentType.ItemsKey], ({ changed, inserted }) => {
this.removeItemsObserver = this.itemManager.addObserver([ContentType.TYPES.ItemsKey], ({ changed, inserted }) => {
if (changed.concat(inserted).length > 0) {
void this.decryptErroredItemPayloads()
}
@@ -84,7 +85,9 @@ export class ItemsEncryptionService extends AbstractService {
payload: EncryptedPayloadInterface,
): ItemsKeyInterface | KeySystemItemsKeyInterface | undefined {
const itemsKeys = this.getItemsKeys()
const keySystemItemsKeys = this.itemManager.getItems<KeySystemItemsKeyInterface>(ContentType.KeySystemItemsKey)
const keySystemItemsKeys = this.itemManager.getItems<KeySystemItemsKeyInterface>(
ContentType.TYPES.KeySystemItemsKey,
)
return [...itemsKeys, ...keySystemItemsKeys].find(
(key) => key.uuid === payload.items_key_id || key.duplicateOf === payload.items_key_id,

View File

@@ -1,10 +1,5 @@
import { OperatorManager } from '@standardnotes/encryption'
import {
ContentType,
ProtocolVersionLastNonrootItemsKey,
ProtocolVersionLatest,
compareVersions,
} from '@standardnotes/common'
import { ProtocolVersionLastNonrootItemsKey, ProtocolVersionLatest, compareVersions } from '@standardnotes/common'
import {
CreateDecryptedItemFromPayload,
DecryptedPayload,
@@ -18,6 +13,7 @@ import { UuidGenerator } from '@standardnotes/utils'
import { MutatorClientInterface } from '../../../Mutator/MutatorClientInterface'
import { ItemManagerInterface } from '../../../Item/ItemManagerInterface'
import { RootKeyManager } from '../../RootKey/RootKeyManager'
import { ContentType } from '@standardnotes/domain-core'
/**
* Creates a new random items key to use for item encryption, and adds it to model management.
@@ -41,7 +37,7 @@ export class CreateNewDefaultItemsKeyUseCase {
/** Create root key based items key */
const payload = new DecryptedPayload<ItemsKeyContent>({
uuid: UuidGenerator.GenerateUuid(),
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContentSpecialized<ItemsKeyContentSpecialized, ItemsKeyContent>({
itemsKey: rootKey.masterKey,
dataAuthenticationKey: rootKey.dataAuthenticationKey,