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
f43959a4
Commit
f43959a4
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Add func to check if a wordlist is signed.
parent
fd5a0c3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diceware/wordlist.py
+10
-0
10 additions, 0 deletions
diceware/wordlist.py
tests/test_wordlist.py
+17
-1
17 additions, 1 deletion
tests/test_wordlist.py
with
27 additions
and
1 deletion
diceware/wordlist.py
+
10
−
0
View file @
f43959a4
...
...
@@ -45,6 +45,16 @@ def get_wordlist_names():
return
sorted
(
result
)
def
is_signed_wordlist
(
file_descriptor
):
"""
check, whether file in `file_descriptor` is signed.
"""
line1
=
file_descriptor
.
readline
()
file_descriptor
.
seek
(
0
)
if
line1
.
rstrip
()
==
"
-----BEGIN PGP SIGNED MESSAGE-----
"
:
return
True
return
False
def
get_wordlist
(
file_descriptor
):
"""
Parse file in `file_descriptor` and build a word list of it.
...
...
This diff is collapsed.
Click to expand it.
tests/test_wordlist.py
+
17
−
1
View file @
f43959a4
...
...
@@ -2,7 +2,7 @@ import os
import
pytest
from
diceware.wordlist
import
(
WORDLISTS_DIR
,
RE_WORDLIST_NAME
,
get_wordlist
,
get_signed_wordlist
,
get_wordlist_path
,
get_wordlist_names
,
get_wordlist_path
,
get_wordlist_names
,
is_signed_wordlist
,
)
...
...
@@ -114,3 +114,19 @@ class TestWordlistModule(object):
# we only recognize wordlist files with dot in name
wordlists_dir
.
join
(
"
file_without_dot-in-name
"
).
write
(
"
a
\n
b
\n
"
)
assert
get_wordlist_names
()
==
[]
def
test_is_signed_wordlist
(
self
):
# we recognize signed wordlists
in_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
sample_signed_wordlist.asc
"
)
with
open
(
in_path
,
"
r
"
)
as
fd
:
result
=
is_signed_wordlist
(
fd
)
assert
result
is
True
def
test_is_signed_wordlist_plain
(
self
,
tmpdir
):
# we can tell if a wordlist is not signed
in_file
=
tmpdir
.
mkdir
(
"
work
"
).
join
(
"
mywordlist
"
)
in_file
.
write
(
"
a
\n
b
\n
"
)
with
open
(
in_file
.
strpath
,
'
r
'
)
as
fd
:
result
=
is_signed_wordlist
(
fd
)
assert
result
is
False
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