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

Commit 3d72df7

Browse files
Merge pull request #29 from WhisperSystems/unlimited-for-yourself
fillMessageKeys: allow for SessionCipher creator to specify limit
2 parents f308236 + b6c3093 commit 3d72df7

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

dist/libsignal-protocol.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36032,7 +36032,14 @@ libsignal.SessionBuilder = function (storage, remoteAddress) {
3603236032
this.processV3 = builder.processV3.bind(builder);
3603336033
};
3603436034

36035-
function SessionCipher(storage, remoteAddress) {
36035+
function SessionCipher(storage, remoteAddress, options) {
36036+
options = options || {};
36037+
36038+
if (typeof options.messageKeysLimit === 'undefined') {
36039+
options.messageKeysLimit = 1000;
36040+
}
36041+
36042+
this.messageKeysLimit = options.messageKeysLimit;
3603636043
this.remoteAddress = remoteAddress;
3603736044
this.storage = storage;
3603836045
}
@@ -36305,7 +36312,7 @@ SessionCipher.prototype = {
3630536312
});
3630636313
},
3630736314
fillMessageKeys: function(chain, counter) {
36308-
if (Object.keys(chain.messageKeys).length >= 1000) {
36315+
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
3630936316
console.log("Too many message keys for chain");
3631036317
return Promise.resolve(); // Stalker, much?
3631136318
}
@@ -36428,8 +36435,8 @@ SessionCipher.prototype = {
3642836435
}
3642936436
};
3643036437

36431-
libsignal.SessionCipher = function(storage, remoteAddress) {
36432-
var cipher = new SessionCipher(storage, remoteAddress);
36438+
libsignal.SessionCipher = function(storage, remoteAddress, options) {
36439+
var cipher = new SessionCipher(storage, remoteAddress, options);
3643336440

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

src/SessionCipher.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
function SessionCipher(storage, remoteAddress) {
1+
function SessionCipher(storage, remoteAddress, options) {
2+
options = options || {};
3+
4+
if (typeof options.messageKeysLimit === 'undefined') {
5+
options.messageKeysLimit = 1000;
6+
}
7+
8+
this.messageKeysLimit = options.messageKeysLimit;
29
this.remoteAddress = remoteAddress;
310
this.storage = storage;
411
}
@@ -271,7 +278,7 @@ SessionCipher.prototype = {
271278
});
272279
},
273280
fillMessageKeys: function(chain, counter) {
274-
if (Object.keys(chain.messageKeys).length >= 1000) {
281+
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
275282
console.log("Too many message keys for chain");
276283
return Promise.resolve(); // Stalker, much?
277284
}
@@ -394,8 +401,8 @@ SessionCipher.prototype = {
394401
}
395402
};
396403

397-
libsignal.SessionCipher = function(storage, remoteAddress) {
398-
var cipher = new SessionCipher(storage, remoteAddress);
404+
libsignal.SessionCipher = function(storage, remoteAddress, options) {
405+
var cipher = new SessionCipher(storage, remoteAddress, options);
399406

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

0 commit comments

Comments
 (0)