From 436edde32c17332d39464fdf31f46815aee55173 Mon Sep 17 00:00:00 2001 From: Patrick Roumanoff Date: Tue, 13 Feb 2018 09:53:20 +0100 Subject: [PATCH] shotform --- base64url.js | 1 + js-keygen.js | 8 +++----- ssh-util.js | 15 ++++----------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/base64url.js b/base64url.js index 3b47f0a..197676e 100644 --- a/base64url.js +++ b/base64url.js @@ -26,4 +26,5 @@ function base64urlDecode(s) { return window.atob(s); // Regular base64 decoder } +module = module || {}; module.exports = { base64urlDecode, base64urlEncode }; diff --git a/js-keygen.js b/js-keygen.js index ffd1992..7c986e1 100644 --- a/js-keygen.js +++ b/js-keygen.js @@ -38,19 +38,17 @@ function generateKeyPair(alg, size, name) { extractable, ["sign", "verify"] ) - .then(function(key) { + .then(key => { var privateKey = window.crypto.subtle .exportKey("jwk", key.privateKey) .then(encodePrivateKey) .then(wrap) .then(rsaPrivateKey); - var publicKey = window.crypto.subtle.exportKey("jwk", key.publicKey).then(function(jwk) { - return encodePublicKey(jwk, name); - }); - + var publicKey = window.crypto.subtle.exportKey("jwk", key.publicKey).then(jwk => encodePublicKey(jwk, name)); return Promise.all([privateKey, publicKey]); }); } +module = module || {}; module.exportKey = { arrayBufferToBase64, generateKeyPair }; diff --git a/ssh-util.js b/ssh-util.js index 4e31e5d..0e060de 100644 --- a/ssh-util.js +++ b/ssh-util.js @@ -5,9 +5,7 @@ function arrayToString(a) { } function stringToArray(s) { - return s.split("").map(function(c) { - return c.charCodeAt(); - }); + return s.split("").map(c => c.charCodeAt()); } function base64urlToArray(s) { @@ -19,13 +17,7 @@ function pemToArray(pem) { } function arrayToPem(a) { - return window.btoa( - a - .map(function(c) { - return String.fromCharCode(c); - }) - .join("") - ); + return window.btoa(a.map(c => String.fromCharCode(c)).join("")); } function arrayToLen(a) { @@ -114,7 +106,7 @@ function asnEncodeLen(n) { function encodePrivateKey(jwk) { var order = ["n", "e", "d", "p", "q", "dp", "dq", "qi"]; - var list = order.map(function(prop) { + var list = order.map(prop => { var v = checkHighestBit(stringToArray(base64urlDecode(jwk[prop]))); var len = asnEncodeLen(v.length); return [0x02].concat(len, v); // int tag is 0x02 @@ -126,4 +118,5 @@ function encodePrivateKey(jwk) { return arrayToPem(a); } +module = module || {}; module.exports = { base64urlToArray, decodePublicKey, encodePublicKey, encodePrivateKey };