From 870ecca738d969d93ccfc3ab78865a596327022f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Forysiuk?= Date: Sun, 12 Aug 2012 16:53:43 +0200 Subject: [PATCH] Make Midori.URI.get_fingerprint more legible --- katze/midori-uri.vala | 22 +++++++++++++--------- tests/magic-uri.c | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index 4dad32c1..c823a48f 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -146,21 +146,25 @@ namespace Midori { out string checksum, out string label) { /* http://foo.bar/baz/spam.eggs#!algo!123456 */ + unowned string display = null; + GLib.ChecksumType type = (GLib.ChecksumType)int.MAX; + unowned string delimiter = "#!md5!"; - unowned string display = _("MD5-Checksum:"); - GLib.ChecksumType type = GLib.ChecksumType.MD5; unowned string? fragment = uri.str (delimiter); - if (fragment == null) { - delimiter = "#!sha1!"; + if (fragment != null) { + display = _("MD5-Checksum:"); + type = GLib.ChecksumType.MD5; + } + + delimiter = "#!sha1!"; + fragment = uri.str (delimiter); + if (fragment != null) { display = _("SHA1-Checksum:"); type = GLib.ChecksumType.SHA1; - fragment = uri.str (delimiter); - } - if (fragment == null) { - type = (GLib.ChecksumType)int.MAX; - display = null; } + /* No SHA256: no known usage and no need for strong encryption */ + if (&checksum != null) checksum = fragment != null ? fragment.offset (delimiter.length) : null; diff --git a/tests/magic-uri.c b/tests/magic-uri.c index b80bf153..53bee470 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -249,6 +249,8 @@ magic_uri_fingerprint (void) g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT); uri = "http://midori-0.4.1.tar.bz2#abcdefg"; g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT); + uri = "http://midori-0.4.1.tar.bz2"; + g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT); } static void -- 2.39.5