throw error if hashbuf is not 32 bytes

This commit is contained in:
Ryan X. Charles 2014-09-16 11:33:49 -07:00
parent 3daeabaf30
commit ed335f35f7
2 changed files with 14 additions and 0 deletions

View File

@ -156,6 +156,9 @@ ECDSA.prototype.sign = function() {
if (!hashbuf || !privkey || !d)
throw new Error('invalid parameters');
if (!Buffer.isBuffer(hashbuf) || hashbuf.length !== 32)
throw new Error('hashbuf must be a 32 byte buffer');
var N = Point.getN();
var G = Point.getG();
var e = BN().fromBuffer(hashbuf);

View File

@ -144,6 +144,17 @@ describe("ECDSA", function() {
ecdsa.verify().should.equal(true);
});
it('should should throw an error if hashbuf is not 32 bytes', function() {
var ecdsa2 = ECDSA().set({
hashbuf: ecdsa.hashbuf.slice(0, 31),
keypair: ecdsa.keypair
});
ecdsa2.randomK();
(function() {
ecdsa2.sign();
}).should.throw('hashbuf must be a 32 byte buffer');
});
});
describe('#signRandomK', function() {