aboutsummaryrefslogtreecommitdiff
path: root/javascript/olm_sas.js
diff options
context:
space:
mode:
authorDamir Jelić <poljar@termina.org.uk>2019-04-01 17:40:43 +0200
committerHubert Chathi <hubert@uhoreg.ca>2019-04-08 15:18:28 -0400
commit071029c20174307de28ca20232196f83fcc37763 (patch)
tree272e901d2bfcf0efe6be018caed3a3a06d54a815 /javascript/olm_sas.js
parent709687a7b56d6768831766459940b6f0bb078d85 (diff)
javascript: Switch from deprecated Pointer_stringify() to UTF8toString().
The Pointer_stringify() function is deprecated and has a couple of issues because it tries to guess the encoding of the buffer. In some cases it can ignore the length parameter which could end up in inconsistencies. Switch to UTF8toString() that takes a length parameter and respects, that way we don't need to allocate an additional byte for a NULL byte.
Diffstat (limited to 'javascript/olm_sas.js')
-rw-r--r--javascript/olm_sas.js10
1 files changed, 5 insertions, 5 deletions
diff --git a/javascript/olm_sas.js b/javascript/olm_sas.js
index a2f82ee..a01cc07 100644
--- a/javascript/olm_sas.js
+++ b/javascript/olm_sas.js
@@ -12,7 +12,7 @@ function sas_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_sas_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -28,9 +28,9 @@ SAS.prototype['free'] = function() {
SAS.prototype['get_pubkey'] = restore_stack(function() {
var pubkey_length = sas_method(Module['_olm_sas_pubkey_length'])(this.ptr);
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
+ var pubkey_buffer = stack(pubkey_length);
sas_method(Module['_olm_sas_get_pubkey'])(this.ptr, pubkey_buffer, pubkey_length);
- return Pointer_stringify(pubkey_buffer);
+ return UTF8ToString(pubkey_buffer, pubkey_length);
});
SAS.prototype['set_their_key'] = restore_stack(function(their_key) {
@@ -66,14 +66,14 @@ SAS.prototype['calculate_mac'] = restore_stack(function(input, info) {
var info_array = array_from_string(info);
var info_buffer = stack(info_array);
var mac_length = sas_method(Module['_olm_sas_mac_length'])(this.ptr);
- var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
+ var mac_buffer = stack(mac_length);
sas_method(Module['_olm_sas_calculate_mac'])(
this.ptr,
input_buffer, input_array.length,
info_buffer, info_array.length,
mac_buffer, mac_length
);
- return Pointer_stringify(mac_buffer);
+ return UTF8ToString(mac_buffer, mac_length);
});
SAS.prototype['calculate_mac_long_kdf'] = restore_stack(function(input, info) {