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); SIN.super_.call(this, type, payload);
return; 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.data = new Buffer(1 + 1 + payload.length);
this.converters = this.encodings['binary'].converters; this.converters = this.encodings['binary'].converters;
this._encoding = this.encodings['binary']._encoding; this._encoding = this.encodings['binary']._encoding;

View File

@ -41,6 +41,13 @@ describe('SIN', function() {
var sin = new SIN(SIN.SIN_EPHEM, myhash); var sin = new SIN(SIN.SIN_EPHEM, myhash);
should.exist(sin); 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() { describe('#fromPubKey', function() {
it('should fail to create a new SIN not using a pub key', function() { it('should fail to create a new SIN not using a pub key', function() {