summaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto-keygen.js
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2018-12-25 13:13:52 +0100
committerAnna Henningsen <anna@addaleax.net>2019-01-08 00:20:09 +0100
commitae2d1f0e05449221ee770a393e5c967b359d9b1b (patch)
tree5d43c4d7b0509e47ca51ad7e6cfb4d3192c29f61 /test/parallel/test-crypto-keygen.js
parent27a03b84c42a021c94649b3f601800b7502a9c15 (diff)
downloadandroid-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.tar.gz
android-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.tar.bz2
android-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.zip
crypto: always accept private keys as public keys
Some APIs already accept private keys instead of public keys. This changes all relevant crypto APIs to do so. PR-URL: https://github.com/nodejs/node/pull/25217 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-keygen.js')
-rw-r--r--test/parallel/test-crypto-keygen.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js
index aabd92e369..61cd69b5d6 100644
--- a/test/parallel/test-crypto-keygen.js
+++ b/test/parallel/test-crypto-keygen.js
@@ -31,9 +31,11 @@ function assertApproximateSize(key, expectedSize) {
function testEncryptDecrypt(publicKey, privateKey) {
const message = 'Hello Node.js world!';
const plaintext = Buffer.from(message, 'utf8');
- const ciphertext = publicEncrypt(publicKey, plaintext);
- const received = privateDecrypt(privateKey, ciphertext);
- assert.strictEqual(received.toString('utf8'), message);
+ for (const key of [publicKey, privateKey]) {
+ const ciphertext = publicEncrypt(key, plaintext);
+ const received = privateDecrypt(privateKey, ciphertext);
+ assert.strictEqual(received.toString('utf8'), message);
+ }
}
// Tests that a key pair can be used for signing / verification.
@@ -41,9 +43,11 @@ function testSignVerify(publicKey, privateKey) {
const message = 'Hello Node.js world!';
const signature = createSign('SHA256').update(message)
.sign(privateKey, 'hex');
- const okay = createVerify('SHA256').update(message)
- .verify(publicKey, signature, 'hex');
- assert(okay);
+ for (const key of [publicKey, privateKey]) {
+ const okay = createVerify('SHA256').update(message)
+ .verify(key, signature, 'hex');
+ assert(okay);
+ }
}
// Constructs a regular expression for a PEM-encoded key with the given label.