from online.fxreader.pr34.commands_typed import crypto
import unittest


class TestCrypto(unittest.TestCase):
    def test_password_utils(self) -> None:
        salt = b'asdfasdfasdf'

        secret = 'blah'

        hash_res = crypto.PasswordUtils.secret_hash(
            secret,
            mode='bytes',
            salt=salt,
        )
        self.assertEqual(
            hash_res,
            (
                salt,
                b'\xdak\xd15\xfa\x8e\xc8\r\xc3\xd2c\xf1m\xb0\xbf\xe6\x98\x01$!j\xc8\xc0Hh\x84\xea,\x91\x8b\x08\xce',
            ),
        )

        check_res = crypto.PasswordUtils.secret_check(
            secret,
            *hash_res,
        )

        self.assertTrue(check_res)

        self.assertFalse(
            crypto.PasswordUtils.secret_check(
                secret + 'asdfasdfsdf',
                *hash_res,
            )
        )