generalize version numbers
This commit is contained in:
parent
e44b2480aa
commit
ca16817a1c
@ -3,15 +3,27 @@
|
|||||||
var Message = require('./Message');
|
var Message = require('./Message');
|
||||||
var ECIES = require('./ECIES');
|
var ECIES = require('./ECIES');
|
||||||
|
|
||||||
|
|
||||||
|
var majorVersion = 1;
|
||||||
|
var minorVersion = 0;
|
||||||
|
|
||||||
/* Encrypted, authenticated messages to be shared between copayers */
|
/* Encrypted, authenticated messages to be shared between copayers */
|
||||||
var AuthMessage = function() {
|
var AuthMessage = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AuthMessage.setVersion = function(major, minor) {
|
||||||
|
majorVersion = major;
|
||||||
|
minorVersion = minor;
|
||||||
|
};
|
||||||
|
|
||||||
AuthMessage.encode = function(topubkey, fromkey, payload, opts) {
|
AuthMessage.encode = function(topubkey, fromkey, payload, opts) {
|
||||||
var version1 = new Buffer([1]); //peers will reject messges containing not-understood version1
|
//peers should reject messges containing bigger major version
|
||||||
//i.e., increment version1 to prevent communications with old clients
|
//i.e., increment to prevent communications with old clients
|
||||||
var version2 = new Buffer([0]); //peers will not reject messages containing not-understood version2
|
var version1 = new Buffer([majorVersion]);
|
||||||
//i.e., increment version2 to allow communication with old clients, but signal new clients
|
|
||||||
|
//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) {
|
if (opts && opts.nonce && Buffer.isBuffer(opts.nonce) && opts.nonce.length == 8) {
|
||||||
var nonce = opts.nonce;
|
var nonce = opts.nonce;
|
||||||
@ -83,11 +95,11 @@ AuthMessage.decode = function(key, encoded, opts) {
|
|||||||
throw new Error('No data present');
|
throw new Error('No data present');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version1 !== 1) {
|
if (version1 !== majorVersion) {
|
||||||
throw new Error('Invalid version number');
|
throw new Error('Invalid version number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version2 !== 0) {
|
if (version2 !== minorVersion) {
|
||||||
//put special version2 handling code here, if ever needed
|
//put special version2 handling code here, if ever needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user