(input: Entity)
| 410 | } |
| 411 | |
| 412 | async encryptEntity(input: Entity): Promise<Entity> { |
| 413 | if (input.key === undefined) { |
| 414 | // input.key should always have value |
| 415 | throw Error(`input ${input.keyRaw} is abnormal without key`); |
| 416 | } |
| 417 | |
| 418 | if (this.isPasswordEmpty()) { |
| 419 | return copyEntityAndCopyKeyEncSizeEnc(input); |
| 420 | } |
| 421 | |
| 422 | // below is for having password |
| 423 | const local = cloneDeep(input); |
| 424 | if (local.sizeEnc === undefined && local.size !== undefined) { |
| 425 | // it's not filled yet, we fill it |
| 426 | // local.size is possibly undefined if it's "prevSync" Entity |
| 427 | // but local.key should always have value |
| 428 | local.sizeEnc = this._getSizeFromOrigToEnc(local.size); |
| 429 | } |
| 430 | |
| 431 | if (local.keyEnc === undefined || local.keyEnc === "") { |
| 432 | let keyEnc = this.cacheMapOrigToEnc[input.key]; |
| 433 | if (keyEnc !== undefined && keyEnc !== "" && keyEnc !== local.key) { |
| 434 | // we can reuse remote encrypted key if any |
| 435 | local.keyEnc = keyEnc; |
| 436 | } else { |
| 437 | // we assign a new encrypted key because of no remote |
| 438 | keyEnc = await this._encryptName(input.key); |
| 439 | local.keyEnc = keyEnc; |
| 440 | // remember to add back to cache! |
| 441 | this.cacheMapOrigToEnc[input.key] = keyEnc; |
| 442 | } |
| 443 | } |
| 444 | return local; |
| 445 | } |
| 446 | |
| 447 | async _encryptContent(content: ArrayBuffer) { |
| 448 | // console.debug("start encryptContent"); |
no test coverage detected