You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
52 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{"version":3,"sources":["node_modules/text-encoding-utf-8/lib/encoding.lib.mjs","node_modules/matrix-react-sdk/lib/utils/MegolmExportEncryption.js"],"names":["inRange","a","min","max","ToDictionary","o","undefined","Object","TypeError","__webpack_require__","r","__webpack_exports__","d","TextEncoder","TextDecoder","end_of_stream","Stream","tokens","this","slice","call","prototype","endOfStream","length","read","shift","prepend","token","Array","isArray","unshift","pop","push","finished","decoderError","fatal","opt_code_point","DEFAULT_ENCODING","encoding","options","String","toLowerCase","Error","_streaming","_BOMseen","_decoder","_fatal","Boolean","_ignoreBOM","defineProperty","value","_encoder","_options","UTF8Decoder","utf8_code_point","utf8_bytes_seen","utf8_bytes_needed","utf8_lower_boundary","utf8_upper_boundary","handler","stream","bite","code_point","UTF8Encoder","count","offset","bytes","temp","decode","input","ArrayBuffer","Uint8Array","buffer","byteOffset","byteLength","result","input_stream","code_points","apply","indexOf","s","i","cp","fromCharCode","codePointsToString","encode","opt_string","string","n","u","c","charCodeAt","b","stringToCodePoints","exports","encryptMegolmKeyFile","decryptMegolmKeyFile","_ref","_ref4","_ref7","_promise2","_interopRequireDefault","_regenerator2","_slicedToArray3","_bluebird","deriveKeys","coroutine","default","mark","_callee","data","password","body","ciphertextLength","salt","iv","iterations","ciphertext","hmac","_ref2","_ref3","aesKey","hmacKey","toVerify","isValid","plaintext","wrap","_context","prev","next","unpackMegolmKeyFile","friendlyError","_languageHandler","_t","subarray","resolve","sent","subtleCrypto","verify","name","t0","cryptoFailMsg","decrypt","counter","t1","abrupt","stop","_x","_x2","arguments","_callee2","kdfRounds","_ref5","_ref6","encodedData","cipherArray","bodyLength","resultBuffer","idx","toSign","hmacArray","_context2","kdf_rounds","window","crypto","getRandomValues","encrypt","set","sign","packMegolmKeyFile","_x3","_x4","_x5","_callee3","start","key","keybits","now","aesProm","hmacProm","_context3","Date","importKey","deriveBits","hash","console","log","catch","e","all","_x6","_x7","_x8","TextEncodingUtf8","obj","__esModule","newObj","hasOwnProperty","_interopRequireWildcard","subtle","webkitSubtle","msg","friendlyText","HEADER_LINE","TRAILER_LINE","fileStr","lineStart","lineEnd","line","trim","dataStart","_lineEnd","dataEnd","base64","latin1String","atob","uint8Array","decodeBase64","nLines","Math","ceil","lines","btoa","join"],"mappings":"0FAeA,SAAAA,EAAAC,EAAAC,EAAAC,GACA,OAAAD,GAAAD,MAAAE,EAOA,SAAAC,EAAAC,GACA,QAAAC,IAAAD,EAAA,SACA,GAAAA,IAAAE,OAAAF,GAAA,OAAAA,EACA,MAAAG,UAAA,4CA1BAC,EAAAC,EAAAC,GAAAF,EAAAG,EAAAD,EAAA,gCAAAE,IAAAJ,EAAAG,EAAAD,EAAA,gCAAAG,IAiJA,IAAAC,GAAA,EASA,SAAAC,EAAAC,GAEAC,KAAAD,OAAA,GAAAE,MAAAC,KAAAH,GAGAD,EAAAK,UAAA,CAIAC,YAAA,WACA,OAAAJ,KAAAD,OAAAM,QAWAC,KAAA,WACA,OAAAN,KAAAD,OAAAM,OAEAL,KAAAD,OAAAQ,QADAV,GAWAW,QAAA,SAAAC,GACA,GAAAC,MAAAC,QAAAF,GAEA,IADA,IAAAV,EAA6C,EAC7CA,EAAAM,QACAL,KAAAD,OAAAa,QAAAb,EAAAc,YAEAb,KAAAD,OAAAa,QAAAH,IAWAK,KAAA,SAAAL,GACA,GAAAC,MAAAC,QAAAF,GAEA,IADA,IAAAV,EAA6C,EAC7CA,EAAAM,QACAL,KAAAD,OAAAe,KAAAf,EAAAQ,cAEAP,KAAAD,OAAAe,KAAAL,KAYA,IAAAM,GAAA,EAOA,SAAAC,EAAAC,EAAAC,GACA,GAAAD,EACA,MAAA3B,UAAA,iBACA,OAAA4B,GAAA,MA+BA,IAAAC,EAAA,QAUA,SAAA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MAAA,KAAA0I,GAEArD,OAAA2D,KAAAR,IAjBAjN,GARA,GAYA,OAFAwN,EAAA5I,KAAA2H,EACAiB,EAAA5I,GAAA,IACA,IAAApE,GAAAwE,OAAAwI,EAAAE,KAAA,OAAAvJ","file":"bundles/e9b8313cd5591059cfdc/2.js","sourcesContent":["'use strict';\n\n// This is free and unencumbered software released into the public domain.\n// See LICENSE.md for more information.\n\n//\n// Utilities\n//\n\n/**\n * @param {number} a The number to test.\n * @param {number} min The minimum value in the range, inclusive.\n * @param {number} max The maximum value in the range, inclusive.\n * @return {boolean} True if a >= min and a <= max.\n */\nfunction inRange(a, min, max) {\n return min <= a && a <= max;\n}\n\n/**\n * @param {*} o\n * @return {Object}\n */\nfunction ToDictionary(o) {\n if (o === undefined) return {};\n if (o === Object(o)) return o;\n throw TypeError('Could not convert argument to dictionary');\n}\n\n/**\n * @param {string} string Input string of UTF-16 code units.\n * @return {!Array.<number>} Code points.\n */\nfunction stringToCodePoints(string) {\n // https://heycam.github.io/webidl/#dfn-obtain-unicode\n\n // 1. Let S be the DOMString value.\n var s = String(string);\n\n // 2. Let n be the length of S.\n var n = s.length;\n\n // 3. Initialize i to 0.\n var i = 0;\n\n // 4. Initialize U to be an empty sequence of Unicode characters.\n var u = [];\n\n // 5. While i < n:\n while (i < n) {\n\n // 1. Let c be the code unit in S at index i.\n var c = s.charCodeAt(i);\n\n // 2. Depending on the value of c:\n\n // c < 0xD800 or c > 0xDFFF\n if (c < 0xD800 || c > 0xDFFF) {\n // Append to U the Unicode character with code point c.\n u.push(c);\n }\n\n // 0xDC00 ≤ c ≤ 0xDFFF\n else if (0xDC00 <= c && c <= 0xDFFF) {\n // Append to U a U+FFFD REPLACEMENT CHARACTER.\n u.push(0xFFFD);\n }\n\n // 0xD800 ≤ c ≤ 0xDBFF\n else if (0xD800 <= c && c <= 0xDBFF) {\n // 1. If i = n1, then append to U a U+FFFD REPLACEMENT\n // CHARACTER.\n if (i === n - 1) {\n u.push(0xFFFD);\n }\n // 2. Otherwise, i < n1:\n else {\n // 1. Let d be the code unit in S at index i+1.\n var d = string.charCodeAt(i + 1);\n\n // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:\n if (0xDC00 <= d && d <= 0xDFFF) {\n // 1. Let a be c & 0x3FF.\n var a = c & 0x3FF;\n\n // 2. Let b be d & 0x3FF.\n var b = d & 0x3FF;\n\n // 3. Append to U the Unicode character with code point\n // 2^16+2^10*a+b.\n u.push(0x10000 + (a << 10) + b);\n\n // 4. Set i to i+1.\n i += 1;\n }\n\n // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a\n // U+FFFD REPLACEMENT CHARACTER.\n else {\n u.push(0xFFFD);\n }\n }\n }\n\n // 3. Set i to i+1.\n i += 1;\n }\n\n // 6. Return U.\n return u;\n}\n\n/**\n * @param {!Array.<number>} code_points Array of code points.\n * @return {string} string String of UTF-16 code units.\n */\nfunction codePointsToString(code_points) {\n var s = '';\n for (var i = 0; i < code_points.length; ++i) {\n var cp = code_points[i];\n if (cp <= 0xFFFF) {\n s += String.fromCharCode(cp);\n } else {\n cp -= 0x10000;\n s += String.fromCharCode((cp >> 10) + 0xD800,\n (cp & 0x3FF) + 0xDC00);\n }\n }\n return s;\n}\n\n\n//\n// Implementation of Encoding specification\n// https://encoding.spec.whatwg.org/\n//\n\n//\n// 3. Terminology\n//\n\n/**\n * End-of-stream is a special token that signifies no more tokens\n * are in the stream.\n * @const\n */ var end_of_stream = -1;\n\n/**\n * A stream represents an ordered sequence of tokens.\n *\n * @constructor\n * @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide the\n * stream.\n */\nfunction Stream(tokens) {\n /** @type {!Array.<number>} */\n this.tokens = [].slice.call(tokens);\n}\n\nStream.prototype = {\n /**\n * @return {boolean} True if end-of-stream has been hit.\n */\n endOfStream: function() {\n return !this.tokens.length;\n },\n\n /**\n * When a token is read from a stream, the first token in the\n * stream must be returned and subsequently removed, and\n * end-of-stream must be returned otherwise.\n *\n * @return {number} Get the next token from the stream, or\n * end_of_stream.\n */\n read: function() {\n if (!this.tokens.length)\n return end_of_stream;\n return this.tokens.shift();\n },\n\n /**\n * When one or more tokens are prepended to a stream, those tokens\n * must be inserted, in given order, before the first token in the\n * stream.\n *\n * @param {(number|!Array.<number>)} token The token(s) to prepend to the stream.\n */\n prepend: function(token) {\n if (Array.isArray(token)) {\n var tokens = /**@type {!Array.<number>}*/(token);\n while (tokens.length)\n this.tokens.unshift(tokens.pop());\n } else {\n this.tokens.unshift(token);\n }\n },\n\n /**\n * When one or more tokens are pushed to a stream, those tokens\n * must be inserted, in given order, after the last token in the\n * stream.\n *\n * @param {(number|!Array.<number>)} token The tokens(s) to prepend to the stream.\n */\n push: function(token) {\n if (Array.isArray(token)) {\n var tokens = /**@type {!Array.<number>}*/(token);\n while (tokens.length)\n this.tokens.push(tokens.shift());\n } else {\n this.tokens.push(token);\n }\n }\n};\n\n//\n// 4. Encodings\n//\n\n// 4.1 Encoders and decoders\n\n/** @const */\nvar finished = -1;\n\n/**\n * @param {boolean} fatal If true, decoding errors raise an exception.\n * @param {number=} opt_code_point Override the standard fallback code point.\n * @return {number} The code point to insert on a decoding error.\n */\nfunction decoderError(fatal, opt_code_point) {\n if (fatal)\n throw TypeError('Decoder error');\n return opt_code_point || 0xFFFD;\n}\n\n/** @interface */\nfunction Decoder() {}\nDecoder.prototype = {\n /**\n * @param {Stream} stream The stream of bytes being decoded.\n * @param {number} bite The next byte read from the stream.\n * @return {?(number|!Array.<number>)} The next code point(s)\n * decoded, or null if not enough data exists in the input\n * stream to decode a complete code point, or |finished|.\n */\n handler: function(stream, bite) {}\n};\n\n/** @interface */\nfunction Encoder() {}\nEncoder.prototype = {\n /**\n * @param {Stream} stream The stream of code points being encoded.\n * @param {number} code_point Next code point read from the stream.\n * @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.\n */\n handler: function(stream, code_point) {}\n};\n\n//\n// 7. API\n//\n\n/** @const */ var DEFAULT_ENCODING = 'utf-8';\n\n// 7.1 Interface TextDecoder\n\n/**\n * @constructor\n * @param {string=} encoding The label of the encoding;\n * defaults to 'utf-8'.\n * @param {Object=} options\n */\nfunction TextDecoder(encoding, options) {\n if (!(this instanceof TextDecoder)) {\n return new TextDecoder(encoding, options);\n }\n encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;\n if (encoding !== DEFAULT_ENCODING) {\n throw new Error('Encoding not supported. Only utf-8 is supported');\n }\n options = ToDictionary(options);\n\n /** @private @type {boolean} */\n this._streaming = false;\n /** @private @type {boolean} */\n this._BOMseen = false;\n /** @private @type {?Decoder} */\n this._decoder = null;\n /** @private @type {boolean} */\n this._fatal = Boolean(options['fatal']);\n /** @private @type {boolean} */\n this._ignoreBOM = Boolean(options['ignoreBOM']);\n\n Object.defineProperty(this, 'encoding', {value: 'utf-8'});\n Object.defineProperty(this, 'fatal', {value: this._fatal});\n Object.defineProperty(this, 'ignoreBOM', {value: this._ignoreBOM});\n}\n\nTextDecoder.prototype = {\n /**\n * @param {ArrayBufferView=} input The buffer of bytes to decode.\n * @param {Object=} options\n * @return {string} The decoded string.\n */\n decode: function decode(input, options) {\n var bytes;\n if (typeof input === 'object' && input instanceof ArrayBuffer) {\n bytes = new Uint8Array(input);\n } else if (typeof input === 'object' && 'buffer' in input &&\n input.buffer instanceof ArrayBuffer) {\n bytes = new Uint8Array(input.buffer,\n input.byteOffset,\n input.byteLength);\n } else {\n bytes = new Uint8Array(0);\n }\n\n options = ToDictionary(options);\n\n if (!this._streaming) {\n this._decoder = new UTF8Decoder({fatal: this._fatal});\n this._BOMseen = false;\n }\n this._streaming = Boolean(options['stream']);\n\n var input_stream = new Stream(bytes);\n\n var code_points = [];\n\n /** @type {?(number|!Array.<number>)} */\n var result;\n\n while (!input_stream.endOfStream()) {\n result = this._decoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (result === null)\n continue;\n if (Array.isArray(result))\n code_points.push.apply(code_points, /**@type {!Array.<number>}*/(result));\n else\n code_points.push(result);\n }\n if (!this._streaming) {\n do {\n result = this._decoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (result === null)\n continue;\n if (Array.isArray(result))\n code_points.push.apply(code_points, /**@type {!Array.<number>}*/(result));\n else\n code_points.push(result);\n } while (!input_stream.endOfStream());\n this._decoder = null;\n }\n\n if (code_points.length) {\n // If encoding is one of utf-8, utf-16be, and utf-16le, and\n // ignore BOM flag and BOM seen flag are unset, run these\n // subsubsteps:\n if (['utf-8'].indexOf(this.encoding) !== -1 &&\n !this._ignoreBOM && !this._BOMseen) {\n // If token is U+FEFF, set BOM seen flag.\n if (code_points[0] === 0xFEFF) {\n this._BOMseen = true;\n code_points.shift();\n } else {\n // Otherwise, if token is not end-of-stream, set BOM seen\n // flag and append token to output.\n this._BOMseen = true;\n }\n }\n }\n\n return codePointsToString(code_points);\n }\n};\n\n// 7.2 Interface TextEncoder\n\n/**\n * @constructor\n * @param {string=} encoding The label of the encoding;\n * defaults to 'utf-8'.\n * @param {Object=} options\n */\nfunction TextEncoder(encoding, options) {\n if (!(this instanceof TextEncoder))\n return new TextEncoder(encoding, options);\n encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;\n if (encoding !== DEFAULT_ENCODING) {\n throw new Error('Encoding not supported. Only utf-8 is supported');\n }\n options = ToDictionary(options);\n\n /** @private @type {boolean} */\n this._streaming = false;\n /** @private @type {?Encoder} */\n this._encoder = null;\n /** @private @type {{fatal: boolean}} */\n this._options = {fatal: Boolean(options['fatal'])};\n\n Object.defineProperty(this, 'encoding', {value: 'utf-8'});\n}\n\nTextEncoder.prototype = {\n /**\n * @param {string=} opt_string The string to encode.\n * @param {Object=} options\n * @return {Uint8Array} Encoded bytes, as a Uint8Array.\n */\n encode: function encode(opt_string, options) {\n opt_string = opt_string ? String(opt_string) : '';\n options = ToDictionary(options);\n\n // NOTE: This option is nonstandard. None of the encodings\n // permitted for encoding (i.e. UTF-8, UTF-16) are stateful,\n // so streaming is not necessary.\n if (!this._streaming)\n this._encoder = new UTF8Encoder(this._options);\n this._streaming = Boolean(options['stream']);\n\n var bytes = [];\n var input_stream = new Stream(stringToCodePoints(opt_string));\n /** @type {?(number|!Array.<number>)} */\n var result;\n while (!input_stream.endOfStream()) {\n result = this._encoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (Array.isArray(result))\n bytes.push.apply(bytes, /**@type {!Array.<number>}*/(result));\n else\n bytes.push(result);\n }\n if (!this._streaming) {\n while (true) {\n result = this._encoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (Array.isArray(result))\n bytes.push.apply(bytes, /**@type {!Array.<number>}*/(result));\n else\n bytes.push(result);\n }\n this._encoder = null;\n }\n return new Uint8Array(bytes);\n }\n};\n\n//\n// 8. The encoding\n//\n\n// 8.1 utf-8\n\n/**\n * @constructor\n * @implements {Decoder}\n * @param {{fatal: boolean}} options\n */\nfunction UTF8Decoder(options) {\n var fatal = options.fatal;\n\n // utf-8's decoder's has an associated utf-8 code point, utf-8\n // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8\n // lower boundary (initially 0x80), and a utf-8 upper boundary\n // (initially 0xBF).\n var /** @type {number} */ utf8_code_point = 0,\n /** @type {number} */ utf8_bytes_seen = 0,\n /** @type {number} */ utf8_bytes_needed = 0,\n /** @type {number} */ utf8_lower_boundary = 0x80,\n /** @type {number} */ utf8_upper_boundary = 0xBF;\n\n /**\n * @param {Stream} stream The stream of bytes being decoded.\n * @param {number} bite The next byte read from the stream.\n * @return {?(number|!Array.<number>)} The next code point(s)\n * decoded, or null if not enough data exists in the input\n * stream to decode a complete code point.\n */\n this.handler = function(stream, bite) {\n // 1. If byte is end-of-stream and utf-8 bytes needed is not 0,\n // set utf-8 bytes needed to 0 and return error.\n if (bite === end_of_stream && utf8_bytes_needed !== 0) {\n utf8_bytes_needed = 0;\n return decoderError(fatal);\n }\n\n // 2. If byte is end-of-stream, return finished.\n if (bite === end_of_stream)\n return finished;\n\n // 3. If utf-8 bytes needed is 0, based on byte:\n if (utf8_bytes_needed === 0) {\n\n // 0x00 to 0x7F\n if (inRange(bite, 0x00, 0x7F)) {\n // Return a code point whose value is byte.\n return bite;\n }\n\n // 0xC2 to 0xDF\n if (inRange(bite, 0xC2, 0xDF)) {\n // Set utf-8 bytes needed to 1 and utf-8 code point to byte\n // 0xC0.\n utf8_bytes_needed = 1;\n utf8_code_point = bite - 0xC0;\n }\n\n // 0xE0 to 0xEF\n else if (inRange(bite, 0xE0, 0xEF)) {\n // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.\n if (bite === 0xE0)\n utf8_lower_boundary = 0xA0;\n // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.\n if (bite === 0xED)\n utf8_upper_boundary = 0x9F;\n // 3. Set utf-8 bytes needed to 2 and utf-8 code point to\n // byte 0xE0.\n utf8_bytes_needed = 2;\n utf8_code_point = bite - 0xE0;\n }\n\n // 0xF0 to 0xF4\n else if (inRange(bite, 0xF0, 0xF4)) {\n // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.\n if (bite === 0xF0)\n utf8_lower_boundary = 0x90;\n // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.\n if (bite === 0xF4)\n utf8_upper_boundary = 0x8F;\n // 3. Set utf-8 bytes needed to 3 and utf-8 code point to\n // byte 0xF0.\n utf8_bytes_needed = 3;\n utf8_code_point = bite - 0xF0;\n }\n\n // Otherwise\n else {\n // Return error.\n return decoderError(fatal);\n }\n\n // Then (byte is in the range 0xC2 to 0xF4) set utf-8 code\n // point to utf-8 code point << (6 × utf-8 bytes needed) and\n // return continue.\n utf8_code_point = utf8_code_point << (6 * utf8_bytes_needed);\n return null;\n }\n\n // 4. If byte is not in the range utf-8 lower boundary to utf-8\n // upper boundary, run these substeps:\n if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {\n\n // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8\n // bytes seen to 0, set utf-8 lower boundary to 0x80, and set\n // utf-8 upper boundary to 0xBF.\n utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;\n utf8_lower_boundary = 0x80;\n utf8_upper_boundary = 0xBF;\n\n // 2. Prepend byte to stream.\n stream.prepend(bite);\n\n // 3. Return error.\n return decoderError(fatal);\n }\n\n // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary\n // to 0xBF.\n utf8_lower_boundary = 0x80;\n utf8_upper_boundary = 0xBF;\n\n // 6. Increase utf-8 bytes seen by one and set utf-8 code point\n // to utf-8 code point + (byte 0x80) << (6 × (utf-8 bytes\n // needed utf-8 bytes seen)).\n utf8_bytes_seen += 1;\n utf8_code_point += (bite - 0x80) << (6 * (utf8_bytes_needed - utf8_bytes_seen));\n\n // 7. If utf-8 bytes seen is not equal to utf-8 bytes needed,\n // continue.\n if (utf8_bytes_seen !== utf8_bytes_needed)\n return null;\n\n // 8. Let code point be utf-8 code point.\n var code_point = utf8_code_point;\n\n // 9. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes\n // seen to 0.\n utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;\n\n // 10. Return a code point whose value is code point.\n return code_point;\n };\n}\n\n/**\n * @constructor\n * @implements {Encoder}\n * @param {{fatal: boolean}} options\n */\nfunction UTF8Encoder(options) {\n var fatal = options.fatal;\n /**\n * @param {Stream} stream Input stream.\n * @param {number} code_point Next code point read from the stream.\n * @return {(number|!Array.<number>)} Byte(s) to emit.\n */\n this.handler = function(stream, code_point) {\n // 1. If code point is end-of-stream, return finished.\n if (code_point === end_of_stream)\n return finished;\n\n // 2. If code point is in the range U+0000 to U+007F, return a\n // byte whose value is code point.\n if (inRange(code_point, 0x0000, 0x007f))\n return code_point;\n\n // 3. Set count and offset based on the range code point is in:\n var count, offset;\n // U+0080 to U+07FF: 1 and 0xC0\n if (inRange(code_point, 0x0080, 0x07FF)) {\n count = 1;\n offset = 0xC0;\n }\n // U+0800 to U+FFFF: 2 and 0xE0\n else if (inRange(code_point, 0x0800, 0xFFFF)) {\n count = 2;\n offset = 0xE0;\n }\n // U+10000 to U+10FFFF: 3 and 0xF0\n else if (inRange(code_point, 0x10000, 0x10FFFF)) {\n count = 3;\n offset = 0xF0;\n }\n\n // 4.Let bytes be a byte sequence whose first byte is (code\n // point >> (6 × count)) + offset.\n var bytes = [(code_point >> (6 * count)) + offset];\n\n // 5. Run these substeps while count is greater than 0:\n while (count > 0) {\n\n // 1. Set temp to code point >> (6 × (count 1)).\n var temp = code_point >> (6 * (count - 1));\n\n // 2. Append to bytes 0x80 | (temp & 0x3F).\n bytes.push(0x80 | (temp & 0x3F));\n\n // 3. Decrease count by one.\n count -= 1;\n }\n\n // 6. Return bytes bytes, in order.\n return bytes;\n };\n}\n\nexport {TextEncoder, TextDecoder};\n","/*\nCopyright 2017 Vector Creations Ltd\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n\"use strict\";\n\n// polyfill textencoder if necessary\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.encryptMegolmKeyFile = exports.decryptMegolmKeyFile = undefined;\n\nvar _promise = require('babel-runtime/core-js/promise');\n\nvar _promise2 = _interopRequireDefault(_promise);\n\nvar _regenerator = require('babel-runtime/regenerator');\n\nvar _regenerator2 = _interopRequireDefault(_regenerator);\n\nvar _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');\n\nvar _slicedToArray3 = _interopRequireDefault(_slicedToArray2);\n\nvar _bluebird = require('bluebird');\n\n/**\n * Decrypt a megolm key file\n *\n * @param {ArrayBuffer} data file to decrypt\n * @param {String} password\n * @return {Promise<String>} promise for decrypted output\n *\n *\n */\nvar decryptMegolmKeyFile = exports.decryptMegolmKeyFile = function () {\n var _ref = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee(data, password) {\n var body, version, ciphertextLength, salt, iv, iterations, ciphertext, hmac, _ref2, _ref3, aesKey, hmacKey, toVerify, isValid, plaintext;\n\n return _regenerator2.default.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n body = unpackMegolmKeyFile(data);\n\n // check we have a version byte\n\n if (!(body.length < 1)) {\n _context.next = 3;\n break;\n }\n\n throw friendlyError('Invalid file: too short', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 3:\n version = body[0];\n\n if (!(version !== 1)) {\n _context.next = 6;\n break;\n }\n\n throw friendlyError('Unsupported version', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 6:\n ciphertextLength = body.length - (1 + 16 + 16 + 4 + 32);\n\n if (!(ciphertextLength < 0)) {\n _context.next = 9;\n break;\n }\n\n throw friendlyError('Invalid file: too short', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 9:\n salt = body.subarray(1, 1 + 16);\n iv = body.subarray(17, 17 + 16);\n iterations = body[33] << 24 | body[34] << 16 | body[35] << 8 | body[36];\n ciphertext = body.subarray(37, 37 + ciphertextLength);\n hmac = body.subarray(-32);\n _context.next = 16;\n return (0, _bluebird.resolve)(deriveKeys(salt, iterations, password));\n\n case 16:\n _ref2 = _context.sent;\n _ref3 = (0, _slicedToArray3.default)(_ref2, 2);\n aesKey = _ref3[0];\n hmacKey = _ref3[1];\n toVerify = body.subarray(0, -32);\n isValid = void 0;\n _context.prev = 22;\n _context.next = 25;\n return (0, _bluebird.resolve)(subtleCrypto.verify({ name: 'HMAC' }, hmacKey, hmac, toVerify));\n\n case 25:\n isValid = _context.sent;\n _context.next = 31;\n break;\n\n case 28:\n _context.prev = 28;\n _context.t0 = _context['catch'](22);\n throw friendlyError('subtleCrypto.verify failed: ' + _context.t0, cryptoFailMsg());\n\n case 31:\n if (isValid) {\n _context.next = 33;\n break;\n }\n\n throw friendlyError('hmac mismatch', (0, _languageHandler._t)('Authentication check failed: incorrect password?'));\n\n case 33:\n plaintext = void 0;\n _context.prev = 34;\n _context.next = 37;\n return (0, _bluebird.resolve)(subtleCrypto.decrypt({\n name: \"AES-CTR\",\n counter: iv,\n length: 64\n }, aesKey, ciphertext));\n\n case 37:\n plaintext = _context.sent;\n _context.next = 43;\n break;\n\n case 40:\n _context.prev = 40;\n _context.t1 = _context['catch'](34);\n throw friendlyError('subtleCrypto.decrypt failed: ' + _context.t1, cryptoFailMsg());\n\n case 43:\n return _context.abrupt('return', new TextDecoder().decode(new Uint8Array(plaintext)));\n\n case 44:\n case 'end':\n return _context.stop();\n }\n }\n }, _callee, this, [[22, 28], [34, 40]]);\n }));\n\n return function decryptMegolmKeyFile(_x, _x2) {\n return _ref.apply(this, arguments);\n };\n}();\n\n/**\n * Encrypt a megolm key file\n *\n * @param {String} data\n * @param {String} password\n * @param {Object=} options\n * @param {Nunber=} options.kdf_rounds Number of iterations to perform of the\n * key-derivation function.\n * @return {Promise<ArrayBuffer>} promise for encrypted output\n */\n\n\nvar encryptMegolmKeyFile = exports.encryptMegolmKeyFile = function () {\n var _ref4 = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(data, password, options) {\n var kdfRounds, salt, iv, _ref5, _ref6, aesKey, hmacKey, encodedData, ciphertext, cipherArray, bodyLength, resultBuffer, idx, toSign, hmac, hmacArray;\n\n return _regenerator2.default.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n options = options || {};\n kdfRounds = options.kdf_rounds || 500000;\n salt = new Uint8Array(16);\n\n window.crypto.getRandomValues(salt);\n\n iv = new Uint8Array(16);\n\n window.crypto.getRandomValues(iv);\n\n // clear bit 63 of the IV to stop us hitting the 64-bit counter boundary\n // (which would mean we wouldn't be able to decrypt on Android). The loss\n // of a single bit of iv is a price we have to pay.\n iv[8] &= 0x7f;\n\n _context2.next = 9;\n return (0, _bluebird.resolve)(deriveKeys(salt, kdfRounds, password));\n\n case 9:\n _ref5 = _context2.sent;\n _ref6 = (0, _slicedToArray3.default)(_ref5, 2);\n aesKey = _ref6[0];\n hmacKey = _ref6[1];\n encodedData = new TextEncoder().encode(data);\n ciphertext = void 0;\n _context2.prev = 15;\n _context2.next = 18;\n return (0, _bluebird.resolve)(subtleCrypto.encrypt({\n name: \"AES-CTR\",\n counter: iv,\n length: 64\n }, aesKey, encodedData));\n\n case 18:\n ciphertext = _context2.sent;\n _context2.next = 24;\n break;\n\n case 21:\n _context2.prev = 21;\n _context2.t0 = _context2['catch'](15);\n throw friendlyError('subtleCrypto.encrypt failed: ' + _context2.t0, cryptoFailMsg());\n\n case 24:\n cipherArray = new Uint8Array(ciphertext);\n bodyLength = 1 + salt.length + iv.length + 4 + cipherArray.length + 32;\n resultBuffer = new Uint8Array(bodyLength);\n idx = 0;\n\n resultBuffer[idx++] = 1; // version\n resultBuffer.set(salt, idx);idx += salt.length;\n resultBuffer.set(iv, idx);idx += iv.length;\n resultBuffer[idx++] = kdfRounds >> 24;\n resultBuffer[idx++] = kdfRounds >> 16 & 0xff;\n resultBuffer[idx++] = kdfRounds >> 8 & 0xff;\n resultBuffer[idx++] = kdfRounds & 0xff;\n resultBuffer.set(cipherArray, idx);idx += cipherArray.length;\n\n toSign = resultBuffer.subarray(0, idx);\n hmac = void 0;\n _context2.prev = 41;\n _context2.next = 44;\n return (0, _bluebird.resolve)(subtleCrypto.sign({ name: 'HMAC' }, hmacKey, toSign));\n\n case 44:\n hmac = _context2.sent;\n _context2.next = 50;\n break;\n\n case 47:\n _context2.prev = 47;\n _context2.t1 = _context2['catch'](41);\n throw friendlyError('subtleCrypto.sign failed: ' + _context2.t1, cryptoFailMsg());\n\n case 50:\n hmacArray = new Uint8Array(hmac);\n\n resultBuffer.set(hmacArray, idx);\n return _context2.abrupt('return', packMegolmKeyFile(resultBuffer));\n\n case 53:\n case 'end':\n return _context2.stop();\n }\n }\n }, _callee2, this, [[15, 21], [41, 47]]);\n }));\n\n return function encryptMegolmKeyFile(_x3, _x4, _x5) {\n return _ref4.apply(this, arguments);\n };\n}();\n\n/**\n * Derive the AES and HMAC-SHA-256 keys for the file\n *\n * @param {Unit8Array} salt salt for pbkdf\n * @param {Number} iterations number of pbkdf iterations\n * @param {String} password password\n * @return {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]\n */\n\n\nvar deriveKeys = function () {\n var _ref7 = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(salt, iterations, password) {\n var start, key, keybits, now, aesKey, hmacKey, aesProm, hmacProm;\n return _regenerator2.default.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n start = new Date();\n key = void 0;\n _context3.prev = 2;\n _context3.next = 5;\n return (0, _bluebird.resolve)(subtleCrypto.importKey('raw', new TextEncoder().encode(password), { name: 'PBKDF2' }, false, ['deriveBits']));\n\n case 5:\n key = _context3.sent;\n _context3.next = 11;\n break;\n\n case 8:\n _context3.prev = 8;\n _context3.t0 = _context3['catch'](2);\n throw friendlyError('subtleCrypto.importKey failed: ' + _context3.t0, cryptoFailMsg());\n\n case 11:\n keybits = void 0;\n _context3.prev = 12;\n _context3.next = 15;\n return (0, _bluebird.resolve)(subtleCrypto.deriveBits({\n name: 'PBKDF2',\n salt: salt,\n iterations: iterations,\n hash: 'SHA-512'\n }, key, 512));\n\n case 15:\n keybits = _context3.sent;\n _context3.next = 21;\n break;\n\n case 18:\n _context3.prev = 18;\n _context3.t1 = _context3['catch'](12);\n throw friendlyError('subtleCrypto.deriveBits failed: ' + _context3.t1, cryptoFailMsg());\n\n case 21:\n now = new Date();\n\n console.log(\"E2e import/export: deriveKeys took \" + (now - start) + \"ms\");\n\n aesKey = keybits.slice(0, 32);\n hmacKey = keybits.slice(32);\n aesProm = subtleCrypto.importKey('raw', aesKey, { name: 'AES-CTR' }, false, ['encrypt', 'decrypt']).catch(function (e) {\n throw friendlyError('subtleCrypto.importKey failed for AES key: ' + e, cryptoFailMsg());\n });\n hmacProm = subtleCrypto.importKey('raw', hmacKey, {\n name: 'HMAC',\n hash: { name: 'SHA-256' }\n }, false, ['sign', 'verify']).catch(function (e) {\n throw friendlyError('subtleCrypto.importKey failed for HMAC key: ' + e, cryptoFailMsg());\n });\n _context3.next = 29;\n return (0, _bluebird.resolve)(_promise2.default.all([aesProm, hmacProm]));\n\n case 29:\n return _context3.abrupt('return', _context3.sent);\n\n case 30:\n case 'end':\n return _context3.stop();\n }\n }\n }, _callee3, this, [[2, 8], [12, 18]]);\n }));\n\n return function deriveKeys(_x6, _x7, _x8) {\n return _ref7.apply(this, arguments);\n };\n}();\n\nvar _textEncodingUtf = require('text-encoding-utf-8');\n\nvar TextEncodingUtf8 = _interopRequireWildcard(_textEncodingUtf);\n\nvar _languageHandler = require('../languageHandler');\n\nfunction _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar TextEncoder = window.TextEncoder;\nif (!TextEncoder) {\n TextEncoder = TextEncodingUtf8.TextEncoder;\n}\nvar TextDecoder = window.TextDecoder;\nif (!TextDecoder) {\n TextDecoder = TextEncodingUtf8.TextDecoder;\n}\n\nvar subtleCrypto = window.crypto.subtle || window.crypto.webkitSubtle;\n\n/**\n * Make an Error object which has a friendlyText property which is already\n * translated and suitable for showing to the user.\n *\n * @param {string} msg message for the exception\n * @param {string} friendlyText\n * @returns {Error}\n */\nfunction friendlyError(msg, friendlyText) {\n var e = new Error(msg);\n e.friendlyText = friendlyText;\n return e;\n}\n\nfunction cryptoFailMsg() {\n return (0, _languageHandler._t)('Your browser does not support the required cryptography extensions');\n}\n\nvar HEADER_LINE = '-----BEGIN MEGOLM SESSION DATA-----';\nvar TRAILER_LINE = '-----END MEGOLM SESSION DATA-----';\n\n/**\n * Unbase64 an ascii-armoured megolm key file\n *\n * Strips the header and trailer lines, and unbase64s the content\n *\n * @param {ArrayBuffer} data input file\n * @return {Uint8Array} unbase64ed content\n */\nfunction unpackMegolmKeyFile(data) {\n // parse the file as a great big String. This should be safe, because there\n // should be no non-ASCII characters, and it means that we can do string\n // comparisons to find the header and footer, and feed it into window.atob.\n var fileStr = new TextDecoder().decode(new Uint8Array(data));\n\n // look for the start line\n var lineStart = 0;\n while (1) {\n var lineEnd = fileStr.indexOf('\\n', lineStart);\n if (lineEnd < 0) {\n throw new Error('Header line not found');\n }\n var line = fileStr.slice(lineStart, lineEnd).trim();\n\n // start the next line after the newline\n lineStart = lineEnd + 1;\n\n if (line === HEADER_LINE) {\n break;\n }\n }\n\n var dataStart = lineStart;\n\n // look for the end line\n while (1) {\n var _lineEnd = fileStr.indexOf('\\n', lineStart);\n var _line = fileStr.slice(lineStart, _lineEnd < 0 ? undefined : _lineEnd).trim();\n if (_line === TRAILER_LINE) {\n break;\n }\n\n if (_lineEnd < 0) {\n throw new Error('Trailer line not found');\n }\n\n // start the next line after the newline\n lineStart = _lineEnd + 1;\n }\n\n var dataEnd = lineStart;\n return decodeBase64(fileStr.slice(dataStart, dataEnd));\n}\n\n/**\n * ascii-armour a megolm key file\n *\n * base64s the content, and adds header and trailer lines\n *\n * @param {Uint8Array} data raw data\n * @return {ArrayBuffer} formatted file\n */\nfunction packMegolmKeyFile(data) {\n // we split into lines before base64ing, because encodeBase64 doesn't deal\n // terribly well with large arrays.\n var LINE_LENGTH = 72 * 4 / 3;\n var nLines = Math.ceil(data.length / LINE_LENGTH);\n var lines = new Array(nLines + 3);\n lines[0] = HEADER_LINE;\n var o = 0;\n var i = void 0;\n for (i = 1; i <= nLines; i++) {\n lines[i] = encodeBase64(data.subarray(o, o + LINE_LENGTH));\n o += LINE_LENGTH;\n }\n lines[i++] = TRAILER_LINE;\n lines[i] = '';\n return new TextEncoder().encode(lines.join('\\n')).buffer;\n}\n\n/**\n * Encode a typed array of uint8 as base64.\n * @param {Uint8Array} uint8Array The data to encode.\n * @return {string} The base64.\n */\nfunction encodeBase64(uint8Array) {\n // Misinterpt the Uint8Array as Latin-1.\n // window.btoa expects a unicode string with codepoints in the range 0-255.\n var latin1String = String.fromCharCode.apply(null, uint8Array);\n // Use the builtin base64 encoder.\n return window.btoa(latin1String);\n}\n\n/**\n * Decode a base64 string to a typed array of uint8.\n * @param {string} base64 The base64 to decode.\n * @return {Uint8Array} The decoded data.\n */\nfunction decodeBase64(base64) {\n // window.atob returns a unicode string with codepoints in the range 0-255.\n var latin1String = window.atob(base64);\n // Encode the string as a Uint8Array\n var uint8Array = new Uint8Array(latin1String.length);\n for (var i = 0; i < latin1String.length; i++) {\n uint8Array[i] = latin1String.charCodeAt(i);\n }\n return uint8Array;\n}\n//# sourceMappingURL=MegolmExportEncryption.js.map"],"sourceRoot":""}