Skip to content

Commit 3ac5f11

Browse files
committed
crypto: make verify() return true or false, not 1 or 0
It's what the documentation says it should return.
1 parent 1cb6fe4 commit 3ac5f11

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3474,7 +3474,7 @@ class Verify : public ObjectWrap {
34743474
delete [] kbuf;
34753475
delete [] hbuf;
34763476

3477-
return scope.Close(Integer::New(r));
3477+
return Boolean::New(r && r != -1);
34783478
}
34793479

34803480
Verify () : ObjectWrap () {

test/simple/test-crypto.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ var verified = crypto.createVerify('RSA-SHA1')
286286
.update('Test')
287287
.update('123')
288288
.verify(certPem, s1, 'base64');
289-
assert.ok(verified, 'sign and verify (base 64)');
289+
assert.strictEqual(verified, true, 'sign and verify (base 64)');
290290

291291
var s2 = crypto.createSign('RSA-SHA256')
292292
.update('Test123')
@@ -295,7 +295,7 @@ var verified = crypto.createVerify('RSA-SHA256')
295295
.update('Test')
296296
.update('123')
297297
.verify(certPem, s2); // binary
298-
assert.ok(verified, 'sign and verify (binary)');
298+
assert.strictEqual(verified, true, 'sign and verify (binary)');
299299

300300
// Test encryption and decryption
301301
var plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
@@ -392,7 +392,7 @@ var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex');
392392
assert.equal(rsaSignature, '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6');
393393

394394
rsaVerify.update(rsaPubPem);
395-
assert.equal(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), 1);
395+
assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true);
396396

397397
// Test PBKDF2 with RFC 6070 test vectors (except #4)
398398

0 commit comments

Comments
 (0)