Skip to content
Snippets Groups Projects
Commit 7b6d08dd authored by Moul's avatar Moul
Browse files

Raise exception when no password is passed with EWIF format

parent e6184c51
No related branches found
No related tags found
1 merge request!193Raise exception when no password is passed with EWIF format
Pipeline #33490 waiting for manual action
......@@ -15,5 +15,5 @@
from .ascii_armor import AsciiArmor
from .encryption_key import PublicKey, SecretKey
from .signing_key import SigningKey
from .signing_key import SigningKey, SigningKeyException
from .verifying_key import VerifyingKey
......@@ -276,7 +276,9 @@ sec: {base58_signing_key}"
if fi == b"\x01":
result = SigningKey.from_wif_hex(wif_hex)
elif fi == b"\x02" and password is not None:
elif fi == b"\x02":
if password is None:
raise SigningKeyException("Error: no password provided with EWIF")
result = SigningKey.from_ewif_hex(wif_hex, password)
else:
raise SigningKeyException("Error: Bad format: not WIF nor EWIF")
......
......@@ -17,7 +17,9 @@ import base64
import os
import unittest
from duniterpy.key import PublicKey, SigningKey, VerifyingKey
import pytest
from duniterpy.key import PublicKey, SigningKey, SigningKeyException, VerifyingKey
from duniterpy.key.scrypt_params import ScryptParams
TEST_FILE_PATH = "/tmp/test_file.txt"
......@@ -101,6 +103,14 @@ class TestSigningKey(unittest.TestCase):
sign_key_load = SigningKey.from_wif_or_ewif_file(TEST_FILE_PATH)
self.assertEqual(sign_key_save.sk, sign_key_load.sk)
def test_load_ewif_file_without_password_raise_exception(self):
sign_key_save = SigningKey.from_credentials("alice", "password")
sign_key_save.save_ewif_file(TEST_FILE_PATH, "password")
error = "Error: no password provided with EWIF"
with pytest.raises(SigningKeyException, match=error):
SigningKey.from_wif_or_ewif_file(TEST_FILE_PATH)
def test_load_credentials_file(self):
salt = password = "test"
......
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