fix: put optional args last for key export (#154)

BREAKING CHANGE: key export arguments are now swapped so that the optional format is last
This commit is contained in:
dirkmc 2019-07-10 13:03:34 -04:00 committed by Jacob Heun
parent ad7107233e
commit d675670ed9
2 changed files with 3 additions and 8 deletions

View File

@ -103,16 +103,11 @@ class RsaPrivateKey {
/** /**
* Exports the key into a password protected PEM format * 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} password - The password to read the encrypted PEM
* @param {string} [format] - Defaults to 'pkcs-8'.
* @returns {KeyInfo} * @returns {KeyInfo}
*/ */
async export (format, password) { // eslint-disable-line require-await async export (password, format = 'pkcs-8') { // eslint-disable-line require-await
if (password == null) {
password = format
format = 'pkcs-8'
}
let pem = null let pem = null
const buffer = new forge.util.ByteBuffer(this.marshal()) const buffer = new forge.util.ByteBuffer(this.marshal())

View File

@ -88,7 +88,7 @@ describe('RSA', function () {
describe('export and import', () => { describe('export and import', () => {
it('password protected PKCS #8', async () => { 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-----') expect(pem).to.startsWith('-----BEGIN ENCRYPTED PRIVATE KEY-----')
const clone = await crypto.keys.import(pem, 'my secret') const clone = await crypto.keys.import(pem, 'my secret')
expect(clone).to.exist() expect(clone).to.exist()