MCPcopy
hub / github.com/mailvelope/mailvelope / decryptFile

Function decryptFile

src/modules/pgpModel.js:510–540  ·  view source on GitHub ↗
({encryptedFile, unlockKey, uiLogSource})

Source from the content-addressed store, hash-verified

508 * @return {Object<data, signatures, filename>} - data as JS binary string
509 */
510export async function decryptFile({encryptedFile, unlockKey, uiLogSource}) {
511 let armoredMessage;
512 let binaryMessage;
513 try {
514 const content = dataURL2str(encryptedFile.content);
515 if (/^-----BEGIN PGP MESSAGE-----/.test(content)) {
516 armoredMessage = content;
517 } else {
518 binaryMessage = str2Uint8Array(content);
519 }
520 const message = await readMessage({armoredMessage, binaryMessage});
521 const encryptionKeyIds = message.getEncryptionKeyIDs();
522 const keyring = await getKeyringWithPrivKey(encryptionKeyIds);
523 if (!keyring) {
524 throw noKeyFoundError(encryptionKeyIds);
525 }
526 const result = await keyring.getPgpBackend().decrypt({base64: () => dataURL2base64(encryptedFile.content), message, keyring, unlockKey: options => unlockKey({message, ...options}), encryptionKeyIds, format: 'binary'});
527 await logDecryption(uiLogSource, keyring, encryptionKeyIds);
528 if (!result.filename) {
529 result.filename = encryptedFile.name.slice(0, -4);
530 }
531 const sigKeyIds = result.signatures.map(sig => sig.fingerprint || sig.keyId);
532 // sync public keys for the signatures
533 await syncPublicKeys({keyring, keyIds: sigKeyIds});
534 await addSignatureDetails({signatures: result.signatures, keyring});
535 return result;
536 } catch (error) {
537 console.log('pgpModel.decryptFile() error', error);
538 throw error;
539 }
540}

Callers 2

pgpModel-test.jsFile · 0.90
decryptFileMethod · 0.90

Calls 12

dataURL2strFunction · 0.90
str2Uint8ArrayFunction · 0.90
getKeyringWithPrivKeyFunction · 0.90
dataURL2base64Function · 0.90
syncPublicKeysFunction · 0.90
readMessageFunction · 0.85
noKeyFoundErrorFunction · 0.85
logDecryptionFunction · 0.85
addSignatureDetailsFunction · 0.85
decryptMethod · 0.80
unlockKeyFunction · 0.70
getPgpBackendMethod · 0.45

Tested by

no test coverage detected