Skip to content

Commit

Permalink
Add tests for the private key methods.
Browse files Browse the repository at this point in the history
These all pass too!
  • Loading branch information
Dan Bornstein committed Feb 10, 2012
1 parent 8487da7 commit 3a5cf76
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions test/test.js
Expand Up @@ -91,11 +91,38 @@ function testPublicKeyMethods(key) {
test_publicDecrypt(key);
}

function test_toPrivatePem(key) {
var keyString = fixture.PRIVATE_KEY.toString(fixture.UTF8);
var result = key.toPrivatePem().toString(fixture.UTF8);
assert.equal(result, keyString);

result = key.toPrivatePem(fixture.UTF8);
assert.equal(result, keyString);
}

function test_decrypt(key) {
var encoded = new Buffer(fixture.PRIVATE_CIPHERTEXT_HEX, fixture.HEX);
var decoded = key.decrypt(encoded).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);

decoded = key.decrypt(fixture.PRIVATE_CIPHERTEXT_HEX, fixture.HEX,
fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
}

function test_privateEncrypt(key) {
var encoded = key.privateEncrypt(
new Buffer(fixture.PLAINTEXT, fixture.UTF8)).toString(fixture.HEX);
assert.equal(encoded, fixture.PUBLIC_CIPHERTEXT_HEX);

encoded = key.privateEncrypt(fixture.PLAINTEXT, fixture.UTF8, fixture.HEX);
assert.equal(encoded, fixture.PUBLIC_CIPHERTEXT_HEX);
}

function testPrivateKeyMethods(key) {
// FIXME
// test_toPrivatePem(key);
// test_decrypt(key);
// test_privateEncrypt(key);
test_toPrivatePem(key);
test_decrypt(key);
test_privateEncrypt(key);
}


Expand Down

0 comments on commit 3a5cf76

Please sign in to comment.