Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
silkaj
Commits
80c3b14f
Commit
80c3b14f
authored
4 years ago
by
matograine
Browse files
Options
Downloads
Patches
Plain Diff
[mod]
#301
: create a function gen_checksum
* gets a pubkey in for input * returns the checksum
parent
10704f48
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
silkaj/crypto_tools.py
+11
-6
11 additions, 6 deletions
silkaj/crypto_tools.py
tests/test_crypto_tools.py
+30
-0
30 additions, 0 deletions
tests/test_crypto_tools.py
with
41 additions
and
6 deletions
silkaj/crypto_tools.py
+
11
−
6
View file @
80c3b14f
...
...
@@ -35,12 +35,7 @@ def check_public_key(pubkey, display_error):
return
pubkey
elif
re
.
search
(
re
.
compile
(
PUBKEY_CHECKSUM_PATTERN
),
pubkey
):
pubkey
,
checksum
=
pubkey
.
split
(
"
:
"
)
pubkey_byte
=
b58_decode
(
pubkey
)
checksum_calculed
=
b58_encode
(
hash
.
sha256
(
hash
.
sha256
(
pubkey_byte
,
encoding
.
RawEncoder
),
encoding
.
RawEncoder
)
)[:
3
]
checksum_calculed
=
gen_checksum
(
pubkey
)
if
checksum_calculed
==
checksum
:
return
pubkey
else
:
...
...
@@ -52,6 +47,16 @@ def check_public_key(pubkey, display_error):
return
False
def
gen_checksum
(
pubkey
):
"""
Returns the checksum of the input pubkey (encoded in b58)
"""
pubkey_byte
=
b58_decode
(
pubkey
)
return
b58_encode
(
hash
.
sha256
(
hash
.
sha256
(
pubkey_byte
,
encoding
.
RawEncoder
),
encoding
.
RawEncoder
)
)[:
3
]
b58_digits
=
"
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
"
...
...
This diff is collapsed.
Click to expand it.
tests/test_crypto_tools.py
0 → 100644
+
30
−
0
View file @
80c3b14f
"""
Copyright 2016-2020 Maël Azimi <m.a@moul.re>
Silkaj is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Silkaj is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
"""
import
pytest
from
silkaj
import
crypto_tools
@pytest.mark.parametrize
(
"
pubkey, checksum
"
,
[
(
"
J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX
"
,
"
KAv
"
),
],
)
def
test_gen_checksum
(
pubkey
,
checksum
):
assert
checksum
==
crypto_tools
.
gen_checksum
(
pubkey
)
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