generalize version numbers

This commit is contained in:
Manuel Araoz 2014-08-01 16:44:39 -03:00
parent e44b2480aa
commit ca16817a1c
1 changed files with 18 additions and 6 deletions

View File

@ -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
}