Skip to content
Snippets Groups Projects
Commit 117b3357 authored by ulif's avatar ulif
Browse files

Start support for signed wordlists.

parent 03d1f227
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,33 @@ def get_wordlist(file_descriptor):
return result
def get_signed_wordlist(file_descriptor):
"""Parse cryptographically signed file in `file_descriptor` and
build a wordlist out of it.
`file_descriptor` is expected to be a file descriptor, already
opened for reading. The descriptor will be closed after
processing.
Signed wordlists are expected to be wordlists as described in
`get_wordlist()` but with ASCII armored signatures (as described in
RFC 4880).
The signature headers/footers are stripped and the contained list of
words returned.
"""
result = []
while file_descriptor.readline().strip():
pass
for line in file_descriptor.readlines():
line = line.strip()
if line == '-----BEGIN PGP SIGNATURE-----':
break
result += [line.strip(), ]
file_descriptor.close()
return result
def get_wordlist_path(name):
"""Get path to a wordlist file for a wordlist named `name`.
......
import os
import pytest
from diceware.wordlist import (
WORDLISTS_DIR, RE_WORDLIST_NAME, get_wordlist, get_wordlist_path,
get_wordlist_names,
WORDLISTS_DIR, RE_WORDLIST_NAME, get_wordlist, get_signed_wordlist,
get_wordlist_path, get_wordlist_names,
)
......@@ -50,6 +50,17 @@ class Test_GetWordList(object):
assert fd.closed is True
class Test_GetSignedWordList(object):
def test_get_signed_wordlist_handles_clearsigned_files(self, tmpdir):
# we can process cryptogrphically signed files
in_path = os.path.join(
os.path.dirname(__file__), "sample_signed_wordlist.asc")
with open(in_path, 'r') as fd:
result = get_signed_wordlist(fd)
assert ["foo", "bar"] == result
class TestWordlistModule(object):
def test_re_wordlist_name(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment