diff options
author | Tobias Nießen <tniessen@tnie.de> | 2018-12-25 13:13:52 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-08 00:20:09 +0100 |
commit | ae2d1f0e05449221ee770a393e5c967b359d9b1b (patch) | |
tree | 5d43c4d7b0509e47ca51ad7e6cfb4d3192c29f61 /test | |
parent | 27a03b84c42a021c94649b3f601800b7502a9c15 (diff) | |
download | android-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')
-rw-r--r-- | test/parallel/test-crypto-keygen.js | 16 |
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. |