MCPcopy
hub / github.com/mailvelope/mailvelope / getKeyringWithPrivKey

Function getKeyringWithPrivKey

src/modules/keyring.js:508–538  ·  view source on GitHub ↗
(keyIds, keyringId, noCache)

Source from the content-addressed store, hash-verified

506 * @return {KeyringBase}
507 */
508export async function getKeyringWithPrivKey(keyIds, keyringId, noCache) {
509 await keyringInitialized;
510 keyIds = toArray(keyIds);
511 let keyrings;
512 if (!keyringId) {
513 keyrings = await getAll();
514 if (keyringMap.has(GNUPG_KEYRING_ID)) {
515 // sort keyrings according to preference
516 keyrings.sort(compareKeyringsByPreference);
517 }
518 } else {
519 keyrings = getPreferredKeyringQueue(keyringId);
520 }
521 // if no keyIds return first keyring
522 if (!keyIds.length) {
523 return keyrings[0];
524 }
525 // return first keyring that includes private keys with keyIds
526 for (const keyring of keyrings) {
527 if (keyring.hasPrivateKey(keyIds)) {
528 if (keyring.id === GNUPG_KEYRING_ID && keyIds.length && noCache) {
529 // with noCache enforcement we want to make sure that a private key operation always triggers
530 // a password dialog and therefore a user interaction. As GPGME does not allow to detect
531 // if cache is used or not we skip the GnuPG keyring here.
532 continue;
533 }
534 return keyring;
535 }
536 }
537 return null;
538}
539
540/**
541 * Get preferred keyring

Callers 8

keyring-test.jsFile · 0.90
decryptMessageFunction · 0.90
encryptMessageFunction · 0.90
signMessageFunction · 0.90
encryptFileFunction · 0.90
decryptFileFunction · 0.90
canUnlockKeyMethod · 0.90
getPreferredKeyringFunction · 0.85

Calls 5

toArrayFunction · 0.90
getPreferredKeyringQueueFunction · 0.85
getAllFunction · 0.70
hasMethod · 0.45
hasPrivateKeyMethod · 0.45

Tested by

no test coverage detected