mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 11:05:47 +05:00
unable to progress(need review)
This commit is contained in:
parent
780d41167d
commit
d6b64d4b5c
@ -62,7 +62,7 @@ img.channelpic {
|
||||
|
||||
.card {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
height: auto;
|
||||
border: 2px solid gray;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
@ -72,8 +72,9 @@ img.channelpic {
|
||||
height: 120px;
|
||||
}
|
||||
.card-title{
|
||||
position: absolute;
|
||||
position: relative;
|
||||
bottom: 0px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/* subject */
|
||||
|
||||
@ -5,79 +5,137 @@ const Data = util.Data;
|
||||
const peopleUtil = require('people/people_util');
|
||||
const sha1 = require('channels/sha1');
|
||||
|
||||
function parseFile(file, callback) {
|
||||
var fileSize = file.size;
|
||||
var chunkSize = 1024 * 1024; // bytes
|
||||
var offset = 0;
|
||||
var self = this; // we need a reference to the current object
|
||||
var chunkReaderBlock = null;
|
||||
var hash = sha1.create();
|
||||
const filesUploadHashes = {
|
||||
// not a good practice, figure out a better way later.
|
||||
PostFiles: [],
|
||||
Thumbnail: [],
|
||||
};
|
||||
|
||||
var readEventHandler = function (evt) {
|
||||
async function parseFile(file, type) {
|
||||
const fileSize = file.size;
|
||||
const chunkSize = 1024 * 1024; // bytes
|
||||
let offset = 0;
|
||||
let chunkReaderBlock = null;
|
||||
const hash = sha1.create();
|
||||
let ans = '';
|
||||
|
||||
const readEventHandler = async function (evt) {
|
||||
if (evt.target.error == null) {
|
||||
offset += evt.target.result.length;
|
||||
// console.log(sha1(evt.target.result)); // callback for handling read chunk
|
||||
hash.update(evt.target.result);
|
||||
await hash.update(evt.target.result);
|
||||
} else {
|
||||
console.log('Read error: ' + evt.target.error);
|
||||
return;
|
||||
}
|
||||
if (offset >= fileSize) {
|
||||
console.log(hash.hex());
|
||||
console.log('Done reading file');
|
||||
ans = await hash.hex();
|
||||
if (type.localeCompare('multiple') === 0) {
|
||||
filesUploadHashes.PostFiles.push(ans);
|
||||
} else {
|
||||
filesUploadHashes.Thumbnail.push(ans);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// of to the next chunk
|
||||
chunkReaderBlock(offset, chunkSize, file);
|
||||
await chunkReaderBlock(offset, chunkSize, file);
|
||||
};
|
||||
|
||||
chunkReaderBlock = function (_offset, length, _file) {
|
||||
var r = new FileReader();
|
||||
var blob = _file.slice(_offset, length + _offset);
|
||||
r.onload = readEventHandler;
|
||||
r.readAsText(blob);
|
||||
chunkReaderBlock = async function (_offset, length, _file) {
|
||||
const reader = new FileReader();
|
||||
const blob = _file.slice(_offset, length + _offset);
|
||||
reader.onload = await readEventHandler;
|
||||
await reader.readAsText(blob);
|
||||
};
|
||||
|
||||
// now let's start the read with the first block
|
||||
chunkReaderBlock(offset, chunkSize, file);
|
||||
// read with the first block
|
||||
await chunkReaderBlock(offset, chunkSize, file);
|
||||
return ans;
|
||||
}
|
||||
|
||||
const AddPost = () => {
|
||||
let content = '';
|
||||
let ptitle = '';
|
||||
const pthumbnail = [];
|
||||
const pfiles = [];
|
||||
let uploadFiles = false;
|
||||
let uploadThumbnail = false;
|
||||
|
||||
return {
|
||||
view: (vnode) =>
|
||||
m('.widget', [
|
||||
m('h3', 'Add Post'),
|
||||
m('hr'),
|
||||
m('label[for=thumbnail]', 'Thumbnail: '),
|
||||
m('input[type=file][name=files][id=thumbnail]', {
|
||||
onchange: (e) => {
|
||||
// sha1(e.target.files);
|
||||
// var hash = sha1.create();
|
||||
// // hash.update(e.target.files);
|
||||
// // hash.hex();
|
||||
// console.log(sha1(e.target.files[0]));
|
||||
// console.log(hash.update(e.target.files[0]));
|
||||
// console.log(hash.hex());
|
||||
// console.log(e.target.files[0]);
|
||||
parseFile(e.target.files[0]);
|
||||
m('input[type=file][name=files][id=thumbnail][accept=image/*]', {
|
||||
onchange: async (e) => {
|
||||
filesUploadHashes.Thumbnail = [];
|
||||
await parseFile(e.target.files[0], '');
|
||||
console.log(filesUploadHashes.Thumbnail, filesUploadHashes.Thumbnail.length);
|
||||
|
||||
if (filesUploadHashes.Thumbnail.length === e.target.files.length) {
|
||||
pthumbnail.push({
|
||||
name: e.target.files[0].name,
|
||||
size: e.target.files[0].size,
|
||||
hash: filesUploadHashes.Thumbnail[0],
|
||||
});
|
||||
uploadThumbnail = true;
|
||||
}
|
||||
},
|
||||
}),
|
||||
m('label[for=browse]', 'Attachments: '),
|
||||
m('input[type=file][name=files][id=browse][multiple=multiple]', {
|
||||
onchange: (e) => {
|
||||
console.log(e.target.files);
|
||||
onchange: async (e) => {
|
||||
filesUploadHashes.PostFiles = [];
|
||||
for (let i = 0; i < e.target.files.length; i++) {
|
||||
await parseFile(e.target.files[i], 'multiple');
|
||||
}
|
||||
console.log(filesUploadHashes.PostFiles, filesUploadHashes.PostFiles.length);
|
||||
|
||||
if (filesUploadHashes.PostFiles.length === e.target.files.length) {
|
||||
for (let i = 0; i < e.target.files.length; i++) {
|
||||
pfiles.push({
|
||||
name: e.target.files[i].name,
|
||||
size: e.target.files[i].size,
|
||||
hash: filesUploadHashes.PostFiles[i],
|
||||
});
|
||||
}
|
||||
uploadFiles = true;
|
||||
}
|
||||
},
|
||||
}),
|
||||
m('input[type=text][placeholder=Title]', {
|
||||
oninput: (e) => console.log(e.target.value),
|
||||
oninput: (e) => (ptitle = e.target.value),
|
||||
}),
|
||||
m('textarea[rows=5][style="width: 90%; display: block;"]', {
|
||||
oninput: (e) => (content = e.target.value),
|
||||
value: content,
|
||||
}),
|
||||
m('button', {}, 'Add'),
|
||||
m(
|
||||
'button',
|
||||
{
|
||||
onclick: async () => {
|
||||
if (uploadFiles && uploadThumbnail) {
|
||||
console.log(vnode.attrs.chanId, ptitle, content, pfiles, pthumbnail);
|
||||
// const res = await rs.rsJsonApiRequest('/rsgxschannels/createPostV2', {
|
||||
// channelId: vnode.attrs.chanId,
|
||||
// title: ptitle,
|
||||
// mBody: content,
|
||||
// files: pfiles,
|
||||
// thumbnail: pthumbnail,
|
||||
// });
|
||||
// res.body.retval === false
|
||||
// ? util.popupMessage([m('h3', 'Error'), m('hr'), m('p', res.body.errorMessage)])
|
||||
// : util.popupMessage([
|
||||
// m('h3', 'Success'),
|
||||
// m('hr'),
|
||||
// m('p', 'Post added successfully'),
|
||||
// ]);
|
||||
}
|
||||
},
|
||||
},
|
||||
'Add'
|
||||
),
|
||||
]),
|
||||
};
|
||||
};
|
||||
@ -177,7 +235,11 @@ const ChannelView = () => {
|
||||
style: 'display:' + (csubscribed ? 'block' : 'none'),
|
||||
},
|
||||
m('h3', 'Posts'),
|
||||
m('button', { onclick: () => util.popupMessage(m(AddPost)) }, 'Add Post'),
|
||||
m(
|
||||
'button',
|
||||
{ onclick: () => util.popupMessage(m(AddPost, { chanId: v.attrs.id })) },
|
||||
'Add Post'
|
||||
),
|
||||
m('hr'),
|
||||
|
||||
m(
|
||||
@ -270,22 +332,23 @@ const AddComment = () => {
|
||||
};
|
||||
|
||||
function DisplayComment(comment, identity) {
|
||||
let showReplies = false;
|
||||
return {
|
||||
showReplies: false,
|
||||
oninit: (v) => {
|
||||
console.log(comment.mComment);
|
||||
if (Data.ParentCommentMap[comment.mMeta.mMsgId]) {
|
||||
Data.ParentCommentMap[comment.mMeta.mMsgId].forEach((value) => console.log(value));
|
||||
}
|
||||
console.log(v.state.showReplies);
|
||||
// console.log(comment.mComment, v.state.showReplies);
|
||||
// if (Data.ParentCommentMap[comment.mMeta.mMsgId]) {
|
||||
// Data.ParentCommentMap[comment.mMeta.mMsgId].forEach((value) => console.log(value));
|
||||
// }
|
||||
},
|
||||
view: (v) => [
|
||||
m('tr', [
|
||||
m('i.fas.fa-angle-right', {
|
||||
class: 'fa-rotate-' + (showReplies ? '90' : '0'),
|
||||
class: 'fa-rotate-' + (v.state.showReplies ? '90' : '0'),
|
||||
style: 'margin-top:12px',
|
||||
onclick: () => {
|
||||
showReplies = !showReplies;
|
||||
console.log(showReplies);
|
||||
v.state.showReplies = !v.state.showReplies;
|
||||
console.log(v.state.showReplies);
|
||||
},
|
||||
}),
|
||||
|
||||
@ -343,14 +406,14 @@ function DisplayComment(comment, identity) {
|
||||
m('td', comment.mUpVotes),
|
||||
m('td', comment.mDownVotes),
|
||||
]),
|
||||
showReplies
|
||||
v.state.showReplies
|
||||
? Data.ParentCommentMap[comment.mMeta.mMsgId]
|
||||
? Data.ParentCommentMap[comment.mMeta.mMsgId].forEach(
|
||||
(value) => m(DisplayComment(value, identity))
|
||||
// console.log(value)
|
||||
// (value) => m(DisplayComment(value, identity))
|
||||
(value) => console.log(value)
|
||||
)
|
||||
: 'undef'
|
||||
: 'toggle',
|
||||
: ''
|
||||
: '',
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,52 +6,53 @@
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
*/
|
||||
/*jslint bitwise: true */
|
||||
/* jslint bitwise: true */
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var root = typeof window === 'object' ? window : {};
|
||||
var NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||
|
||||
let root = typeof window === 'object' ? window : {};
|
||||
const NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object';
|
||||
if (NODE_JS) {
|
||||
root = global;
|
||||
}
|
||||
var COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
var AMD = typeof define === 'function' && define.amd;
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
||||
var SHIFT = [24, 16, 8, 0];
|
||||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
||||
|
||||
var blocks = [];
|
||||
|
||||
var createOutputMethod = function (outputType) {
|
||||
const COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
// const AMD = typeof define === 'function' && define.amd;
|
||||
const HEX_CHARS = '0123456789abcdef'.split('');
|
||||
const EXTRA = [-2147483648, 8388608, 32768, 128];
|
||||
const SHIFT = [24, 16, 8, 0];
|
||||
const OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
||||
|
||||
const blocks = [];
|
||||
function Sha1(sharedMemory) {
|
||||
if (sharedMemory) {
|
||||
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
this.blocks = blocks;
|
||||
} else {
|
||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
}
|
||||
|
||||
this.h0 = 0x67452301;
|
||||
this.h1 = 0xEFCDAB89;
|
||||
this.h2 = 0x98BADCFE;
|
||||
this.h3 = 0x10325476;
|
||||
this.h4 = 0xC3D2E1F0;
|
||||
|
||||
this.block = this.start = this.bytes = this.hBytes = 0;
|
||||
this.finalized = this.hashed = false;
|
||||
this.first = true;
|
||||
}
|
||||
const createOutputMethod = function (outputType) {
|
||||
return function (message) {
|
||||
return new Sha1(true).update(message)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createMethod = function () {
|
||||
var method = createOutputMethod('hex');
|
||||
if (NODE_JS) {
|
||||
method = nodeWrap(method);
|
||||
}
|
||||
method.create = function () {
|
||||
return new Sha1();
|
||||
};
|
||||
method.update = function (message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createOutputMethod(type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var nodeWrap = function (method) {
|
||||
var crypto = eval("require('crypto')");
|
||||
var Buffer = eval("require('buffer').Buffer");
|
||||
var nodeMethod = function (message) {
|
||||
const nodeWrap = function (method) {
|
||||
const crypto = eval('require(\'crypto\')');
|
||||
const Buffer = eval('require(\'buffer\').Buffer');
|
||||
const nodeMethod = function (message) {
|
||||
if (typeof message === 'string') {
|
||||
return crypto.createHash('sha1').update(message, 'utf8').digest('hex');
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
@ -63,39 +64,36 @@
|
||||
};
|
||||
return nodeMethod;
|
||||
};
|
||||
|
||||
function Sha1(sharedMemory) {
|
||||
if (sharedMemory) {
|
||||
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
|
||||
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
this.blocks = blocks;
|
||||
} else {
|
||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
const createMethod = function () {
|
||||
let method = createOutputMethod('hex');
|
||||
if (NODE_JS) {
|
||||
method = nodeWrap(method);
|
||||
}
|
||||
|
||||
this.h0 = 0x67452301;
|
||||
this.h1 = 0xEFCDAB89;
|
||||
this.h2 = 0x98BADCFE;
|
||||
this.h3 = 0x10325476;
|
||||
this.h4 = 0xC3D2E1F0;
|
||||
|
||||
this.block = this.start = this.bytes = this.hBytes = 0;
|
||||
this.finalized = this.hashed = false;
|
||||
this.first = true;
|
||||
}
|
||||
|
||||
method.create = function () {
|
||||
return new Sha1();
|
||||
};
|
||||
method.update = function (message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
for (let i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||
const type = OUTPUT_TYPES[i];
|
||||
method[type] = createOutputMethod(type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
var notString = typeof(message) !== 'string';
|
||||
const notString = typeof(message) !== 'string';
|
||||
if (notString && message.constructor === root.ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
||||
|
||||
let code, index = 0, i;
|
||||
const length = message.length || 0, blocks = this.blocks;
|
||||
|
||||
while (index < length) {
|
||||
if (this.hashed) {
|
||||
this.hashed = false;
|
||||
@ -105,7 +103,7 @@
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
|
||||
|
||||
if(notString) {
|
||||
for (i = this.start; index < length && i < 64; ++index) {
|
||||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||
@ -131,7 +129,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.lastByteIndex = i;
|
||||
this.bytes += i - this.start;
|
||||
if (i >= 64) {
|
||||
@ -149,13 +147,13 @@
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.finalize = function () {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
this.finalized = true;
|
||||
var blocks = this.blocks, i = this.lastByteIndex;
|
||||
const blocks = this.blocks, i = this.lastByteIndex;
|
||||
blocks[16] = this.block;
|
||||
blocks[i >> 2] |= EXTRA[i & 3];
|
||||
this.block = blocks[16];
|
||||
@ -173,136 +171,137 @@
|
||||
blocks[15] = this.bytes << 3;
|
||||
this.hash();
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.hash = function () {
|
||||
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4;
|
||||
var f, j, t, blocks = this.blocks;
|
||||
|
||||
let a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4;
|
||||
let f, j, t;
|
||||
const blocks = this.blocks;
|
||||
|
||||
for(j = 16; j < 80; ++j) {
|
||||
t = blocks[j - 3] ^ blocks[j - 8] ^ blocks[j - 14] ^ blocks[j - 16];
|
||||
blocks[j] = (t << 1) | (t >>> 31);
|
||||
}
|
||||
|
||||
|
||||
for(j = 0; j < 20; j += 5) {
|
||||
f = (b & c) | ((~b) & d);
|
||||
t = (a << 5) | (a >>> 27);
|
||||
e = t + f + e + 1518500249 + blocks[j] << 0;
|
||||
b = (b << 30) | (b >>> 2);
|
||||
|
||||
|
||||
f = (a & b) | ((~a) & c);
|
||||
t = (e << 5) | (e >>> 27);
|
||||
d = t + f + d + 1518500249 + blocks[j + 1] << 0;
|
||||
a = (a << 30) | (a >>> 2);
|
||||
|
||||
|
||||
f = (e & a) | ((~e) & b);
|
||||
t = (d << 5) | (d >>> 27);
|
||||
c = t + f + c + 1518500249 + blocks[j + 2] << 0;
|
||||
e = (e << 30) | (e >>> 2);
|
||||
|
||||
|
||||
f = (d & e) | ((~d) & a);
|
||||
t = (c << 5) | (c >>> 27);
|
||||
b = t + f + b + 1518500249 + blocks[j + 3] << 0;
|
||||
d = (d << 30) | (d >>> 2);
|
||||
|
||||
|
||||
f = (c & d) | ((~c) & e);
|
||||
t = (b << 5) | (b >>> 27);
|
||||
a = t + f + a + 1518500249 + blocks[j + 4] << 0;
|
||||
c = (c << 30) | (c >>> 2);
|
||||
}
|
||||
|
||||
|
||||
for(; j < 40; j += 5) {
|
||||
f = b ^ c ^ d;
|
||||
t = (a << 5) | (a >>> 27);
|
||||
e = t + f + e + 1859775393 + blocks[j] << 0;
|
||||
b = (b << 30) | (b >>> 2);
|
||||
|
||||
|
||||
f = a ^ b ^ c;
|
||||
t = (e << 5) | (e >>> 27);
|
||||
d = t + f + d + 1859775393 + blocks[j + 1] << 0;
|
||||
a = (a << 30) | (a >>> 2);
|
||||
|
||||
|
||||
f = e ^ a ^ b;
|
||||
t = (d << 5) | (d >>> 27);
|
||||
c = t + f + c + 1859775393 + blocks[j + 2] << 0;
|
||||
e = (e << 30) | (e >>> 2);
|
||||
|
||||
|
||||
f = d ^ e ^ a;
|
||||
t = (c << 5) | (c >>> 27);
|
||||
b = t + f + b + 1859775393 + blocks[j + 3] << 0;
|
||||
d = (d << 30) | (d >>> 2);
|
||||
|
||||
|
||||
f = c ^ d ^ e;
|
||||
t = (b << 5) | (b >>> 27);
|
||||
a = t + f + a + 1859775393 + blocks[j + 4] << 0;
|
||||
c = (c << 30) | (c >>> 2);
|
||||
}
|
||||
|
||||
|
||||
for(; j < 60; j += 5) {
|
||||
f = (b & c) | (b & d) | (c & d);
|
||||
t = (a << 5) | (a >>> 27);
|
||||
e = t + f + e - 1894007588 + blocks[j] << 0;
|
||||
b = (b << 30) | (b >>> 2);
|
||||
|
||||
|
||||
f = (a & b) | (a & c) | (b & c);
|
||||
t = (e << 5) | (e >>> 27);
|
||||
d = t + f + d - 1894007588 + blocks[j + 1] << 0;
|
||||
a = (a << 30) | (a >>> 2);
|
||||
|
||||
|
||||
f = (e & a) | (e & b) | (a & b);
|
||||
t = (d << 5) | (d >>> 27);
|
||||
c = t + f + c - 1894007588 + blocks[j + 2] << 0;
|
||||
e = (e << 30) | (e >>> 2);
|
||||
|
||||
|
||||
f = (d & e) | (d & a) | (e & a);
|
||||
t = (c << 5) | (c >>> 27);
|
||||
b = t + f + b - 1894007588 + blocks[j + 3] << 0;
|
||||
d = (d << 30) | (d >>> 2);
|
||||
|
||||
|
||||
f = (c & d) | (c & e) | (d & e);
|
||||
t = (b << 5) | (b >>> 27);
|
||||
a = t + f + a - 1894007588 + blocks[j + 4] << 0;
|
||||
c = (c << 30) | (c >>> 2);
|
||||
}
|
||||
|
||||
|
||||
for(; j < 80; j += 5) {
|
||||
f = b ^ c ^ d;
|
||||
t = (a << 5) | (a >>> 27);
|
||||
e = t + f + e - 899497514 + blocks[j] << 0;
|
||||
b = (b << 30) | (b >>> 2);
|
||||
|
||||
|
||||
f = a ^ b ^ c;
|
||||
t = (e << 5) | (e >>> 27);
|
||||
d = t + f + d - 899497514 + blocks[j + 1] << 0;
|
||||
a = (a << 30) | (a >>> 2);
|
||||
|
||||
|
||||
f = e ^ a ^ b;
|
||||
t = (d << 5) | (d >>> 27);
|
||||
c = t + f + c - 899497514 + blocks[j + 2] << 0;
|
||||
e = (e << 30) | (e >>> 2);
|
||||
|
||||
|
||||
f = d ^ e ^ a;
|
||||
t = (c << 5) | (c >>> 27);
|
||||
b = t + f + b - 899497514 + blocks[j + 3] << 0;
|
||||
d = (d << 30) | (d >>> 2);
|
||||
|
||||
|
||||
f = c ^ d ^ e;
|
||||
t = (b << 5) | (b >>> 27);
|
||||
a = t + f + a - 899497514 + blocks[j + 4] << 0;
|
||||
c = (c << 30) | (c >>> 2);
|
||||
}
|
||||
|
||||
|
||||
this.h0 = this.h0 + a << 0;
|
||||
this.h1 = this.h1 + b << 0;
|
||||
this.h2 = this.h2 + c << 0;
|
||||
this.h3 = this.h3 + d << 0;
|
||||
this.h4 = this.h4 + e << 0;
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.hex = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
|
||||
|
||||
|
||||
const h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
|
||||
|
||||
return HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
|
||||
@ -324,14 +323,14 @@
|
||||
HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F];
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.toString = Sha1.prototype.hex;
|
||||
|
||||
|
||||
Sha1.prototype.digest = function () {
|
||||
this.finalize();
|
||||
|
||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
|
||||
|
||||
|
||||
const h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
|
||||
|
||||
return [
|
||||
(h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
|
||||
(h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
|
||||
@ -340,14 +339,14 @@
|
||||
(h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
Sha1.prototype.array = Sha1.prototype.digest;
|
||||
|
||||
|
||||
Sha1.prototype.arrayBuffer = function () {
|
||||
this.finalize();
|
||||
|
||||
var buffer = new ArrayBuffer(20);
|
||||
var dataView = new DataView(buffer);
|
||||
|
||||
const buffer = new ArrayBuffer(20);
|
||||
const dataView = new DataView(buffer);
|
||||
dataView.setUint32(0, this.h0);
|
||||
dataView.setUint32(4, this.h1);
|
||||
dataView.setUint32(8, this.h2);
|
||||
@ -355,17 +354,17 @@
|
||||
dataView.setUint32(16, this.h4);
|
||||
return buffer;
|
||||
};
|
||||
|
||||
var exports = createMethod();
|
||||
|
||||
|
||||
const exports = createMethod();
|
||||
|
||||
if (COMMON_JS) {
|
||||
module.exports = exports;
|
||||
} else {
|
||||
root.sha1 = exports;
|
||||
if (AMD) {
|
||||
define(function () {
|
||||
return exports;
|
||||
});
|
||||
}
|
||||
// if (AMD) {
|
||||
// define(function () {
|
||||
// return exports;
|
||||
// });
|
||||
// }
|
||||
}
|
||||
})();
|
||||
})();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user