diff --git a/js/libtextsecure.js b/js/libtextsecure.js index f6abed1b5..4016a9adc 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37496,6 +37496,17 @@ window.axolotl.protocol = function(storage_interface) { return result; }); }); + }; + + function getPaddedMessageLength(messageLength) { + var messageLengthWithTerminator = messageLength + 1; + var messagePartCount = messageLengthWithTerminator / 160; + + if (messageLengthWithTerminator % 160 != 0) { + messagePartCount++; + } + + return messagePartCount * 160; } // return Promise(encoded [PreKey]WhisperMessage) @@ -37509,7 +37520,7 @@ window.axolotl.protocol = function(storage_interface) { var msg = new axolotlInternal.protobuf.WhisperMessage(); var plaintext = axolotlInternal.utils.convertToArrayBuffer(pushMessageContent.encode()); - var paddedPlaintext = new Uint8Array(Math.ceil((plaintext.byteLength + 1) / 160.0) * 160 - 1); + var paddedPlaintext = new Uint8Array(getPaddedMessageLength(plaintext.byteLength)); paddedPlaintext.set(new Uint8Array(plaintext)); paddedPlaintext[plaintext.byteLength] = 0x80; diff --git a/libtextsecure/libaxolotl.js b/libtextsecure/libaxolotl.js index 9917754f9..b7b4462fc 100644 --- a/libtextsecure/libaxolotl.js +++ b/libtextsecure/libaxolotl.js @@ -37398,6 +37398,17 @@ window.axolotl.protocol = function(storage_interface) { return result; }); }); + }; + + function getPaddedMessageLength(messageLength) { + var messageLengthWithTerminator = messageLength + 1; + var messagePartCount = messageLengthWithTerminator / 160; + + if (messageLengthWithTerminator % 160 != 0) { + messagePartCount++; + } + + return messagePartCount * 160; } // return Promise(encoded [PreKey]WhisperMessage) @@ -37411,7 +37422,7 @@ window.axolotl.protocol = function(storage_interface) { var msg = new axolotlInternal.protobuf.WhisperMessage(); var plaintext = axolotlInternal.utils.convertToArrayBuffer(pushMessageContent.encode()); - var paddedPlaintext = new Uint8Array(Math.ceil((plaintext.byteLength + 1) / 160.0) * 160 - 1); + var paddedPlaintext = new Uint8Array(getPaddedMessageLength(plaintext.byteLength)); paddedPlaintext.set(new Uint8Array(plaintext)); paddedPlaintext[plaintext.byteLength] = 0x80;