add check in constructor

This commit is contained in:
Matias Alejo Garcia 2014-07-24 01:40:13 -03:00
parent 3dd09129c8
commit 19584e1f26
2 changed files with 10 additions and 0 deletions

View File

@ -9,6 +9,9 @@ function SIN(type, payload) {
SIN.super_.call(this, type, payload);
return;
}
if ( !Buffer.isBuffer(payload) || payload.length != 20)
throw new Error('Payload must be 20 bytes');
this.data = new Buffer(1 + 1 + payload.length);
this.converters = this.encodings['binary'].converters;
this._encoding = this.encodings['binary']._encoding;

View File

@ -41,6 +41,13 @@ describe('SIN', function() {
var sin = new SIN(SIN.SIN_EPHEM, myhash);
should.exist(sin);
});
it('should fail with param version, string', function() {
var hash = '1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0';
( function (){
var sin = new SIN(SIN.SIN_EPHEM, hash);
}).should.throw();
});
});
describe('#fromPubKey', function() {
it('should fail to create a new SIN not using a pub key', function() {