From 0024c7de3d33ee191a12574549e92fd1dd2aa03e Mon Sep 17 00:00:00 2001
From: ulif <uli@gnufix.de>
Date: Wed, 29 Jul 2015 17:33:17 +0200
Subject: [PATCH] Let WordList handle signed lists.

We also support cryptographically signed wordlists with WordList instances.
---
 diceware/wordlist.py   | 11 ++++++++++-
 tests/test_wordlist.py |  7 +++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/diceware/wordlist.py b/diceware/wordlist.py
index e2308bb..0b24115 100644
--- a/diceware/wordlist.py
+++ b/diceware/wordlist.py
@@ -157,5 +157,14 @@ class WordList(object):
 
     def __iter__(self):
         self.fd.seek(0)
+        if self.signed:
+            while self.fd.readline().strip():
+                # wait for first empty line
+                pass
         for line in self.fd:
-            yield refine_wordlist_entry(line, signed=self.signed)
+            line = refine_wordlist_entry(line, signed=self.signed)
+            if not line:
+                continue
+            elif self.signed and line == '-----BEGIN PGP SIGNATURE-----':
+                break
+            yield line
diff --git a/tests/test_wordlist.py b/tests/test_wordlist.py
index 29ccb3a..4ed641f 100644
--- a/tests/test_wordlist.py
+++ b/tests/test_wordlist.py
@@ -239,3 +239,10 @@ class TestWordList(object):
         in_file.write("foo\nbar\n")
         w_list = WordList(str(in_file))
         assert list(w_list) == ["foo", "bar"]
+
+    def test_wordlist_from_signed_file(self):
+        # we can get an iterator from signed wordlist.
+        in_path = os.path.join(
+            os.path.dirname(__file__), "sample_signed_wordlist.asc")
+        w_list = WordList(in_path)
+        assert list(w_list) == ["foo", "bar", "-dash-at-start", "baz"]
-- 
GitLab