From 57f1692d9998742c1320cf39fc84644d5afe37d5 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 19 Mar 2019 18:26:42 +0100 Subject: [PATCH] fix: key.toJWK() fixed on windows * ci: try different os builds * fix: key.toJWK() fixed on windows resolves #17 --- .travis.yml | 10 +++++++++- lib/help/key_utils.js | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27819f5242..6a9b087a76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,15 @@ script: npm run coverage after_script: npx codecov jobs: include: + - stage: macOS + os: osx + script: npm run coverage + node_js: stable + - stage: windows + os: windows + script: npm run coverage + node_js: node - stage: Lint script: npm run lint - node_js: stable + node_js: node after_script: skip diff --git a/lib/help/key_utils.js b/lib/help/key_utils.js index 1878b64e98..c2462b4210 100644 --- a/lib/help/key_utils.js +++ b/lib/help/key_utils.js @@ -1,3 +1,4 @@ +const { EOL } = require('os') const keyto = require('@trust/keyto') const errors = require('../errors') @@ -8,7 +9,12 @@ module.exports.keyObjectToJWK = (keyObject) => { const type = keyObject.type === 'private' ? 'pkcs8' : 'spki' const format = 'pem' - const pem = keyObject.export({ type, format }) + let pem = keyObject.export({ type, format }) + + // keyObject export always uses \n but @trust/keyto splits based on the os.EOL + if (EOL !== '\n') { + pem = pem.replace(/\n/g, EOL) + } return keyto.from(pem, 'pem').toJwk(keyObject.type) }