2015-07-14 17:45:00 +02:00
|
|
|
var get_random_values;
|
2016-12-12 17:52:03 +01:00
|
|
|
|
|
|
|
if (typeof(window) !== 'undefined') {
|
2018-09-21 17:01:51 +02:00
|
|
|
// We're in a browser (directly, via browserify, or via webpack).
|
2015-07-14 17:45:00 +02:00
|
|
|
get_random_values = function(buf) {
|
|
|
|
window.crypto.getRandomValues(buf);
|
|
|
|
};
|
|
|
|
} else if (module["exports"]) {
|
|
|
|
// We're running in node.
|
|
|
|
var nodeCrypto = require("crypto");
|
|
|
|
get_random_values = function(buf) {
|
2018-09-21 17:01:51 +02:00
|
|
|
// [''] syntax needed here rather than '.' to prevent
|
|
|
|
// closure compiler from mangling the import(!)
|
|
|
|
var bytes = nodeCrypto['randomBytes'](buf.length);
|
2015-07-14 17:45:00 +02:00
|
|
|
buf.set(bytes);
|
2016-12-12 17:52:03 +01:00
|
|
|
};
|
2015-07-21 15:30:46 +02:00
|
|
|
process = global["process"];
|
2015-07-14 17:45:00 +02:00
|
|
|
} else {
|
|
|
|
throw new Error("Cannot find global to attach library to");
|
|
|
|
}
|
|
|
|
|
2018-09-21 17:01:51 +02:00
|
|
|
/* applications should define OLM_OPTIONS in the environment to override
|
2018-09-21 17:35:17 +02:00
|
|
|
* emscripten module settings
|
2018-09-21 17:01:51 +02:00
|
|
|
*/
|
|
|
|
if (typeof(OLM_OPTIONS) !== 'undefined') {
|
|
|
|
for (var olm_option_key in OLM_OPTIONS) {
|
|
|
|
if (OLM_OPTIONS.hasOwnProperty(olm_option_key)) {
|
|
|
|
Module[olm_option_key] = OLM_OPTIONS[olm_option_key];
|
2016-12-14 12:41:51 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-21 17:01:51 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 21:09:54 +02:00
|
|
|
Module['onRuntimeInitialized'] = function() {
|
|
|
|
OLM_ERROR = Module['_olm_error']();
|
2018-10-10 21:15:40 +02:00
|
|
|
olm_exports["PRIVATE_KEY_LENGTH"] = Module['_olm_pk_private_key_length']();
|
2018-10-04 21:09:54 +02:00
|
|
|
if (onInitSuccess) onInitSuccess();
|
|
|
|
};
|
|
|
|
|
|
|
|
Module['onAbort'] = function(err) {
|
|
|
|
if (onInitFail) onInitFail(err);
|
|
|
|
};
|