aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/util.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-05-11 09:39:02 -0600
committerfiaxh <git@lightrise.org>2019-07-08 18:46:30 +0200
commit837de4063dbe398735a5b1d35bde1821c177b555 (patch)
tree81c46027a32a9ff14f2c4932260ac97d3574b848 /plugins/omemo/src/util.vala
parent701175fcd3b39aff46f52627af74b4de29363058 (diff)
downloaddino-837de4063dbe398735a5b1d35bde1821c177b555.tar.gz
dino-837de4063dbe398735a5b1d35bde1821c177b555.zip
OMEMO: Move files to fitting subdirectory
Diffstat (limited to 'plugins/omemo/src/util.vala')
-rw-r--r--plugins/omemo/src/util.vala60
1 files changed, 0 insertions, 60 deletions
diff --git a/plugins/omemo/src/util.vala b/plugins/omemo/src/util.vala
deleted file mode 100644
index 88d30b3b..00000000
--- a/plugins/omemo/src/util.vala
+++ /dev/null
@@ -1,60 +0,0 @@
-namespace Dino.Plugins.Omemo {
-
-public static string fingerprint_from_base64(string b64) {
- uint8[] arr = Base64.decode(b64);
-
- arr = arr[1:arr.length];
- string s = "";
- foreach (uint8 i in arr) {
- string tmp = i.to_string("%x");
- if (tmp.length == 1) tmp = "0" + tmp;
- s = s + tmp;
- }
-
- return s;
-}
-
-public static string fingerprint_markup(string s) {
- string markup = "";
- for (int i = 0; i < s.length; i += 4) {
- string four_chars = s.substring(i, 4).down();
-
- int raw = (int) four_chars.to_long(null, 16);
- uint8[] bytes = {(uint8) ((raw >> 8) & 0xff - 128), (uint8) (raw & 0xff - 128)};
-
- Checksum checksum = new Checksum(ChecksumType.SHA1);
- checksum.update(bytes, bytes.length);
- uint8[] digest = new uint8[20];
- size_t len = 20;
- checksum.get_digest(digest, ref len);
-
- uint8 r = digest[0];
- uint8 g = digest[1];
- uint8 b = digest[2];
-
- if (r == 0 && g == 0 && b == 0) r = g = b = 1;
-
- double brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
-
- if (brightness < 80) {
- double factor = 80.0 / brightness;
- r = uint8.min(255, (uint8) (r * factor));
- g = uint8.min(255, (uint8) (g * factor));
- b = uint8.min(255, (uint8) (b * factor));
-
- } else if (brightness > 180) {
- double factor = 180.0 / brightness;
- r = (uint8) (r * factor);
- g = (uint8) (g * factor);
- b = (uint8) (b * factor);
- }
-
- if (i % 32 == 0 && i != 0) markup += "\n";
- markup += @"<span foreground=\"$("#%02x%02x%02x".printf(r, g, b))\">$four_chars</span>";
- if (i % 8 == 4 && i % 32 != 28) markup += " ";
- }
-
- return "<span font_family='monospace' font='8'>" + markup + "</span>";
-}
-
-} \ No newline at end of file