tiny-oss 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/vendor/digest.js DELETED
@@ -1,390 +0,0 @@
1
- /*! ***** BEGIN LICENSE BLOCK *****
2
- *!
3
- *! Copyright 2011-2012, 2014 Jean-Christophe Sirot <sirot@chelonix.com>
4
- *!
5
- *! This file is part of digest.js
6
- *!
7
- *! digest.js is free software: you can redistribute it and/or modify it under
8
- *! the terms of the GNU General Public License as published by the Free Software
9
- *! Foundation, either version 3 of the License, or (at your option) any later
10
- *! version.
11
- *!
12
- *! digest.js is distributed in the hope that it will be useful, but
13
- *! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
- *! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
- *! more details.
16
- *!
17
- *! You should have received a copy of the GNU General Public License along with
18
- *! digest.js. If not, see http://www.gnu.org/licenses/.
19
- *!
20
- *! ***** END LICENSE BLOCK ***** */
21
-
22
- /*global ArrayBuffer: true, Uint8Array: true, Uint32Array:true */
23
- /*jslint browser: true, bitwise: true, plusplus: true, vars: true, indent: 4, maxerr: 50 */
24
-
25
-
26
- (function () {
27
- "use strict";
28
- if (!ArrayBuffer.prototype.slice) {
29
- ArrayBuffer.prototype.slice = function (start, end) {
30
- var i;
31
- var that = new Uint8Array(this);
32
- if (end === undefined) {
33
- end = that.length;
34
- }
35
- var result = new ArrayBuffer(end - start);
36
- var resultArray = new Uint8Array(result);
37
- for (i = 0; i < resultArray.length; i++) {
38
- resultArray[i] = that[i + start];
39
- }
40
- return result;
41
- };
42
- }
43
- }());
44
-
45
-
46
- ;(function (global) {
47
- "use strict";
48
-
49
- /* SHA-1 */
50
-
51
- function sha1Engine() {}
52
-
53
- sha1Engine.prototype.processBlock = function (input) {
54
-
55
- var A = this.current[0];
56
- var B = this.current[1];
57
- var C = this.current[2];
58
- var D = this.current[3];
59
- var E = this.current[4];
60
-
61
- var W = [
62
- input[0] << 24 | input[1] << 16 | input[2] << 8 | input[3],
63
- input[4] << 24 | input[5] << 16 | input[6] << 8 | input[7],
64
- input[8] << 24 | input[9] << 16 | input[10] << 8 | input[11],
65
- input[12] << 24 | input[13] << 16 | input[14] << 8 | input[15],
66
- input[16] << 24 | input[17] << 16 | input[18] << 8 | input[19],
67
- input[20] << 24 | input[21] << 16 | input[22] << 8 | input[23],
68
- input[24] << 24 | input[25] << 16 | input[26] << 8 | input[27],
69
- input[28] << 24 | input[29] << 16 | input[30] << 8 | input[31],
70
- input[32] << 24 | input[33] << 16 | input[34] << 8 | input[35],
71
- input[36] << 24 | input[37] << 16 | input[38] << 8 | input[39],
72
- input[40] << 24 | input[41] << 16 | input[42] << 8 | input[43],
73
- input[44] << 24 | input[45] << 16 | input[46] << 8 | input[47],
74
- input[48] << 24 | input[49] << 16 | input[50] << 8 | input[51],
75
- input[52] << 24 | input[53] << 16 | input[54] << 8 | input[55],
76
- input[56] << 24 | input[57] << 16 | input[58] << 8 | input[59],
77
- input[60] << 24 | input[61] << 16 | input[62] << 8 | input[63]
78
- ];
79
- var T;
80
- var i;
81
-
82
- for (i = 16; i < 80; i++) {
83
- W.push((((W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]) << 1) | ((W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]) >>> 31)));
84
- }
85
-
86
- for (i = 0; i < 80; i++) {
87
- T = ((A << 5) | (A >>> 27)) + E + W[i];
88
- if (i < 20) {
89
- T += ((B & C) | (~B & D)) + 0x5A827999 | 0;
90
- } else if (i < 40) {
91
- T += (B ^ C ^ D) + 0x6ED9EBA1 | 0;
92
- } else if (i < 60) {
93
- T += ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC| 0;
94
- } else {
95
- T += (B ^ C ^ D) + 0xCA62C1D6 | 0;
96
- }
97
- E = D;
98
- D = C;
99
- C = ((B << 30) | (B >>> 2));
100
- B = A;
101
- A = T;
102
- }
103
-
104
- this.current[0] += A;
105
- this.current[1] += B;
106
- this.current[2] += C;
107
- this.current[3] += D;
108
- this.current[4] += E;
109
- this.currentLen += 64;
110
- };
111
-
112
- sha1Engine.prototype.doPadding = function () {
113
- var datalen = (this.inLen + this.currentLen) * 8;
114
- var msw = 0; // FIXME
115
- var lsw = datalen & 0xFFFFFFFF;
116
- var zeros = this.inLen <= 55 ? 55 - this.inLen : 119 - this.inLen;
117
- var pad = new Uint8Array(new ArrayBuffer(zeros + 1 + 8));
118
- pad[0] = 0x80;
119
- pad[pad.length - 1] = lsw & 0xFF;
120
- pad[pad.length - 2] = (lsw >>> 8) & 0xFF;
121
- pad[pad.length - 3] = (lsw >>> 16) & 0xFF;
122
- pad[pad.length - 4] = (lsw >>> 24) & 0xFF;
123
- pad[pad.length - 5] = msw & 0xFF;
124
- pad[pad.length - 6] = (msw >>> 8) & 0xFF;
125
- pad[pad.length - 7] = (msw >>> 16) & 0xFF;
126
- pad[pad.length - 8] = (msw >>> 24) & 0xFF;
127
- return pad;
128
- };
129
-
130
- sha1Engine.prototype.getDigest = function () {
131
- var rv = new Uint8Array(new ArrayBuffer(20));
132
- rv[3] = this.current[0] & 0xFF;
133
- rv[2] = (this.current[0] >>> 8) & 0xFF;
134
- rv[1] = (this.current[0] >>> 16) & 0xFF;
135
- rv[0] = (this.current[0] >>> 24) & 0xFF;
136
- rv[7] = this.current[1] & 0xFF;
137
- rv[6] = (this.current[1] >>> 8) & 0xFF;
138
- rv[5] = (this.current[1] >>> 16) & 0xFF;
139
- rv[4] = (this.current[1] >>> 24) & 0xFF;
140
- rv[11] = this.current[2] & 0xFF;
141
- rv[10] = (this.current[2] >>> 8) & 0xFF;
142
- rv[9] = (this.current[2] >>> 16) & 0xFF;
143
- rv[8] = (this.current[2] >>> 24) & 0xFF;
144
- rv[15] = this.current[3] & 0xFF;
145
- rv[14] = (this.current[3] >>> 8) & 0xFF;
146
- rv[13] = (this.current[3] >>> 16) & 0xFF;
147
- rv[12] = (this.current[3] >>> 24) & 0xFF;
148
- rv[19] = this.current[4] & 0xFF;
149
- rv[18] = (this.current[4] >>> 8) & 0xFF;
150
- rv[17] = (this.current[4] >>> 16) & 0xFF;
151
- rv[16] = (this.current[4] >>> 24) & 0xFF;
152
- return rv.buffer;
153
- };
154
-
155
- sha1Engine.prototype.reset = function () {
156
- this.currentLen = 0;
157
- this.inLen = 0;
158
- this.current = new Uint32Array(new ArrayBuffer(20));
159
- this.current[0] = 0x67452301;
160
- this.current[1] = 0xEFCDAB89;
161
- this.current[2] = 0x98BADCFE;
162
- this.current[3] = 0x10325476;
163
- this.current[4] = 0xC3D2E1F0;
164
- };
165
-
166
- sha1Engine.prototype.blockLen = 64;
167
- sha1Engine.prototype.digestLen = 20;
168
-
169
- /* Input utility functions */
170
-
171
- var fromASCII = function (s) {
172
- var buffer = new ArrayBuffer(s.length);
173
- var b = new Uint8Array(buffer);
174
- var i;
175
- for (i = 0; i < s.length; i++) {
176
- b[i] = s.charCodeAt(i);
177
- }
178
- return b;
179
- };
180
-
181
- var fromInteger = function (v) {
182
- var buffer = new ArrayBuffer(1);
183
- var b = new Uint8Array(buffer);
184
- b[0] = v;
185
- return b;
186
- };
187
-
188
- var convertToUint8Array = function (input) {
189
- if (input.constructor === Uint8Array) {
190
- return input;
191
- } else if (input.constructor === ArrayBuffer) {
192
- return new Uint8Array(input);
193
- } else if (input.constructor === String) {
194
- return fromASCII(input);
195
- } else if (input.constructor === Number) {
196
- if (input > 0xFF) {
197
- throw "For more than one byte, use an array buffer";
198
- } else if (input < 0) {
199
- throw "Input value must be positive";
200
- }
201
- return fromInteger(input);
202
- } else {
203
- throw "Unsupported type";
204
- }
205
- };
206
-
207
- var convertToUInt32 = function (i) {
208
- var tmp = new Uint8Array(new ArrayBuffer(4));
209
- tmp[0] = (i & 0xFF000000) >> 24;
210
- tmp[1] = (i & 0x00FF0000) >> 16;
211
- tmp[2] = (i & 0x0000FF00) >> 8;
212
- tmp[3] = (i & 0x000000FF);
213
- return tmp;
214
- };
215
-
216
- /* Digest implementation */
217
- var dg = function (Constructor) {
218
- var update = function (input) {
219
- var len = input.length;
220
- var offset = 0;
221
- while (len > 0) {
222
- var copyLen = this.blockLen - this.inLen;
223
- if (copyLen > len) {
224
- copyLen = len;
225
- }
226
- var tmpInput = input.subarray(offset, offset + copyLen);
227
- this.inbuf.set(tmpInput, this.inLen);
228
- offset += copyLen;
229
- len -= copyLen;
230
- this.inLen += copyLen;
231
- if (this.inLen === this.blockLen) {
232
- //var t0 = performance.now();
233
- this.processBlock(this.inbuf);
234
- //var t1 = performance.now();
235
- //console.log(t1 - t0);
236
- this.inLen = 0;
237
- }
238
- }
239
- };
240
-
241
- var finalize = function () {
242
- var padding = this.doPadding();
243
- this.update(padding);
244
- var result = this.getDigest();
245
- this.reset();
246
- return result;
247
- };
248
-
249
- var engine = (function () {
250
- if (!Constructor) {
251
- throw "Unsupported algorithm: " + Constructor.toString();
252
- }
253
- Constructor.prototype.update = update;
254
- Constructor.prototype.finalize = finalize;
255
- var engine = new Constructor();
256
- engine.inbuf = new Uint8Array(new ArrayBuffer(engine.blockLen));
257
- engine.reset();
258
- return engine;
259
- }());
260
-
261
- return {
262
- update: function (input) {
263
- engine.update(convertToUint8Array(input));
264
- },
265
-
266
- finalize: function () {
267
- return engine.finalize();
268
- },
269
-
270
- digest: function (input) {
271
- engine.update(convertToUint8Array(input));
272
- return engine.finalize();
273
- },
274
-
275
- reset: function () {
276
- engine.reset();
277
- },
278
-
279
- digestLength: function () {
280
- return engine.digestLen;
281
- }
282
- };
283
- };
284
-
285
- /* HMAC implementation */
286
- var hmac = function (digest) {
287
- var initialized = false;
288
- var key, ipad, opad;
289
- var init = function () {
290
- var i, kbuf;
291
- if (initialized) {
292
- return;
293
- }
294
- if (key === undefined) {
295
- throw "MAC key is not defined";
296
- }
297
- if (key.byteLength > 64) { /* B = 64 */
298
- kbuf = new Uint8Array(digest.digest(key));
299
- } else {
300
- kbuf = new Uint8Array(key);
301
- }
302
- ipad = new Uint8Array(new ArrayBuffer(64));
303
- for (i = 0; i < kbuf.length; i++) {
304
- ipad[i] = 0x36 ^ kbuf[i];
305
- }
306
- for (i = kbuf.length; i < 64; i++) {
307
- ipad[i] = 0x36;
308
- }
309
- opad = new Uint8Array(new ArrayBuffer(64));
310
- for (i = 0; i < kbuf.length; i++) {
311
- opad[i] = 0x5c ^ kbuf[i];
312
- }
313
- for (i = kbuf.length; i < 64; i++) {
314
- opad[i] = 0x5c;
315
- }
316
- initialized = true;
317
- digest.update(ipad.buffer);
318
- };
319
-
320
- var resetMac = function () {
321
- initialized = false;
322
- key = undefined;
323
- ipad = undefined;
324
- opad = undefined;
325
- digest.reset();
326
- };
327
-
328
- var finalizeMac = function () {
329
- var result = digest.finalize();
330
- digest.reset();
331
- digest.update(opad.buffer);
332
- digest.update(result);
333
- result = digest.finalize();
334
- resetMac();
335
- return result;
336
- };
337
-
338
- var setKeyMac = function (k) {
339
- key = k;
340
- };
341
-
342
- return {
343
- setKey: function (key) {
344
- setKeyMac(convertToUint8Array(key));
345
- init();
346
- },
347
-
348
- update: function (input) {
349
- digest.update(input);
350
- },
351
-
352
- finalize: function () {
353
- return finalizeMac();
354
- },
355
-
356
- mac: function (input) {
357
- this.update(input);
358
- return this.finalize();
359
- },
360
-
361
- reset: function () {
362
- resetMac();
363
- },
364
-
365
- hmacLength: function () {
366
- return digest.digestLength();
367
- }
368
- };
369
- };
370
-
371
- var Digest = {
372
- SHA1: function () {
373
- return dg(sha1Engine);
374
- },
375
-
376
- HMAC_SHA1: function () {
377
- return hmac(dg(sha1Engine));
378
- }
379
- };
380
-
381
- if ("undefined" !== typeof exports) { /* Node Support */
382
- if (("undefined" !== typeof module) && module.exports) {
383
- module.exports = exports = Digest;
384
- } else {
385
- exports = Digest;
386
- }
387
- } else { /* Browsers and Web Workers*/
388
- global.Digest = Digest;
389
- }
390
- }(this));