Skip to content
Snippets Groups Projects
Commit 80c3b14f authored by matograine's avatar matograine
Browse files

[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
......@@ -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"
......
"""
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)
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