|
|
|
@ -8,14 +8,9 @@ define([
|
|
|
|
|
var cypherChunkLength = 131088;
|
|
|
|
|
|
|
|
|
|
var computeEncryptedSize = function (bytes, meta) {
|
|
|
|
|
var metasize = Nacl.util.decodeUTF8(meta).length + 18;
|
|
|
|
|
var metasize = Nacl.util.decodeUTF8(JSON.stringify(meta)).length;
|
|
|
|
|
var chunks = Math.ceil(bytes / plainChunkLength);
|
|
|
|
|
console.log({
|
|
|
|
|
metasize: metasize,
|
|
|
|
|
chunks: chunks,
|
|
|
|
|
bytes: bytes,
|
|
|
|
|
});
|
|
|
|
|
return metasize + (chunks * 16) + bytes;
|
|
|
|
|
return metasize + 18 + (chunks * 16) + bytes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var encodePrefix = function (p) {
|
|
|
|
@ -142,23 +137,15 @@ define([
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
0: metadata
|
|
|
|
|
1: u8
|
|
|
|
|
2: done
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var state = 0;
|
|
|
|
|
|
|
|
|
|
var next = function (cb) {
|
|
|
|
|
if (state === 2) { return void cb(); }
|
|
|
|
|
|
|
|
|
|
var start;
|
|
|
|
|
var end;
|
|
|
|
|
var part;
|
|
|
|
|
var box;
|
|
|
|
|
|
|
|
|
|
// DONE
|
|
|
|
|
if (state === 2) { return void cb(); }
|
|
|
|
|
|
|
|
|
|
if (state === 0) { // metadata...
|
|
|
|
|
part = new Uint8Array(plaintext);
|
|
|
|
|
box = Nacl.secretbox(part, nonce, key);
|
|
|
|
@ -171,10 +158,6 @@ define([
|
|
|
|
|
.concat(slice(box)));
|
|
|
|
|
state++;
|
|
|
|
|
|
|
|
|
|
// TODO verify that each box is the expected size
|
|
|
|
|
|
|
|
|
|
console.log(part.length, prefixed.length);
|
|
|
|
|
|
|
|
|
|
return void cb(void 0, prefixed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -187,8 +170,6 @@ define([
|
|
|
|
|
increment(nonce);
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
console.log(part.length, box.length);
|
|
|
|
|
|
|
|
|
|
// regular data is done
|
|
|
|
|
if (i * plainChunkLength >= u8.length) { state = 2; }
|
|
|
|
|
|
|
|
|
|