From 19584e1f267bde36b423661e58e7ea4ed89ee841 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 24 Jul 2014 01:40:13 -0300 Subject: [PATCH] add check in constructor --- lib/SIN.js | 3 +++ test/test.SIN.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/SIN.js b/lib/SIN.js index a14cfe5..5143c93 100644 --- a/lib/SIN.js +++ b/lib/SIN.js @@ -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; diff --git a/test/test.SIN.js b/test/test.SIN.js index a1c00be..23d117a 100644 --- a/test/test.SIN.js +++ b/test/test.SIN.js @@ -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() {