aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'javascript')
-rw-r--r--javascript/olm_sas.js12
-rw-r--r--javascript/test/sas.spec.js4
2 files changed, 11 insertions, 5 deletions
diff --git a/javascript/olm_sas.js b/javascript/olm_sas.js
index 8fc535b..d5044ce 100644
--- a/javascript/olm_sas.js
+++ b/javascript/olm_sas.js
@@ -42,10 +42,13 @@ SAS.prototype['set_their_key'] = restore_stack(function(their_key) {
);
});
-SAS.prototype['generate_bytes'] = restore_stack(function(length) {
+SAS.prototype['generate_bytes'] = restore_stack(function(info, length) {
+ var info_array = array_from_string(info);
+ var info_buffer = stack(info_array);
var output_buffer = stack(length);
sas_method(Module['_olm_sas_generate_bytes'])(
this.ptr,
+ info_buffer, info_array.length,
output_buffer, length
);
// The inner Uint8Array creates a view of the buffer. The outer Uint8Array
@@ -57,14 +60,17 @@ SAS.prototype['generate_bytes'] = restore_stack(function(length) {
return output_arr;
});
-SAS.prototype['calculate_mac'] = restore_stack(function(input) {
+SAS.prototype['calculate_mac'] = restore_stack(function(input, info) {
var input_array = array_from_string(input);
- var input_buffer = stack(input_array)
+ var input_buffer = stack(input_array);
+ 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);
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);
diff --git a/javascript/test/sas.spec.js b/javascript/test/sas.spec.js
index 544131d..af7ea65 100644
--- a/javascript/test/sas.spec.js
+++ b/javascript/test/sas.spec.js
@@ -42,12 +42,12 @@ describe("sas", function() {
it('should create matching SAS bytes', function () {
alice.set_their_key(bob.get_pubkey());
bob.set_their_key(alice.get_pubkey());
- expect(alice.generate_bytes(5).toString()).toEqual(bob.generate_bytes(5).toString());
+ expect(alice.generate_bytes("SAS", 5).toString()).toEqual(bob.generate_bytes("SAS", 5).toString());
});
it('should create matching MACs', function () {
alice.set_their_key(bob.get_pubkey());
bob.set_their_key(alice.get_pubkey());
- expect(alice.calculate_mac("test").toString()).toEqual(bob.calculate_mac("test").toString());
+ expect(alice.calculate_mac("test", "MAC").toString()).toEqual(bob.calculate_mac("test", "MAC").toString());
});
});