aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/bundle.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-12 02:28:23 +0100
committerMarvin W <git@larma.de>2017-03-12 03:17:21 +0100
commita9ea0e9f87e71c60bc570066525d3e3634fbdcc0 (patch)
treee0db0fdd3cae07ee731de8e6ea1b112537323ebc /plugins/omemo/src/bundle.vala
parent7e1ecb34cb1eca2b74949c7ddc2ad52fb02e3a77 (diff)
downloaddino-a9ea0e9f87e71c60bc570066525d3e3634fbdcc0.tar.gz
dino-a9ea0e9f87e71c60bc570066525d3e3634fbdcc0.zip
Split OMEMO plug-in into files, various fixes
Diffstat (limited to 'plugins/omemo/src/bundle.vala')
-rw-r--r--plugins/omemo/src/bundle.vala87
1 files changed, 87 insertions, 0 deletions
diff --git a/plugins/omemo/src/bundle.vala b/plugins/omemo/src/bundle.vala
new file mode 100644
index 00000000..211dc29b
--- /dev/null
+++ b/plugins/omemo/src/bundle.vala
@@ -0,0 +1,87 @@
+using Gee;
+using Signal;
+using Xmpp.Core;
+
+namespace Dino.Plugins.Omemo {
+
+public class Bundle {
+ private StanzaNode? node;
+
+ public Bundle(StanzaNode? node) {
+ this.node = node;
+ }
+
+ public int32 signed_pre_key_id { owned get {
+ if (node == null) return -1;
+ string id = node.get_deep_attribute("signedPreKeyPublic", "signedPreKeyId");
+ if (id == null) return -1;
+ return int.parse(id);
+ }}
+
+ public ECPublicKey? signed_pre_key { owned get {
+ if (node == null) return null;
+ string? key = node.get_deep_string_content("signedPreKeyPublic");
+ if (key == null) return null;
+ try {
+ return Plugin.context.decode_public_key(Base64.decode(key));
+ } catch (Error e) {
+ return null;
+ }
+ }}
+
+ public uint8[]? signed_pre_key_signature { owned get {
+ if (node == null) return null;
+ string? sig = node.get_deep_string_content("signedPreKeySignature");
+ if (sig == null) return null;
+ return Base64.decode(sig);
+ }}
+
+ public ECPublicKey? identity_key { owned get {
+ if (node == null) return null;
+ string? key = node.get_deep_string_content("identityKey");
+ if (key == null) return null;
+ try {
+ return Plugin.context.decode_public_key(Base64.decode(key));
+ } catch (Error e) {
+ return null;
+ }
+ }}
+
+ public ArrayList<PreKey> pre_keys { owned get {
+ ArrayList<PreKey> list = new ArrayList<PreKey>();
+ if (node == null || node.get_subnode("prekeys") == null) return list;
+ node.get_deep_subnodes("prekeys", "preKeyPublic")
+ .filter((node) => node.get_attribute("preKeyId") != null)
+ .map<PreKey>(PreKey.create)
+ .foreach((key) => list.add(key));
+ return list;
+ }}
+
+ public class PreKey {
+ private StanzaNode node;
+
+ public static PreKey create(owned StanzaNode node) {
+ return new PreKey(node);
+ }
+
+ public PreKey(StanzaNode node) {
+ this.node = node;
+ }
+
+ public int32 key_id { owned get {
+ return int.parse(node.get_attribute("preKeyId") ?? "-1");
+ }}
+
+ public ECPublicKey? key { owned get {
+ string? key = node.get_string_content();
+ if (key == null) return null;
+ try {
+ return Plugin.context.decode_public_key(Base64.decode(key));
+ } catch (Error e) {
+ return null;
+ }
+ }}
+ }
+}
+
+} \ No newline at end of file