Skip to content

Commit

Permalink
Merge pull request #145 from brpowell/bp/cipherAliasUpdate
Browse files Browse the repository at this point in the history
Update secureBuffer cipherName
  • Loading branch information
tnoonan-salesforce authored Jun 28, 2019
2 parents 69669a0 + b55fcde commit 6662590
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/unit/secureStringTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { expect } from 'chai';
import * as crypto from 'crypto';
import { stub } from 'sinon';
import { SecureBuffer } from '../../src/secureBuffer';

describe('secureBuffer', async () => {
Expand Down Expand Up @@ -49,4 +51,23 @@ describe('secureBuffer', async () => {
expect(buffer.toString('utf8')).to.not.be.equal(secretText);
});
});

it('test backwards compatibility between aes256 and aes-256-cbc', () => {
const key = Buffer.from('aaaabbbbccccddddeeeeffffgggghhhh');
const iv = Buffer.from('aaaabbbbccccdddd');
const cipher = crypto.createCipheriv('aes256', key, iv);
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
const createCipherStub = stub(crypto, 'createCipheriv').returns(cipher);
const createDecipherStub = stub(crypto, 'createDecipheriv').returns(decipher);
try {
const secure = new SecureBuffer();
secure.consume(Buffer.from(secretText, 'utf8'));
expect(createCipherStub.calledOnce).to.be.true;
secure.value(val => expect(val.toString('utf8')).to.be.equal(secretText));
expect(createDecipherStub.calledOnce).to.be.true;
} finally {
createCipherStub.restore();
createDecipherStub.restore();
}
});
});

0 comments on commit 6662590

Please sign in to comment.