UNPKG

2.23 kBJavaScriptView Raw
1;(function (root, factory) {
2 if (typeof exports === "object") {
3 // CommonJS
4 module.exports = exports = factory(require("./core"));
5 }
6 else if (typeof define === "function" && define.amd) {
7 // AMD
8 define(["./core"], factory);
9 }
10 else {
11 // Global (browser)
12 factory(root.CryptoJS);
13 }
14}(this, function (CryptoJS) {
15
16 (function () {
17 // Check if typed arrays are supported
18 if (typeof ArrayBuffer != 'function') {
19 return;
20 }
21
22 // Shortcuts
23 var C = CryptoJS;
24 var C_lib = C.lib;
25 var WordArray = C_lib.WordArray;
26
27 // Reference original init
28 var superInit = WordArray.init;
29
30 // Augment WordArray.init to handle typed arrays
31 var subInit = WordArray.init = function (typedArray) {
32 // Convert buffers to uint8
33 if (typedArray instanceof ArrayBuffer) {
34 typedArray = new Uint8Array(typedArray);
35 }
36
37 // Convert other array views to uint8
38 if (
39 typedArray instanceof Int8Array ||
40 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
41 typedArray instanceof Int16Array ||
42 typedArray instanceof Uint16Array ||
43 typedArray instanceof Int32Array ||
44 typedArray instanceof Uint32Array ||
45 typedArray instanceof Float32Array ||
46 typedArray instanceof Float64Array
47 ) {
48 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
49 }
50
51 // Handle Uint8Array
52 if (typedArray instanceof Uint8Array) {
53 // Shortcut
54 var typedArrayByteLength = typedArray.byteLength;
55
56 // Extract bytes
57 var words = [];
58 for (var i = 0; i < typedArrayByteLength; i++) {
59 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
60 }
61
62 // Initialize this word array
63 superInit.call(this, words, typedArrayByteLength);
64 } else {
65 // Else call normal init
66 superInit.apply(this, arguments);
67 }
68 };
69
70 subInit.prototype = WordArray;
71 }());
72
73
74 return CryptoJS.lib.WordArray;
75
76}));
\No newline at end of file