diff options
author | Marvin W <git@larma.de> | 2017-03-11 01:29:38 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-03-11 23:59:04 +0100 |
commit | d5ea5172a754848c10d061a4a9dd777f63ba71c1 (patch) | |
tree | aeb7694b93158e23714f481a5cdfb5c87b59b630 /plugins/signal-protocol/src/util.vala | |
parent | e27d63269d0b41fa8d5b5f0f2e4a9dc7de4b9ab9 (diff) | |
download | dino-d5ea5172a754848c10d061a4a9dd777f63ba71c1.tar.gz dino-d5ea5172a754848c10d061a4a9dd777f63ba71c1.zip |
Add OMEMO via Plugin
Diffstat (limited to 'plugins/signal-protocol/src/util.vala')
-rw-r--r-- | plugins/signal-protocol/src/util.vala | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/signal-protocol/src/util.vala b/plugins/signal-protocol/src/util.vala new file mode 100644 index 00000000..4c0ae72d --- /dev/null +++ b/plugins/signal-protocol/src/util.vala @@ -0,0 +1,45 @@ +namespace Signal { + +public ECPublicKey generate_public_key(ECPrivateKey private_key) throws Error { + ECPublicKey public_key; + throw_by_code(ECPublicKey.generate(out public_key, private_key), "Error generating public key"); + + return public_key; +} + +public uint8[] calculate_agreement(ECPublicKey public_key, ECPrivateKey private_key) throws Error { + uint8[] res; + int len = Curve.calculate_agreement(out res, public_key, private_key); + throw_by_code(len, "Error calculating agreement"); + res.length = len; + return res; +} + +public bool verify_signature(ECPublicKey signing_key, uint8[] message, uint8[] signature) throws Error { + return throw_by_code(Curve.verify_signature(signing_key, message, signature)) == 1; +} + +public PreKeyBundle create_pre_key_bundle(uint32 registration_id, int device_id, uint32 pre_key_id, ECPublicKey? pre_key_public, + uint32 signed_pre_key_id, ECPublicKey? signed_pre_key_public, uint8[]? signed_pre_key_signature, ECPublicKey? identity_key) throws Error { + PreKeyBundle res; + throw_by_code(PreKeyBundle.create(out res, registration_id, device_id, pre_key_id, pre_key_public, signed_pre_key_id, signed_pre_key_public, signed_pre_key_signature, identity_key), "Error creating PreKeyBundle"); + return res; +} + +internal string carr_to_string(char[] carr) { + char[] nu = new char[carr.length + 1]; + Memory.copy(nu, carr, carr.length); + return (string) nu; +} + +internal delegate int CodeErroringFunc() throws Error; + +internal int catch_to_code(CodeErroringFunc func) { + try { + return func(); + } catch (Error e) { + return e.code; + } +} + +}
\ No newline at end of file |