From ca16817a1c484f3d2cb880a3c353fdb45a5e045b Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 1 Aug 2014 16:44:39 -0300 Subject: [PATCH] generalize version numbers --- lib/AuthMessage.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/AuthMessage.js b/lib/AuthMessage.js index 010a9255e..c0d03e5a2 100644 --- a/lib/AuthMessage.js +++ b/lib/AuthMessage.js @@ -3,15 +3,27 @@ var Message = require('./Message'); var ECIES = require('./ECIES'); + +var majorVersion = 1; +var minorVersion = 0; + /* Encrypted, authenticated messages to be shared between copayers */ var AuthMessage = function() { }; +AuthMessage.setVersion = function(major, minor) { + majorVersion = major; + minorVersion = minor; +}; + AuthMessage.encode = function(topubkey, fromkey, payload, opts) { - var version1 = new Buffer([1]); //peers will reject messges containing not-understood version1 - //i.e., increment version1 to prevent communications with old clients - var version2 = new Buffer([0]); //peers will not reject messages containing not-understood version2 - //i.e., increment version2 to allow communication with old clients, but signal new clients + //peers should reject messges containing bigger major version + //i.e., increment to prevent communications with old clients + var version1 = new Buffer([majorVersion]); + + //peers should not reject messages containing not-understood minorversion + //i.e., increment to allow communication with old clients, but signal new clients + var version2 = new Buffer([minorVersion]); if (opts && opts.nonce && Buffer.isBuffer(opts.nonce) && opts.nonce.length == 8) { var nonce = opts.nonce; @@ -83,11 +95,11 @@ AuthMessage.decode = function(key, encoded, opts) { throw new Error('No data present'); } - if (version1 !== 1) { + if (version1 !== majorVersion) { throw new Error('Invalid version number'); } - if (version2 !== 0) { + if (version2 !== minorVersion) { //put special version2 handling code here, if ever needed }