# Path: src/keybar/tests/utils/samples.py
# DERIVED_KEY_SAMPLES = {
#     'keys': ('salt', 'password', 'expected'),
#     'samples': [
#         {
#             'salt': b'predictable salt',
#             'password': '漢語中文',
#             'expected': b'J\xcb\x00\x98\xc2\xec\x99\xac\xed\xe6\xe992o\xf5\xe6\xadj"d\xa1W\xbbvo5`\x15b4\x07\x8b',
#         },
#         {
#             'salt': b'predictable salt',
#             'password': 'simple string',
#             'expected': b'\x13n\xd7\xbf\xceP[W\xfc\x14\xac\x1a/~{\x02\xc1\xa9\x10l\x88\x04\xca\xe5\xfas\xdb^\xd2\x15\xabI',
#         },
#         {
#             'salt': b'predictable salt',
#             'password': b'simple bytes string',
#             'expected': b"fj\x92\x0fe\x1d\x82\xa2\xfa\x1dp\xcc \x1f}\xdb\xbf\xa13\xf6\xa3'\x80M\xb2\x91\xba6\xe9\xe8\x1b.",
#         },
#         {
#             'salt': b'predictable salt',
#             'password': '½³@ſđæ',
#             'expected': b'\n\xf3\xa4\x01\x92V\xd7\x88[\xaa\xaa\x90{,1U\xb1N\x98\x01\xdb\x08n\x98u\xc3[L\xe5LV\x9b',
#         },
#     ]
# }
# 
# def generate_parameters(source):
#     keys = source['keys']
#     return pytest.mark.parametrize(keys, [
#         tuple([entry[k] for k in keys])
#         for entry in source['samples']
#     ])


import os
from django.utils.encoding import force_bytes
from hypothesis import strategies as st
from hypothesis import example, given
from keybar.utils.crypto import (
    derive_encryption_key, fernet_decrypt, fernet_encrypt, get_salt, verify_encryption_key)
from .samples import DERIVED_KEY_SAMPLES, generate_parameters
    from keybar.conf.base import KEYBAR_KDF_ITERATIONS
    from keybar.conf.development import KEYBAR_KDF_ITERATIONS as DEV_KEYBAR_KDF_ITERATIONS





@generate_parameters(DERIVED_KEY_SAMPLES)
def test_simple_encryption_key_derive_and_verify(salt, password, expected):
    assert derive_encryption_key(salt, password) == expected
    assert verify_encryption_key(salt, password, expected)


@given(salt=st.binary(), password=st.text(), message=st.text())
@example(os.urandom(16), b'my super secure password', '漢語中文')
@example(os.urandom(16), 'my super secure password', '@y1ŋ@¨³¼½¬]@')
@example(os.urandom(16), 'æ¶←@³¬\~]²↓³¼¬ŧ@', 'this is my secure message')
@example(os.urandom(16), '漢語中文', 'this is my secure message')
@example(os.urandom(16), '漢語中文', b'this is my secure message')

# Path: src/keybar/tests/utils/samples.py
# DERIVED_KEY_SAMPLES = {
#     'keys': ('salt', 'password', 'expected'),
#     'samples': [
#         {
#             'salt': b'predictable salt',
#             'password': '漢語中文',
#             'expected': b'J\xcb\x00\x98\xc2\xec\x99\xac\xed\xe6\xe992o\xf5\xe6\xadj"d\xa1W\xbbvo5`\x15b4\x07\x8b',
#         },
#         {
#             'salt': b'predictable salt',
#             'password': 'simple string',
#             'expected': b'\x13n\xd7\xbf\xceP[W\xfc\x14\xac\x1a/~{\x02\xc1\xa9\x10l\x88\x04\xca\xe5\xfas\xdb^\xd2\x15\xabI',
#         },
#         {
#             'salt': b'predictable salt',
#             'password': b'simple bytes string',
#             'expected': b"fj\x92\x0fe\x1d\x82\xa2\xfa\x1dp\xcc \x1f}\xdb\xbf\xa13\xf6\xa3'\x80M\xb2\x91\xba6\xe9\xe8\x1b.",
#         },
#         {
#             'salt': b'predictable salt',
#             'password': '½³@ſđæ',
#             'expected': b'\n\xf3\xa4\x01\x92V\xd7\x88[\xaa\xaa\x90{,1U\xb1N\x98\x01\xdb\x08n\x98u\xc3[L\xe5LV\x9b',
#         },
#     ]
# }
# 
# def generate_parameters(source):
#     keys = source['keys']
#     return pytest.mark.parametrize(keys, [
#         tuple([entry[k] for k in keys])
#         for entry in source['samples']
#     ])


# Path: src/keybar/tests/utils/test_crypto.py
import os
from django.utils.encoding import force_bytes
from hypothesis import strategies as st
from hypothesis import example, given
from keybar.utils.crypto import (
    derive_encryption_key, fernet_decrypt, fernet_encrypt, get_salt, verify_encryption_key)
from .samples import DERIVED_KEY_SAMPLES, generate_parameters
    from keybar.conf.base import KEYBAR_KDF_ITERATIONS
    from keybar.conf.development import KEYBAR_KDF_ITERATIONS as DEV_KEYBAR_KDF_ITERATIONS






@generate_parameters(DERIVED_KEY_SAMPLES)
def test_simple_encryption_key_derive_and_verify(salt, password, expected):
    assert derive_encryption_key(salt, password) == expected
    assert verify_encryption_key(salt, password, expected)


@given(salt=st.binary(), password=st.text(), message=st.text())
@example(os.urandom(16), b'my super secure password', '漢語中文')
@example(os.urandom(16), 'my super secure password', '@y1ŋ@¨³¼½¬]@')
@example(os.urandom(16), 'æ¶←@³¬\~]²↓³¼¬ŧ@', 'this is my secure message')
@example(os.urandom(16), '漢語中文', 'this is my secure message')
@example(os.urandom(16), '漢語中文', b'this is my secure message')

def test_encrypt_decrypt_cycle(salt, password, message):