aboutsummaryrefslogtreecommitdiff
path: root/javascript/olm_pk.js
diff options
context:
space:
mode:
authorDavid Baker <dbkr@users.noreply.github.com>2018-10-12 08:24:45 +0100
committerGitHub <noreply@github.com>2018-10-12 08:24:45 +0100
commitb1130fb77f0bcaa436a5308bd1093b0e94aa6585 (patch)
tree0224871c07b0a98989e122c1937606a1857a2aa4 /javascript/olm_pk.js
parentb2d91f55ece853ca1a398d3c6814f18a3f10bee0 (diff)
parent50ed20f61e76c4569c001cf8acb6e5bc361957b3 (diff)
Merge pull request #61 from matrix-org/dbkr/pk_private_export_import
Work with PkDecryption keys by their private keys
Diffstat (limited to 'javascript/olm_pk.js')
-rw-r--r--javascript/olm_pk.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/javascript/olm_pk.js b/javascript/olm_pk.js
index 5a2c7dc..4f730dd 100644
--- a/javascript/olm_pk.js
+++ b/javascript/olm_pk.js
@@ -118,16 +118,32 @@ PkDecryption.prototype['free'] = function() {
free(this.ptr);
}
+PkDecryption.prototype['init_with_private_key'] = restore_stack(function (private_key) {
+ var private_key_buffer = stack(private_key.length);
+ Module['HEAPU8'].set(private_key, private_key_buffer);
+
+ var pubkey_length = pk_decryption_method(
+ Module['_olm_pk_key_length']
+ )();
+ var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
+ pk_decryption_method(Module['_olm_pk_key_from_private'])(
+ this.ptr,
+ pubkey_buffer, pubkey_length,
+ private_key_buffer, private_key.length
+ );
+ return Pointer_stringify(pubkey_buffer);
+});
+
PkDecryption.prototype['generate_key'] = restore_stack(function () {
var random_length = pk_decryption_method(
- Module['_olm_pk_generate_key_random_length']
+ Module['_olm_pk_private_key_length']
)();
var random_buffer = random_stack(random_length);
var pubkey_length = pk_decryption_method(
Module['_olm_pk_key_length']
)();
var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
- pk_decryption_method(Module['_olm_pk_generate_key'])(
+ pk_decryption_method(Module['_olm_pk_key_from_private'])(
this.ptr,
pubkey_buffer, pubkey_length,
random_buffer, random_length
@@ -135,6 +151,18 @@ PkDecryption.prototype['generate_key'] = restore_stack(function () {
return Pointer_stringify(pubkey_buffer);
});
+PkDecryption.prototype['get_private_key'] = restore_stack(function () {
+ var privkey_length = pk_encryption_method(
+ Module['_olm_pk_private_key_length']
+ )();
+ var privkey_buffer = stack(privkey_length);
+ pk_decryption_method(Module['_olm_pk_get_private_key'])(
+ this.ptr,
+ privkey_buffer, privkey_length
+ );
+ return new Uint8Array(Module['HEAPU8'].buffer, privkey_buffer, privkey_length);
+});
+
PkDecryption.prototype['pickle'] = restore_stack(function (key) {
var key_array = array_from_string(key);
var pickle_length = pk_decryption_method(