-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Part of #20 * Next to use async notion for a better experience.
- Loading branch information
Showing
4 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
importScripts("resource://gre/modules/workers/require.js"); | ||
|
||
let PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js"); | ||
|
||
let Funcs = {}; | ||
|
||
// Only what we need from libotr.js | ||
Funcs.generateKey = function(path, otrl_version, newkeySource) { | ||
let newkey = eval(newkeySource); | ||
let libotr = ctypes.open(path); | ||
|
||
let abi = ctypes.default_abi; | ||
let gcry_error_t = ctypes.unsigned_int; | ||
|
||
// Initialize the OTR library. Pass the version of the API you are using. | ||
let otrl_init = libotr.declare( | ||
"otrl_init", abi, gcry_error_t, | ||
ctypes.unsigned_int, ctypes.unsigned_int, ctypes.unsigned_int | ||
); | ||
|
||
// Do the private key generation calculation. You may call this from a | ||
// background thread. When it completes, call | ||
// otrl_privkey_generate_finish from the _main_ thread. | ||
let otrl_privkey_generate_calculate = libotr.declare( | ||
"otrl_privkey_generate_calculate", abi, gcry_error_t, | ||
ctypes.void_t.ptr | ||
); | ||
|
||
otrl_init.apply(libotr, otrl_version); | ||
let err = otrl_privkey_generate_calculate(newkey); | ||
libotr.close(); | ||
return err; | ||
}; | ||
|
||
let worker = new PromiseWorker.AbstractWorker(); | ||
|
||
worker.dispatch = function(method, args = []) { | ||
return Funcs[method](...args); | ||
}; | ||
|
||
worker.postMessage = function(res, ...args) { | ||
self.postMessage(res, ...args); | ||
}; | ||
|
||
worker.close = function() { | ||
self.close(); | ||
}; | ||
|
||
self.addEventListener("message", msg => worker.handleMessage(msg)); |
ed1af6f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aleth In case you missed this. They don't appear to be shared nothing.