From 35c13212ddacd2eeefc8b7f83e273b379589a0d3 Mon Sep 17 00:00:00 2001
From: Daniel Huigens <d.huigens@protonmail.com>
Date: Tue, 18 Feb 2020 17:44:00 +0100
Subject: [PATCH] Remove unnecessary calls to convertStreams()

---
 src/openpgp.js | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

diff --git a/src/openpgp.js b/src/openpgp.js
index 6abcf11a..2d6b54af 100644
--- a/src/openpgp.js
+++ b/src/openpgp.js
@@ -146,14 +146,14 @@ export function generateKey({ userIds = [], passphrase = "", numBits = 2048, rsa
     const revocationCertificate = await key.getRevocationCertificate(date);
     key.revocationSignatures = [];
 
-    return convertStreams({
+    return {
 
       key: key,
       privateKeyArmored: key.armor(),
       publicKeyArmored: key.toPublic().armor(),
       revocationCertificate: revocationCertificate
 
-    });
+    };
   }).catch(onError.bind(null, 'Error generating keypair'));
 }
 
@@ -179,14 +179,14 @@ export function reformatKey({ privateKey, userIds = [], passphrase = "", keyExpi
     const revocationCertificate = await key.getRevocationCertificate(date);
     key.revocationSignatures = [];
 
-    return convertStreams({
+    return {
 
       key: key,
       privateKeyArmored: key.armor(),
       publicKeyArmored: key.toPublic().armor(),
       revocationCertificate: revocationCertificate
 
-    });
+    };
   }).catch(onError.bind(null, 'Error reformatting keypair'));
 }
 
@@ -221,7 +221,6 @@ export function revokeKey({
       return key.revoke(reasonForRevocation);
     }
   }).then(async key => {
-    await convertStreams(key);
     if (key.isPrivate()) {
       const publicKey = key.toPublic();
       return {
@@ -636,27 +635,6 @@ async function convertStream(data, streaming, encoding = 'utf8') {
   return data;
 }
 
-/**
- * Convert object properties from Stream
- * @param  {Object} obj                               the data to convert
- * @param  {'web'|'ponyfill'|'node'|false} streaming  (optional) whether to return ReadableStreams, and of what type
- * @param  {'utf8'|'binary'} encoding                 (optional) how to return data in Node Readable streams
- * @param  {Array<String>} keys                       (optional) which keys to return as streams, if possible
- * @returns {Object}                                  the data in the respective format
- */
-async function convertStreams(obj, streaming, encoding = 'utf8', keys = []) {
-  if (Object.prototype.isPrototypeOf(obj) && !Uint8Array.prototype.isPrototypeOf(obj)) {
-    await Promise.all(Object.entries(obj).map(async ([key, value]) => { // recursively search all children
-      if (util.isStream(value) || keys.includes(key)) {
-        obj[key] = await convertStream(value, streaming, encoding);
-      } else {
-        await convertStreams(obj[key], streaming, encoding);
-      }
-    }));
-  }
-  return obj;
-}
-
 /**
  * Link result.data to the message stream for cancellation.
  * @param  {Object} result                  the data to convert