diff options
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/olm_sas.js | 6 | ||||
-rw-r--r-- | javascript/test/sas.spec.js | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/javascript/olm_sas.js b/javascript/olm_sas.js index 5cf3fb0..38535d5 100644 --- a/javascript/olm_sas.js +++ b/javascript/olm_sas.js @@ -42,6 +42,12 @@ SAS.prototype['set_their_key'] = restore_stack(function(their_key) { ); }); +SAS.prototype['is_their_key_set'] = restore_stack(function() { + return sas_method(Module['_olm_sas_is_their_key_set'])( + this.ptr + ) ? true : false; +}); + SAS.prototype['generate_bytes'] = restore_stack(function(info, length) { var info_array = array_from_string(info); var info_buffer = stack(info_array); diff --git a/javascript/test/sas.spec.js b/javascript/test/sas.spec.js index af7ea65..4ab4120 100644 --- a/javascript/test/sas.spec.js +++ b/javascript/test/sas.spec.js @@ -50,4 +50,13 @@ describe("sas", function() { bob.set_their_key(alice.get_pubkey()); expect(alice.calculate_mac("test", "MAC").toString()).toEqual(bob.calculate_mac("test", "MAC").toString()); }); + + it('should fail to generate bytes if their key is not set', function () { + expect(alice.is_their_key_set()).toBeFalsy(); + expect(() => { + alice.generate_bytes("SAS", 5); + }).toThrow(); + alice.set_their_key(bob.get_pubkey()); + expect(alice.is_their_key_set()).toBeTruthy(); + }); }); |