Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging
commit
0f8ef2f516
|
@ -89,5 +89,15 @@ define([], function () {
|
|||
return Math.floor(bytes / 1024 * 100) / 100;
|
||||
};
|
||||
|
||||
Util.fetch = function (src, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", src, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onload = function () {
|
||||
return void cb(void 0, new Uint8Array(xhr.response));
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
return Util;
|
||||
});
|
||||
|
|
|
@ -71,6 +71,7 @@ define([
|
|||
common.fixFileName = Util.fixFileName;
|
||||
common.bytesToMegabytes = Util.bytesToMegabytes;
|
||||
common.bytesToKilobytes = Util.bytesToKilobytes;
|
||||
common.fetch = Util.fetch;
|
||||
|
||||
// import hash utilities for export
|
||||
var createRandomHash = common.createRandomHash = Hash.createRandomHash;
|
||||
|
|
|
@ -7,6 +7,18 @@ define([
|
|||
var plainChunkLength = 128 * 1024;
|
||||
var cypherChunkLength = 131088;
|
||||
|
||||
var encodePrefix = function (p) {
|
||||
return [
|
||||
65280, // 255 << 8
|
||||
255,
|
||||
].map(function (n, i) {
|
||||
return (p & n) >> ((1 - i) * 8);
|
||||
});
|
||||
};
|
||||
var decodePrefix = function (A) {
|
||||
return (A[0] << 8) | A[1];
|
||||
};
|
||||
|
||||
var slice = function (A) {
|
||||
return Array.prototype.slice.call(A);
|
||||
};
|
||||
|
@ -64,6 +76,7 @@ define([
|
|||
var nonce = createNonce();
|
||||
var i = 0;
|
||||
|
||||
decodePrefix([]); // TODO
|
||||
var takeChunk = function () {
|
||||
var start = i * cypherChunkLength;
|
||||
var end = start + cypherChunkLength;
|
||||
|
@ -126,6 +139,8 @@ define([
|
|||
var encrypt = function (u8, metadata, key) {
|
||||
var nonce = createNonce();
|
||||
|
||||
encodePrefix(); // TODO
|
||||
|
||||
// encode metadata
|
||||
var metaBuffer = Array.prototype.slice
|
||||
.call(Nacl.util.decodeUTF8(JSON.stringify(metadata)));
|
||||
|
|
|
@ -24,16 +24,6 @@ define([
|
|||
|
||||
Cryptpad.addLoadingScreen();
|
||||
|
||||
var fetch = function (src, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", src, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onload = function () {
|
||||
return void cb(void 0, new Uint8Array(xhr.response));
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
var myFile;
|
||||
var myDataType;
|
||||
|
||||
|
@ -78,6 +68,7 @@ define([
|
|||
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
||||
console.log("encrypted blob is now available as %s", uri);
|
||||
|
||||
// TODO use cryptpad-common utilities
|
||||
window.location.hash = [
|
||||
'',
|
||||
2,
|
||||
|
@ -88,6 +79,7 @@ define([
|
|||
|
||||
$form.hide();
|
||||
|
||||
// check if the uploaded file can be decrypted
|
||||
var newU8 = FileCrypto.joinChunks(chunks);
|
||||
FileCrypto.decrypt(newU8, key, function (e, res) {
|
||||
if (e) { return console.error(e); }
|
||||
|
@ -97,7 +89,7 @@ define([
|
|||
|
||||
var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href));
|
||||
APP.updateTitle(title || defaultName);
|
||||
|
||||
Cryptpad.alert("successfully uploaded: " + title);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -212,7 +204,7 @@ define([
|
|||
|
||||
if (!uploadMode) {
|
||||
var src = Cryptpad.getBlobPathFromHex(hexFileName);
|
||||
return fetch(src, function (e, u8) {
|
||||
return Cryptpad.fetch(src, function (e, u8) {
|
||||
// now decrypt the u8
|
||||
if (e) { return window.alert('error'); }
|
||||
var cryptKey = secret.keys && secret.keys.fileKeyStr;
|
||||
|
|
Loading…
Reference in New Issue