Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
diceware-debian
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drebs
diceware-debian
Commits
117b3357
Commit
117b3357
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Start support for signed wordlists.
parent
03d1f227
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diceware/wordlist.py
+27
-0
27 additions, 0 deletions
diceware/wordlist.py
tests/test_wordlist.py
+13
-2
13 additions, 2 deletions
tests/test_wordlist.py
with
40 additions
and
2 deletions
diceware/wordlist.py
+
27
−
0
View file @
117b3357
...
...
@@ -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`.
...
...
This diff is collapsed.
Click to expand it.
tests/test_wordlist.py
+
13
−
2
View file @
117b3357
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment