(keyIds, keyringId, noCache)
| 506 | * @return {KeyringBase} |
| 507 | */ |
| 508 | export 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 |
no test coverage detected