From 7fa44a6ff691b2787a8232cb3174e679667c270b Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 5 Apr 2025 14:33:42 +0200 Subject: OMEMO: Use libomemo-c instead of libsignal-protocol-c --- plugins/omemo/src/native/simple_iks.vala | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plugins/omemo/src/native/simple_iks.vala (limited to 'plugins/omemo/src/native/simple_iks.vala') diff --git a/plugins/omemo/src/native/simple_iks.vala b/plugins/omemo/src/native/simple_iks.vala new file mode 100644 index 00000000..6f752d33 --- /dev/null +++ b/plugins/omemo/src/native/simple_iks.vala @@ -0,0 +1,40 @@ +using Gee; + +namespace Omemo { + +public class SimpleIdentityKeyStore : IdentityKeyStore { + public override Bytes identity_key_private { get; set; } + public override Bytes identity_key_public { get; set; } + public override uint32 local_registration_id { get; set; } + private Map> trusted_identities = new HashMap>(); + + public override void save_identity(Address address, uint8[] key) throws Error { + string name = address.name; + if (trusted_identities.has_key(name)) { + if (trusted_identities[name].has_key(address.device_id)) { + trusted_identities[name][address.device_id].key = key; + trusted_identity_updated(trusted_identities[name][address.device_id]); + } else { + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } else { + trusted_identities[name] = new HashMap(); + trusted_identities[name][address.device_id] = new TrustedIdentity.by_address(address, key); + trusted_identity_added(trusted_identities[name][address.device_id]); + } + } + + public override bool is_trusted_identity(Address address, uint8[] key) throws Error { + if (!trusted_identities.has_key(address.name)) return true; + if (!trusted_identities[address.name].has_key(address.device_id)) return true; + uint8[] other_key = trusted_identities[address.name][address.device_id].key; + if (other_key.length != key.length) return false; + for (int i = 0; i < key.length; i++) { + if (other_key[i] != key[i]) return false; + } + return true; + } +} + +} -- cgit v1.3