MCPcopy
hub / github.com/remotely-save/remotely-save / encryptEntity

Method encryptEntity

src/fsEncrypt.ts:412–445  ·  view source on GitHub ↗
(input: Entity)

Source from the content-addressed store, hash-verified

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");

Callers 1

ensembleMixedEntiesFunction · 0.80

Calls 4

isPasswordEmptyMethod · 0.95
_getSizeFromOrigToEncMethod · 0.95
_encryptNameMethod · 0.95

Tested by

no test coverage detected