Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: put optional args last for key export (#154)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: key export arguments are now swapped so that the optional format is last
  • Loading branch information
dirkmc authored and jacobheun committed Jul 10, 2019
1 parent ad71072 commit d675670
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/keys/rsa-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,11 @@ class RsaPrivateKey {
/**
* Exports the key into a password protected PEM format
*
* @param {string} [format] - Defaults to 'pkcs-8'.
* @param {string} password - The password to read the encrypted PEM
* @param {string} [format] - Defaults to 'pkcs-8'.
* @returns {KeyInfo}
*/
async export (format, password) { // eslint-disable-line require-await
if (password == null) {
password = format
format = 'pkcs-8'
}

async export (password, format = 'pkcs-8') { // eslint-disable-line require-await
let pem = null

const buffer = new forge.util.ByteBuffer(this.marshal())
Expand Down
2 changes: 1 addition & 1 deletion test/keys/rsa.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('RSA', function () {

describe('export and import', () => {
it('password protected PKCS #8', async () => {
const pem = await key.export('pkcs-8', 'my secret')
const pem = await key.export('my secret', 'pkcs-8')
expect(pem).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----')
const clone = await crypto.keys.import(pem, 'my secret')
expect(clone).to.exist()
Expand Down

0 comments on commit d675670

Please sign in to comment.