Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29 from WhisperSystems/unlimited-for-yourself
Browse files Browse the repository at this point in the history
fillMessageKeys: allow for SessionCipher creator to specify limit
  • Loading branch information
scottnonnenberg authored Aug 4, 2017
2 parents f308236 + b6c3093 commit 3d72df7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 11 additions & 4 deletions dist/libsignal-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -36032,7 +36032,14 @@ libsignal.SessionBuilder = function (storage, remoteAddress) {
this.processV3 = builder.processV3.bind(builder);
};

function SessionCipher(storage, remoteAddress) {
function SessionCipher(storage, remoteAddress, options) {
options = options || {};

if (typeof options.messageKeysLimit === 'undefined') {
options.messageKeysLimit = 1000;
}

this.messageKeysLimit = options.messageKeysLimit;
this.remoteAddress = remoteAddress;
this.storage = storage;
}
Expand Down Expand Up @@ -36305,7 +36312,7 @@ SessionCipher.prototype = {
});
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}
Expand Down Expand Up @@ -36428,8 +36435,8 @@ SessionCipher.prototype = {
}
};

libsignal.SessionCipher = function(storage, remoteAddress) {
var cipher = new SessionCipher(storage, remoteAddress);
libsignal.SessionCipher = function(storage, remoteAddress, options) {
var cipher = new SessionCipher(storage, remoteAddress, options);

// returns a Promise that resolves to a ciphertext object
this.encrypt = cipher.encrypt.bind(cipher);
Expand Down
15 changes: 11 additions & 4 deletions src/SessionCipher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
function SessionCipher(storage, remoteAddress) {
function SessionCipher(storage, remoteAddress, options) {
options = options || {};

if (typeof options.messageKeysLimit === 'undefined') {
options.messageKeysLimit = 1000;
}

this.messageKeysLimit = options.messageKeysLimit;
this.remoteAddress = remoteAddress;
this.storage = storage;
}
Expand Down Expand Up @@ -271,7 +278,7 @@ SessionCipher.prototype = {
});
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}
Expand Down Expand Up @@ -394,8 +401,8 @@ SessionCipher.prototype = {
}
};

libsignal.SessionCipher = function(storage, remoteAddress) {
var cipher = new SessionCipher(storage, remoteAddress);
libsignal.SessionCipher = function(storage, remoteAddress, options) {
var cipher = new SessionCipher(storage, remoteAddress, options);

// returns a Promise that resolves to a ciphertext object
this.encrypt = cipher.encrypt.bind(cipher);
Expand Down

0 comments on commit 3d72df7

Please sign in to comment.