From 2a89baa837b33f99ca14f864700d83aa4a35066e Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Fri, 22 May 2015 12:02:23 -0700 Subject: [PATCH] tanx updates --- src/crypto/public_key/rsa.js | 26 +++++++++++++------------- src/util.js | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 1d92216e..bf7ddbc3 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -140,17 +140,6 @@ function RSA() { // Native RSA keygen using Web Crypto // - function convertKeyOperation(keyop, errmsg) { - return new Promise(function(resolve, reject) { - keyop.onerror = function (err) { - reject(new Error(errmsg)); - } - keyop.oncomplete = function (e) { - resolve(e.target.result); - } - }); - } - if (webCrypto) { var Euint32 = new Uint32Array([parseInt(E, 16)]); // get integer of exponent var Euint8 = new Uint8Array(Euint32.buffer); // get bytes of exponent @@ -195,8 +184,8 @@ function RSA() { function exportKey(keypair) { // export the generated keys as JsonWebKey (JWK) // https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33 - key = webCrypto.exportKey('jwk', keypair.privateKey); - if(!(key instanceof Promise)) { // IE11 KeyOperation + var key = webCrypto.exportKey('jwk', keypair.privateKey); + if (!(key instanceof Promise)) { // IE11 KeyOperation key = convertKeyOperation(key, 'Error exporting RSA key pair.'); } return key; @@ -221,6 +210,17 @@ function RSA() { return key; } + function convertKeyOperation(keyop, errmsg) { + return new Promise(function(resolve, reject) { + keyop.onerror = function (err) { + reject(new Error(errmsg)); + } + keyop.oncomplete = function (e) { + resolve(e.target.result); + } + }); + } + // // JS code // diff --git a/src/util.js b/src/util.js index c2f9c386..a88a2952 100644 --- a/src/util.js +++ b/src/util.js @@ -321,10 +321,10 @@ module.exports = { } if (typeof window !== 'undefined') { - if(window.crypto) { + if (window.crypto) { return window.crypto.subtle || window.crypto.webkitSubtle; } - if(window.msCrypto) { + if (window.msCrypto) { return window.msCrypto.subtle; } }