Skip to content

Commit

Permalink
Add tests for the new sign/verify methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Spark-NF committed May 24, 2018
1 parent d7ffc16 commit 106ea44
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/test.rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,45 @@ keySizes.forEach(function(keySize, index){
});

});

describe('#sign() | #verify()', function(){

var maxLength = (((jse.getKey().n.bitLength()+7)>>3)-11);
var maxLengthBit = maxLength << 3;

it('should sign/verify up to '+maxLengthBit+' bit', function () {

var digest = function(data){ return data; };

var test = [];
for (var i=0; i<maxLength;i++)
test.push('a');
test = test.join('');

var signature = jse.sign(test, digest);
expect(signature).to.be.ok();

var verified = jse.verify(test, signature, digest);
expect(verified).to.be(true);

var failed = jse.verify('no', signature, digest);
expect(failed).to.be(false);

});

it('should fail to verify more than '+maxLengthBit+' bit', function(){

var test = [];
for (var i=0; i<(maxLength+1);i++)
test.push('a');
test = test.join('');

var signature = jse.sign(test);
expect(signature).to.not.be.ok();

});

});

describe('#getPublicKey()', function(){

Expand Down

0 comments on commit 106ea44

Please sign in to comment.