[Git][reproducible-builds/diffoscope][master] Additionally compare pgpdump(1) output when comparing PGP signatures. (Re:...

Chris Lamb gitlab at salsa.debian.org
Wed Feb 20 10:34:43 CET 2019


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
2693ad67 by Chris Lamb at 2019-02-20T09:32:37Z
Additionally compare pgpdump(1) output when comparing PGP signatures. (Re: #908991, reproducible-builds/diffoscope#7)

- - - - -


6 changed files:

- diffoscope/comparators/__init__.py
- diffoscope/comparators/pgp.py
- diffoscope/comparators/text.py
- tests/comparators/test_pgp.py
- tests/comparators/test_text.py
- tests/data/text_asc_expected_diff → tests/data/pgp_signature_expected_diff


Changes:

=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -98,6 +98,7 @@ class ComparatorManager(object):
         ('gif.GifFile',),
         ('pcap.PcapFile',),
         ('pgp.PgpFile',),
+        ('pgp.PgpSignature',),
         ('dtb.DeviceTreeFile',),
         ('ogg.OggFile',),
         ('xsb.XsbFile',),


=====================================
diffoscope/comparators/pgp.py
=====================================
@@ -22,6 +22,7 @@ import re
 from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
+from .text import TextFile
 from .utils.file import File
 from .utils.command import Command
 
@@ -50,3 +51,23 @@ class PgpFile(File):
                 Pgpdump, self.path, other.path, source='pgpdump'
             )
         ]
+
+
+class PgpSignature(TextFile):
+    DESCRIPTION = "PGP signatures"
+    FILE_TYPE_RE = re.compile(r'^PGP signature\b')
+
+    def compare(self, other, source=None):
+        # Don't display signatures as hexdumps; use TextFile's comparisons...
+        difference = super().compare(other, source)
+
+        # ... but attach pgpdump of outout
+        difference.add_details(
+            [
+                Difference.from_command(
+                    Pgpdump, self.path, other.path, source='pgpdump'
+                )
+            ]
+        )
+
+        return difference


=====================================
diffoscope/comparators/text.py
=====================================
@@ -40,7 +40,7 @@ def order_only_difference(unified_diff):
 
 class TextFile(File):
     DESCRIPTION = "text files"
-    FILE_TYPE_RE = re.compile(r'(?:\btext\b|^PGP signature Signature)')
+    FILE_TYPE_RE = re.compile(r'\btext\b')
 
     @property
     def encoding(self):


=====================================
tests/comparators/test_pgp.py
=====================================
@@ -19,7 +19,7 @@
 
 import pytest
 
-from diffoscope.comparators.pgp import PgpFile
+from diffoscope.comparators.pgp import PgpFile, PgpSignature
 
 from ..utils.data import load_fixture, get_data
 from ..utils.tools import skip_unless_tools_exist
@@ -27,6 +27,8 @@ from ..utils.nonexisting import assert_non_existing
 
 pgp1 = load_fixture('test1.pgp')
 pgp2 = load_fixture('test2.pgp')
+signature1 = load_fixture('test1.asc')
+signature2 = load_fixture('test2.asc')
 
 
 def test_identification(pgp1):
@@ -52,3 +54,16 @@ def test_diff(differences):
 @skip_unless_tools_exist('pgpdump')
 def test_compare_non_existing(monkeypatch, pgp1):
     assert_non_existing(monkeypatch, pgp1, has_null_source=False)
+
+
+def test_pgp_signature_identification(signature1, signature2):
+    assert isinstance(signature1, PgpSignature)
+    assert isinstance(signature2, PgpSignature)
+
+
+ at skip_unless_tools_exist('pgpdump')
+def test_pgp_signature(signature1, signature2):
+    difference = signature1.compare(signature2)
+    assert difference.unified_diff == get_data('pgp_signature_expected_diff')
+    assert difference.details[0].source1 == 'pgpdump'
+    assert len(difference.details) == 1


=====================================
tests/comparators/test_text.py
=====================================
@@ -96,17 +96,3 @@ def test_ordering_differences(text_order1, text_order2):
     difference = text_order1.compare(text_order2)
     assert difference.comments == ['ordering differences only']
     assert difference.unified_diff == get_data('text_order_expected_diff')
-
-
-signature1 = load_fixture('test1.asc')
-signature2 = load_fixture('test2.asc')
-
-
-def test_gpg_signature_identification(signature1, signature2):
-    assert isinstance(signature1, TextFile)
-    assert isinstance(signature2, TextFile)
-
-
-def test_gpg_signature(signature1, signature2):
-    difference = signature1.compare(signature2)
-    assert difference.unified_diff == get_data('text_asc_expected_diff')


=====================================
tests/data/text_asc_expected_diff → tests/data/pgp_signature_expected_diff
=====================================



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/2693ad67271b293bfbb222274af7b91fc98e7649

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/2693ad67271b293bfbb222274af7b91fc98e7649
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20190220/b2d7a558/attachment.html>


More information about the rb-commits mailing list