From 3ac5f1106d31bad2e47ca158d9bc95afd38afdca Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 17 Nov 2011 20:46:40 +0100 Subject: [PATCH] crypto: make verify() return true or false, not 1 or 0 It's what the documentation says it should return. --- src/node_crypto.cc | 2 +- test/simple/test-crypto.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 16fbaea019a..d0fcfc9a2a9 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3474,7 +3474,7 @@ class Verify : public ObjectWrap { delete [] kbuf; delete [] hbuf; - return scope.Close(Integer::New(r)); + return Boolean::New(r && r != -1); } Verify () : ObjectWrap () { diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 583eec75519..6b1c6ca0204 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -286,7 +286,7 @@ var verified = crypto.createVerify('RSA-SHA1') .update('Test') .update('123') .verify(certPem, s1, 'base64'); -assert.ok(verified, 'sign and verify (base 64)'); +assert.strictEqual(verified, true, 'sign and verify (base 64)'); var s2 = crypto.createSign('RSA-SHA256') .update('Test123') @@ -295,7 +295,7 @@ var verified = crypto.createVerify('RSA-SHA256') .update('Test') .update('123') .verify(certPem, s2); // binary -assert.ok(verified, 'sign and verify (binary)'); +assert.strictEqual(verified, true, 'sign and verify (binary)'); // Test encryption and decryption var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; @@ -392,7 +392,7 @@ var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); assert.equal(rsaSignature, '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6'); rsaVerify.update(rsaPubPem); -assert.equal(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), 1); +assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); // Test PBKDF2 with RFC 6070 test vectors (except #4)