Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
clients
python
DuniterPy
Commits
b31fee74
Commit
b31fee74
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#91
fix pylint alerts in key.signing_key module
parent
e7d2fe1a
No related branches found
No related tags found
1 merge request
!65
Pylint
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/key/signing_key.py
+17
-15
17 additions, 15 deletions
duniterpy/key/signing_key.py
with
17 additions
and
15 deletions
duniterpy/key/signing_key.py
+
17
−
15
View file @
b31fee74
...
@@ -3,7 +3,7 @@ duniter public and private keys
...
@@ -3,7 +3,7 @@ duniter public and private keys
@author: inso
@author: inso
"""
"""
from
re
import
compile
,
MULTILINE
,
search
import
re
from
typing
import
Optional
,
Union
,
TypeVar
,
Type
from
typing
import
Optional
,
Union
,
TypeVar
,
Type
import
libnacl.sign
import
libnacl.sign
...
@@ -77,8 +77,8 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -77,8 +77,8 @@ class SigningKey(libnacl.sign.Signer):
:param str seedhex: Hexadecimal seed string
:param str seedhex: Hexadecimal seed string
"""
"""
regex_seedhex
=
compile
(
"
([0-9a-fA-F]{64})
"
)
regex_seedhex
=
re
.
compile
(
"
([0-9a-fA-F]{64})
"
)
match
=
search
(
regex_seedhex
,
seedhex
)
match
=
re
.
search
(
regex_seedhex
,
seedhex
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad seed hexadecimal format
'
)
raise
Exception
(
'
Error: Bad seed hexadecimal format
'
)
seedhex
=
match
.
groups
()[
0
]
seedhex
=
match
.
groups
()[
0
]
...
@@ -128,16 +128,16 @@ class SigningKey(libnacl.sign.Signer):
...
@@ -128,16 +128,16 @@ class SigningKey(libnacl.sign.Signer):
pubsec_content
=
fh
.
read
()
pubsec_content
=
fh
.
read
()
# line patterns
# line patterns
regex_pubkey
=
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]{43,44})
"
,
MULTILINE
)
regex_pubkey
=
re
.
compile
(
"
pub: ([1-9A-HJ-NP-Za-km-z]{43,44})
"
,
re
.
MULTILINE
)
regex_signkey
=
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]{88,90})
"
,
MULTILINE
)
regex_signkey
=
re
.
compile
(
"
sec: ([1-9A-HJ-NP-Za-km-z]{88,90})
"
,
re
.
MULTILINE
)
# check public key field
# check public key field
match
=
search
(
regex_pubkey
,
pubsec_content
)
match
=
re
.
search
(
regex_pubkey
,
pubsec_content
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad format PubSec v1 file, missing public key
'
)
raise
Exception
(
'
Error: Bad format PubSec v1 file, missing public key
'
)
# check signkey field
# check signkey field
match
=
search
(
regex_signkey
,
pubsec_content
)
match
=
re
.
search
(
regex_signkey
,
pubsec_content
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad format PubSec v1 file, missing sec key
'
)
raise
Exception
(
'
Error: Bad format PubSec v1 file, missing sec key
'
)
...
@@ -183,8 +183,8 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
...
@@ -183,8 +183,8 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
wif_content
=
fh
.
read
()
wif_content
=
fh
.
read
()
# check data field
# check data field
regex
=
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
MULTILINE
)
regex
=
re
.
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
re
.
MULTILINE
)
match
=
search
(
regex
,
wif_content
)
match
=
re
.
search
(
regex
,
wif_content
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad format WIF or EWIF v1 file
'
)
raise
Exception
(
'
Error: Bad format WIF or EWIF v1 file
'
)
...
@@ -205,12 +205,14 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
...
@@ -205,12 +205,14 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
fi
=
wif_bytes
[
0
:
1
]
fi
=
wif_bytes
[
0
:
1
]
if
fi
==
b
"
\x01
"
:
if
fi
==
b
"
\x01
"
:
re
turn
SigningKey
.
from_wif_hex
(
wif_hex
)
re
sult
=
SigningKey
.
from_wif_hex
(
wif_hex
)
elif
fi
==
b
"
\x02
"
and
password
is
not
None
:
elif
fi
==
b
"
\x02
"
and
password
is
not
None
:
re
turn
SigningKey
.
from_ewif_hex
(
wif_hex
,
password
)
re
sult
=
SigningKey
.
from_ewif_hex
(
wif_hex
,
password
)
else
:
else
:
raise
Exception
(
"
Error: Bad format: not WIF nor EWIF
"
)
raise
Exception
(
"
Error: Bad format: not WIF nor EWIF
"
)
return
result
@staticmethod
@staticmethod
def
from_wif_file
(
path
:
str
)
->
SigningKeyType
:
def
from_wif_file
(
path
:
str
)
->
SigningKeyType
:
"""
"""
...
@@ -222,8 +224,8 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
...
@@ -222,8 +224,8 @@ sec: {signkey}""".format(version=version, pubkey=base58_public_key, signkey=base
wif_content
=
fh
.
read
()
wif_content
=
fh
.
read
()
# check data field
# check data field
regex
=
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
MULTILINE
)
regex
=
re
.
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
re
.
MULTILINE
)
match
=
search
(
regex
,
wif_content
)
match
=
re
.
search
(
regex
,
wif_content
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad format WIF v1 file
'
)
raise
Exception
(
'
Error: Bad format WIF v1 file
'
)
...
@@ -298,8 +300,8 @@ Data: {data}""".format(version=version, data=wif_key)
...
@@ -298,8 +300,8 @@ Data: {data}""".format(version=version, data=wif_key)
wif_content
=
fh
.
read
()
wif_content
=
fh
.
read
()
# check data field
# check data field
regex
=
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
MULTILINE
)
regex
=
re
.
compile
(
'
Data: ([1-9A-HJ-NP-Za-km-z]+)
'
,
re
.
MULTILINE
)
match
=
search
(
regex
,
wif_content
)
match
=
re
.
search
(
regex
,
wif_content
)
if
not
match
:
if
not
match
:
raise
Exception
(
'
Error: Bad format EWIF v1 file
'
)
raise
Exception
(
'
Error: Bad format EWIF v1 file
'
)
...
...
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