From f0633f00eaaa59d4f910b6899623e37c220f3e7b Mon Sep 17 00:00:00 2001
From: Daniel Huigens <d.huigens@protonmail.com>
Date: Tue, 29 May 2018 14:35:09 +0200
Subject: [PATCH] Don't repeatedly decrypt the same key in unit tests

---
 test/general/openpgp.js | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/test/general/openpgp.js b/test/general/openpgp.js
index 2d8606ef..04bb25a5 100644
--- a/test/general/openpgp.js
+++ b/test/general/openpgp.js
@@ -817,9 +817,13 @@ describe('OpenPGP.js public api tests', function() {
       describe('encryptSessionKey, decryptSessionKeys', function() {
         const sk = new Uint8Array([0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01]);
 
+        let decryptedPrivateKey;
         beforeEach(async function() {
-          expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
-          return true;
+          if (!decryptedPrivateKey) {
+            expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
+            decryptedPrivateKey = privateKey;
+          }
+          privateKey = decryptedPrivateKey;
         });
 
         it('should encrypt with public key', function() {
@@ -981,9 +985,13 @@ describe('OpenPGP.js public api tests', function() {
           '=6XMW\r\n' +
           '-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n';
 
-        beforeEach(async function () {
-          expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
-          return true;
+        let decryptedPrivateKey;
+        beforeEach(async function() {
+          if (!decryptedPrivateKey) {
+            expect(await privateKey.keys[0].decrypt(passphrase)).to.be.true;
+            decryptedPrivateKey = privateKey;
+          }
+          privateKey = decryptedPrivateKey;
         });
 
         it('should encrypt then decrypt', function () {