diff --git a/src/worker/async_proxy.js b/src/worker/async_proxy.js index ad95f091..4b904a29 100644 --- a/src/worker/async_proxy.js +++ b/src/worker/async_proxy.js @@ -134,6 +134,20 @@ AsyncProxy.prototype.seedRandom = async function(workerId, size) { this.workers[workerId].postMessage({ event:'seed-random', buf }, util.getTransferables(buf, true)); }; +/** + * Clear key caches + * @async + */ +AsyncProxy.prototype.clearKeyCache = async function() { + await Promise.all(this.workers.map(worker => new Promise((resolve, reject) => { + const id = this.getID(); + + worker.postMessage({ id, event: 'clear-key-cache' }); + + this.tasks[id] = { resolve, reject }; + }))); +}; + /** * Terminates the workers */ diff --git a/src/worker/worker.js b/src/worker/worker.js index 44b3d96d..05815504 100644 --- a/src/worker/worker.js +++ b/src/worker/worker.js @@ -119,6 +119,16 @@ function getCachedKey(key) { * @param {Object} options The api function's options */ function delegate(id, method, options) { + if (method === 'clear-key-cache') { + Array.from(keyCache.values()).forEach(key => { + if (key.isPrivate()) { + key.clearPrivateParams(); + } + }); + keyCache.clear(); + response({ id, event: 'method-return' }); + return; + } if (typeof openpgp[method] !== 'function') { response({ id:id, event:'method-return', err:'Unknown Worker Event' }); return;