|
1 | 1 | let signal = require('signal-protocol') |
2 | 2 | let through = require('through2') |
3 | | -let l = require('./helpers') |
| 3 | +// let l = require('./helpers') |
4 | 4 | // var textsecure = require('signal-protocol/test/temp_helpers') |
5 | 5 | const PREKEY_BUNDLE_CODE = 3 //textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE |
6 | | - |
7 | 6 | let pushPromise = (p, next) => p.then(x => next(null, x), next) |
8 | | -let streamF = f => through.obj(function (buf, enc, next) { pushPromise(f(buf), next) }) |
9 | | -let duplexify = require('duplexify') |
| 7 | +let streamF = f => through.obj((buf, enc, next) => pushPromise(f(buf), next)) |
10 | 8 |
|
11 | 9 | function encryptor (cipher) { |
12 | 10 | return function (plaintext) { |
13 | | - return cipher.encrypt(plaintext) |
| 11 | + return Promise.all([ |
| 12 | + cipher.encrypt(plaintext.slice(0, 200)), |
| 13 | + cipher.encrypt(plaintext.slice(201, 400)), |
| 14 | + ]) |
14 | 15 | } |
15 | 16 | } |
16 | 17 |
|
17 | 18 | function decryptor (cipher) { |
18 | 19 | // returns a promise of plaintext |
19 | | - return function (ciphertext) { |
| 20 | + function dec (ciphertext) { |
20 | 21 | // console.log('ciphertext to decrypt is', ciphertext) |
21 | 22 | if (ciphertext.type == PREKEY_BUNDLE_CODE) |
22 | 23 | return cipher.decryptPreKeyWhisperMessage(ciphertext.body, 'binary') |
23 | 24 | return cipher.decryptWhisperMessage(ciphertext.body, 'binary') |
24 | 25 | } |
| 26 | + return function (ctxts) { |
| 27 | + return Promise.all(ctxts.map(dec)) |
| 28 | + } |
25 | 29 | } |
26 | 30 |
|
27 | 31 | module.exports = function (cipher) { |
|
0 commit comments