1
0
mirror of https://github.com/Luzifer/wasm-openssl.git synced 2024-09-19 16:02:58 +00:00

Prefix functions to prevent collisions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-09-18 19:24:43 +02:00
parent 183d4aa492
commit 2df57ab352
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
3 changed files with 7 additions and 7 deletions

View File

@ -40,11 +40,11 @@ Afterwards in your HTML you can include the `wasm_exec.js` and load the binary:
</html> </html>
``` ```
If you have a top-level function `opensslLoaded()` defined, this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `encrypt` and `decrypt`: If you have a top-level function `opensslLoaded()` defined, this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `opensslEncrypt` and `opensslDecrypt`:
```javascript ```javascript
function decrypt(ciphertext, passphrase, callback) {} function opensslDecrypt(ciphertext, passphrase, callback) {}
function encrypt(plaintext, passphrase, callback) {} function opensslEncrypt(plaintext, passphrase, callback) {}
``` ```
The functions will not return anything in the moment as in the current state Go WASM support does not have return values. Instead the callback function you've provided will be called and always have two arguments: `function callback(result, error)` - The `result` will be the plaintext on `decrypt` and the ciphertext on `encrypt`. The `error` will either be `null` or a string containing details about the error. When an error occurred the `result` is `null`. The functions will not return anything in the moment as in the current state Go WASM support does not have return values. Instead the callback function you've provided will be called and always have two arguments: `function callback(result, error)` - The `result` will be the plaintext on `decrypt` and the ciphertext on `encrypt`. The `error` will either be `null` or a string containing details about the error. When an error occurred the `result` is `null`.

View File

@ -5,12 +5,12 @@ function decryptResponse(plaintext, error) {
function encryptResponse(ciphertext, error) { function encryptResponse(ciphertext, error) {
console.log(["encryptResponse", ciphertext, error]) console.log(["encryptResponse", ciphertext, error])
if (error === null) { if (error === null) {
decrypt(ciphertext, "password", decryptResponse) opensslDecrypt(ciphertext, "password", decryptResponse)
} }
} }
function opensslLoaded() { function opensslLoaded() {
encrypt("Knut", "password", encryptResponse) opensslEncrypt("Knut", "password", encryptResponse)
} }
const go = new Go() const go = new Go()

View File

@ -8,8 +8,8 @@ import (
) )
func main() { func main() {
js.Global().Set("decrypt", js.NewCallback(decrypt)) js.Global().Set("opensslDecrypt", js.NewCallback(decrypt))
js.Global().Set("encrypt", js.NewCallback(encrypt)) js.Global().Set("opensslEncrypt", js.NewCallback(encrypt))
// Trigger custom "event" // Trigger custom "event"
if js.Global().Get("opensslLoaded").Type() == js.TypeFunction { if js.Global().Get("opensslLoaded").Type() == js.TypeFunction {