throw error if hashbuf is not 32 bytes
This commit is contained in:
parent
3daeabaf30
commit
ed335f35f7
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue