aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javascript/olm_inbound_group_session.js27
-rw-r--r--javascript/olm_outbound_group_session.js25
-rw-r--r--javascript/olm_pk.js58
-rw-r--r--javascript/olm_post.js58
-rw-r--r--javascript/olm_pre.js8
-rw-r--r--javascript/olm_sas.js10
6 files changed, 69 insertions, 117 deletions
diff --git a/javascript/olm_inbound_group_session.js b/javascript/olm_inbound_group_session.js
index dd8e493..4aa3201 100644
--- a/javascript/olm_inbound_group_session.js
+++ b/javascript/olm_inbound_group_session.js
@@ -8,7 +8,7 @@ function inbound_group_session_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_inbound_group_session_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -28,7 +28,7 @@ InboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
Module['_olm_pickle_inbound_group_session_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
+ var pickle_buffer = stack(pickle_length);
try {
inbound_group_session_method(Module['_olm_pickle_inbound_group_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -40,7 +40,7 @@ InboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
key_array[i] = 0;
}
}
- return Pointer_stringify(pickle_buffer);
+ return UTF8ToString(pickle_buffer, pickle_length);
});
InboundGroupSession.prototype['unpickle'] = restore_stack(function(key, pickle) {
@@ -112,7 +112,7 @@ InboundGroupSession.prototype['decrypt'] = restore_stack(function(
// caculating the length destroys the input buffer, so we need to re-copy it.
writeAsciiToMemory(message, message_buffer, true);
- plaintext_buffer = malloc(max_plaintext_length + NULL_BYTE_PADDING_LENGTH);
+ plaintext_buffer = malloc(max_plaintext_length);
var message_index = stack(4);
plaintext_length = inbound_group_session_method(
@@ -124,15 +124,8 @@ InboundGroupSession.prototype['decrypt'] = restore_stack(function(
message_index
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer+plaintext_length,
- 0, "i8"
- );
-
return {
- "plaintext": UTF8ToString(plaintext_buffer),
+ "plaintext": UTF8ToString(plaintext_buffer, plaintext_length),
"message_index": getValue(message_index, "i32")
}
} finally {
@@ -141,7 +134,7 @@ InboundGroupSession.prototype['decrypt'] = restore_stack(function(
}
if (plaintext_buffer !== undefined) {
// don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length + NULL_BYTE_PADDING_LENGTH);
+ bzero(plaintext_buffer, plaintext_length);
free(plaintext_buffer);
}
}
@@ -151,11 +144,11 @@ InboundGroupSession.prototype['session_id'] = restore_stack(function() {
var length = inbound_group_session_method(
Module['_olm_inbound_group_session_id_length']
)(this.ptr);
- var session_id = stack(length + NULL_BYTE_PADDING_LENGTH);
+ var session_id = stack(length);
inbound_group_session_method(Module['_olm_inbound_group_session_id'])(
this.ptr, session_id, length
);
- return Pointer_stringify(session_id);
+ return UTF8ToString(session_id, length);
});
InboundGroupSession.prototype['first_known_index'] = restore_stack(function() {
@@ -168,11 +161,11 @@ InboundGroupSession.prototype['export_session'] = restore_stack(function(message
var key_length = inbound_group_session_method(
Module['_olm_export_inbound_group_session_length']
)(this.ptr);
- var key = stack(key_length + NULL_BYTE_PADDING_LENGTH);
+ var key = stack(key_length);
outbound_group_session_method(Module['_olm_export_inbound_group_session'])(
this.ptr, key, key_length, message_index
);
- var key_str = Pointer_stringify(key);
+ var key_str = UTF8ToString(key, key_length);
bzero(key, key_length); // clear out a copy of the key
return key_str;
});
diff --git a/javascript/olm_outbound_group_session.js b/javascript/olm_outbound_group_session.js
index f1ccd3d..e4427cc 100644
--- a/javascript/olm_outbound_group_session.js
+++ b/javascript/olm_outbound_group_session.js
@@ -8,7 +8,7 @@ function outbound_group_session_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_outbound_group_session_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -28,7 +28,7 @@ OutboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
Module['_olm_pickle_outbound_group_session_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
+ var pickle_buffer = stack(pickle_length);
try {
outbound_group_session_method(Module['_olm_pickle_outbound_group_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -40,7 +40,7 @@ OutboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
key_array[i] = 0;
}
}
- return Pointer_stringify(pickle_buffer);
+ return UTF8ToString(pickle_buffer, pickle_length);
});
OutboundGroupSession.prototype['unpickle'] = restore_stack(function(key, pickle) {
@@ -86,21 +86,14 @@ OutboundGroupSession.prototype['encrypt'] = function(plaintext) {
plaintext_buffer = malloc(plaintext_length + 1);
stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
- message_buffer = malloc(message_length + NULL_BYTE_PADDING_LENGTH);
+ message_buffer = malloc(message_length);
outbound_group_session_method(Module['_olm_group_encrypt'])(
this.ptr,
plaintext_buffer, plaintext_length,
message_buffer, message_length
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- message_buffer+message_length,
- 0, "i8"
- );
-
- return UTF8ToString(message_buffer);
+ return UTF8ToString(message_buffer, message_length);
} finally {
if (plaintext_buffer !== undefined) {
// don't leave a copy of the plaintext in the heap.
@@ -117,22 +110,22 @@ OutboundGroupSession.prototype['session_id'] = restore_stack(function() {
var length = outbound_group_session_method(
Module['_olm_outbound_group_session_id_length']
)(this.ptr);
- var session_id = stack(length + NULL_BYTE_PADDING_LENGTH);
+ var session_id = stack(length);
outbound_group_session_method(Module['_olm_outbound_group_session_id'])(
this.ptr, session_id, length
);
- return Pointer_stringify(session_id);
+ return UTF8ToString(session_id, length);
});
OutboundGroupSession.prototype['session_key'] = restore_stack(function() {
var key_length = outbound_group_session_method(
Module['_olm_outbound_group_session_key_length']
)(this.ptr);
- var key = stack(key_length + NULL_BYTE_PADDING_LENGTH);
+ var key = stack(key_length);
outbound_group_session_method(Module['_olm_outbound_group_session_key'])(
this.ptr, key, key_length
);
- var key_str = Pointer_stringify(key);
+ var key_str = UTF8ToString(key, key_length);
bzero(key, key_length); // clear out our copy of the key
return key_str;
});
diff --git a/javascript/olm_pk.js b/javascript/olm_pk.js
index 2cbe44d..8e99494 100644
--- a/javascript/olm_pk.js
+++ b/javascript/olm_pk.js
@@ -8,7 +8,7 @@ function pk_encryption_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_pk_encryption_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -45,11 +45,11 @@ PkEncryption.prototype['encrypt'] = restore_stack(function(
var ciphertext_length = pk_encryption_method(
Module['_olm_pk_ciphertext_length']
)(this.ptr, plaintext_length);
- ciphertext_buffer = malloc(ciphertext_length + NULL_BYTE_PADDING_LENGTH);
+ ciphertext_buffer = malloc(ciphertext_length);
var mac_length = pk_encryption_method(
Module['_olm_pk_mac_length']
)(this.ptr);
- var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
+ var mac_buffer = stack(mac_length);
setValue(
mac_buffer + mac_length,
0, "i8"
@@ -57,7 +57,7 @@ PkEncryption.prototype['encrypt'] = restore_stack(function(
var ephemeral_length = pk_encryption_method(
Module['_olm_pk_key_length']
)();
- var ephemeral_buffer = stack(ephemeral_length + NULL_BYTE_PADDING_LENGTH);
+ var ephemeral_buffer = stack(ephemeral_length);
setValue(
ephemeral_buffer + ephemeral_length,
0, "i8"
@@ -70,16 +70,10 @@ PkEncryption.prototype['encrypt'] = restore_stack(function(
ephemeral_buffer, ephemeral_length,
random, random_length
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- ciphertext_buffer + ciphertext_length,
- 0, "i8"
- );
return {
- "ciphertext": UTF8ToString(ciphertext_buffer),
- "mac": Pointer_stringify(mac_buffer),
- "ephemeral": Pointer_stringify(ephemeral_buffer)
+ "ciphertext": UTF8ToString(ciphertext_buffer, ciphertext_length),
+ "mac": UTF8ToString(mac_buffer, mac_length),
+ "ephemeral": UTF8ToString(ephemeral_buffer, ephemeral_length)
};
} finally {
if (random !== undefined) {
@@ -108,7 +102,7 @@ function pk_decryption_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_pk_decryption_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -129,7 +123,7 @@ PkDecryption.prototype['init_with_private_key'] = restore_stack(function (privat
var pubkey_length = pk_decryption_method(
Module['_olm_pk_key_length']
)();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
+ var pubkey_buffer = stack(pubkey_length);
try {
pk_decryption_method(Module['_olm_pk_key_from_private'])(
this.ptr,
@@ -140,7 +134,7 @@ PkDecryption.prototype['init_with_private_key'] = restore_stack(function (privat
// clear out our copy of the private key
bzero(private_key_buffer, private_key.length);
}
- return Pointer_stringify(pubkey_buffer);
+ return UTF8ToString(pubkey_buffer, pubkey_length);
});
PkDecryption.prototype['generate_key'] = restore_stack(function () {
@@ -151,7 +145,7 @@ PkDecryption.prototype['generate_key'] = restore_stack(function () {
var pubkey_length = pk_decryption_method(
Module['_olm_pk_key_length']
)();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
+ var pubkey_buffer = stack(pubkey_length);
try {
pk_decryption_method(Module['_olm_pk_key_from_private'])(
this.ptr,
@@ -162,7 +156,7 @@ PkDecryption.prototype['generate_key'] = restore_stack(function () {
// clear out the random buffer (= private key)
bzero(random_buffer, random_length);
}
- return Pointer_stringify(pubkey_buffer);
+ return UTF8ToString(pubkey_buffer, pubkey_length);
});
PkDecryption.prototype['get_private_key'] = restore_stack(function () {
@@ -190,7 +184,7 @@ PkDecryption.prototype['pickle'] = restore_stack(function (key) {
Module['_olm_pickle_pk_decryption_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
+ var pickle_buffer = stack(pickle_length);
try {
pk_decryption_method(Module['_olm_pickle_pk_decryption'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -202,7 +196,7 @@ PkDecryption.prototype['pickle'] = restore_stack(function (key) {
key_array[i] = 0;
}
}
- return Pointer_stringify(pickle_buffer);
+ return UTF8ToString(pickle_buffer, pickle_length);
});
PkDecryption.prototype['unpickle'] = restore_stack(function (key, pickle) {
@@ -213,7 +207,7 @@ PkDecryption.prototype['unpickle'] = restore_stack(function (key, pickle) {
var ephemeral_length = pk_decryption_method(
Module["_olm_pk_key_length"]
)();
- var ephemeral_buffer = stack(ephemeral_length + NULL_BYTE_PADDING_LENGTH);
+ var ephemeral_buffer = stack(ephemeral_length);
try {
pk_decryption_method(Module['_olm_unpickle_pk_decryption'])(
this.ptr, key_buffer, key_array.length, pickle_buffer,
@@ -226,7 +220,7 @@ PkDecryption.prototype['unpickle'] = restore_stack(function (key, pickle) {
key_array[i] = 0;
}
}
- return Pointer_stringify(ephemeral_buffer);
+ return UTF8ToString(ephemeral_buffer, ephemeral_length);
});
PkDecryption.prototype['decrypt'] = restore_stack(function (
@@ -245,7 +239,7 @@ PkDecryption.prototype['decrypt'] = restore_stack(function (
this.ptr,
ciphertext_length
);
- plaintext_buffer = malloc(plaintext_max_length + NULL_BYTE_PADDING_LENGTH);
+ plaintext_buffer = malloc(plaintext_max_length);
var plaintext_length = pk_decryption_method(Module['_olm_pk_decrypt'])(
this.ptr,
ephemeralkey_buffer, ephemeralkey_array.length,
@@ -253,13 +247,7 @@ PkDecryption.prototype['decrypt'] = restore_stack(function (
ciphertext_buffer, ciphertext_length,
plaintext_buffer, plaintext_max_length
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer + plaintext_length,
- 0, "i8"
- );
- return UTF8ToString(plaintext_buffer);
+ return UTF8ToString(plaintext_buffer, plaintext_length);
} finally {
if (plaintext_buffer !== undefined) {
// don't leave a copy of the plaintext in the heap.
@@ -283,7 +271,7 @@ function pk_signing_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_pk_signing_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -304,7 +292,7 @@ PkSigning.prototype['init_with_seed'] = restore_stack(function (seed) {
var pubkey_length = pk_signing_method(
Module['_olm_pk_signing_public_key_length']
)();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
+ var pubkey_buffer = stack(pubkey_length);
try {
pk_signing_method(Module['_olm_pk_signing_key_from_seed'])(
this.ptr,
@@ -315,7 +303,7 @@ PkSigning.prototype['init_with_seed'] = restore_stack(function (seed) {
// clear out our copy of the seed
bzero(seed_buffer, seed.length);
}
- return Pointer_stringify(pubkey_buffer);
+ return UTF8ToString(pubkey_buffer, pubkey_length);
});
PkSigning.prototype['generate_seed'] = restore_stack(function () {
@@ -345,13 +333,13 @@ PkSigning.prototype['sign'] = restore_stack(function (message) {
var sig_length = pk_signing_method(
Module['_olm_pk_signature_length']
)();
- var sig_buffer = stack(sig_length + NULL_BYTE_PADDING_LENGTH);
+ var sig_buffer = stack(sig_length);
pk_signing_method(Module['_olm_pk_sign'])(
this.ptr,
message_buffer, message_length,
sig_buffer, sig_length
);
- return Pointer_stringify(sig_buffer);
+ return UTF8ToString(sig_buffer, sig_length);
} finally {
if (message_buffer !== undefined) {
// don't leave a copy of the plaintext in the heap.
diff --git a/javascript/olm_post.js b/javascript/olm_post.js
index a3a3ef4..8460893 100644
--- a/javascript/olm_post.js
+++ b/javascript/olm_post.js
@@ -49,7 +49,7 @@ function account_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_account_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -77,11 +77,11 @@ Account.prototype['identity_keys'] = restore_stack(function() {
var keys_length = account_method(
Module['_olm_account_identity_keys_length']
)(this.ptr);
- var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
+ var keys = stack(keys_length);
account_method(Module['_olm_account_identity_keys'])(
this.ptr, keys, keys_length
);
- return Pointer_stringify(keys);
+ return UTF8ToString(keys, keys_length);
});
Account.prototype['sign'] = restore_stack(function(message) {
@@ -90,7 +90,7 @@ Account.prototype['sign'] = restore_stack(function(message) {
)(this.ptr);
var message_array = array_from_string(message);
var message_buffer = stack(message_array);
- var signature_buffer = stack(signature_length + NULL_BYTE_PADDING_LENGTH);
+ var signature_buffer = stack(signature_length);
try {
account_method(Module['_olm_account_sign'])(
this.ptr,
@@ -104,18 +104,18 @@ Account.prototype['sign'] = restore_stack(function(message) {
message_array[i] = 0;
}
}
- return Pointer_stringify(signature_buffer);
+ return UTF8ToString(signature_buffer, signature_length);
});
Account.prototype['one_time_keys'] = restore_stack(function() {
var keys_length = account_method(
Module['_olm_account_one_time_keys_length']
)(this.ptr);
- var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
+ var keys = stack(keys_length);
account_method(Module['_olm_account_one_time_keys'])(
this.ptr, keys, keys_length
);
- return Pointer_stringify(keys);
+ return UTF8ToString(keys, keys_length);
});
Account.prototype['mark_keys_as_published'] = restore_stack(function() {
@@ -152,7 +152,7 @@ Account.prototype['pickle'] = restore_stack(function(key) {
Module['_olm_pickle_account_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
+ var pickle_buffer = stack(pickle_length);
try {
account_method(Module['_olm_pickle_account'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -164,7 +164,7 @@ Account.prototype['pickle'] = restore_stack(function(key) {
key_array[i] = 0;
}
}
- return Pointer_stringify(pickle_buffer);
+ return UTF8ToString(pickle_buffer, pickle_length);
});
Account.prototype['unpickle'] = restore_stack(function(key, pickle) {
@@ -196,7 +196,7 @@ function session_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_session_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -216,7 +216,7 @@ Session.prototype['pickle'] = restore_stack(function(key) {
Module['_olm_pickle_session_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
+ var pickle_buffer = stack(pickle_length);
try {
session_method(Module['_olm_pickle_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -228,7 +228,7 @@ Session.prototype['pickle'] = restore_stack(function(key) {
key_array[i] = 0;
}
}
- return Pointer_stringify(pickle_buffer);
+ return UTF8ToString(pickle_buffer, pickle_length);
});
Session.prototype['unpickle'] = restore_stack(function(key, pickle) {
@@ -316,11 +316,11 @@ Session.prototype['create_inbound_from'] = restore_stack(function(
Session.prototype['session_id'] = restore_stack(function() {
var id_length = session_method(Module['_olm_session_id_length'])(this.ptr);
- var id_buffer = stack(id_length + NULL_BYTE_PADDING_LENGTH);
+ var id_buffer = stack(id_length);
session_method(Module['_olm_session_id'])(
this.ptr, id_buffer, id_length
);
- return Pointer_stringify(id_buffer);
+ return UTF8ToString(id_buffer, id_length);
});
Session.prototype['has_received_message'] = function() {
@@ -378,7 +378,7 @@ Session.prototype['encrypt'] = restore_stack(function(
plaintext_buffer = malloc(plaintext_length + 1);
stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
- message_buffer = malloc(message_length + NULL_BYTE_PADDING_LENGTH);
+ message_buffer = malloc(message_length);
session_method(Module['_olm_encrypt'])(
this.ptr,
@@ -387,16 +387,9 @@ Session.prototype['encrypt'] = restore_stack(function(
message_buffer, message_length
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- message_buffer+message_length,
- 0, "i8"
- );
-
return {
"type": message_type,
- "body": UTF8ToString(message_buffer),
+ "body": UTF8ToString(message_buffer, message_length),
};
} finally {
if (random !== undefined) {
@@ -430,7 +423,7 @@ Session.prototype['decrypt'] = restore_stack(function(
// caculating the length destroys the input buffer, so we need to re-copy it.
writeAsciiToMemory(message, message_buffer, true);
- plaintext_buffer = malloc(max_plaintext_length + NULL_BYTE_PADDING_LENGTH);
+ plaintext_buffer = malloc(max_plaintext_length);
var plaintext_length = session_method(Module["_olm_decrypt"])(
this.ptr, message_type,
@@ -438,21 +431,14 @@ Session.prototype['decrypt'] = restore_stack(function(
plaintext_buffer, max_plaintext_length
);
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer+plaintext_length,
- 0, "i8"
- );
-
- return UTF8ToString(plaintext_buffer);
+ return UTF8ToString(plaintext_buffer, plaintext_length);
} finally {
if (message_buffer !== undefined) {
free(message_buffer);
}
if (plaintext_buffer !== undefined) {
// don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, max_plaintext_length + NULL_BYTE_PADDING_LENGTH);
+ bzero(plaintext_buffer, max_plaintext_length);
free(plaintext_buffer);
}
}
@@ -469,7 +455,7 @@ function utility_method(wrapped) {
return function() {
var result = wrapped.apply(this, arguments);
if (result === OLM_ERROR) {
- var message = Pointer_stringify(
+ var message = UTF8ToString(
Module['_olm_utility_last_error'](arguments[0])
);
throw new Error("OLM." + message);
@@ -487,7 +473,7 @@ Utility.prototype['sha256'] = restore_stack(function(input) {
var output_length = utility_method(Module['_olm_sha256_length'])(this.ptr);
var input_array = array_from_string(input);
var input_buffer = stack(input_array);
- var output_buffer = stack(output_length + NULL_BYTE_PADDING_LENGTH);
+ var output_buffer = stack(output_length);
try {
utility_method(Module['_olm_sha256'])(
this.ptr,
@@ -501,7 +487,7 @@ Utility.prototype['sha256'] = restore_stack(function(input) {
input_array[i] = 0;
}
}
- return Pointer_stringify(output_buffer);
+ return UTF8ToString(output_buffer, output_length);
});
Utility.prototype['ed25519_verify'] = restore_stack(function(
diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js
index 314d7da..7153f7a 100644
--- a/javascript/olm_pre.js
+++ b/javascript/olm_pre.js
@@ -30,14 +30,6 @@ if (typeof(OLM_OPTIONS) !== 'undefined') {
}
}
-/* The 'length' argument to Pointer_stringify doesn't work if the input
- * includes characters >= 128, which makes Pointer_stringify unreliable. We
- * could use it on strings which are known to be ascii, but that seems
- * dangerous. Instead we add a NULL character to all of our strings and just
- * use UTF8ToString.
- */
-var NULL_BYTE_PADDING_LENGTH = 1;
-
Module['onRuntimeInitialized'] = function() {
OLM_ERROR = Module['_olm_error']();
olm_exports["PRIVATE_KEY_LENGTH"] = Module['_olm_pk_private_key_length']();
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) {