# Path: esteid/constants.py
# HASH_SHA256 = "SHA256"
# 
# Path: esteid/smartid/utils.py
# def get_verification_code(hash_value):
#     """Compute Smart-ID verification code from a hash
# 
#     Verification Code is computed with: `integer(SHA256(hash)[-2:-1]) mod 10000`
# 
#     1. Take SHA256 result of hash_value
#     2. Extract 2 rightmost bytes from it
#     3. Interpret them as a big-endian unsigned short
#     4. Take the last 4 digits in decimal
# 
#     Note: SHA256 is always used, e.g. the algorithm used when generating the hash does not matter
# 
#     based on https://github.com/SK-EID/smart-id-documentation#612-computing-the-verification-code
#     """
#     digest = hashlib.sha256(hash_value).digest()
#     raw_value = struct.unpack(">H", digest[-2:])[0] % 10000
# 
#     return f"{raw_value:04}"
# 
# Path: esteid/util.py
# def generate_hash(algorithm, data):
#     """Hash the data with the supplied algorithm
# 
#     https://github.com/SK-EID/smart-id-documentation#33-hash-algorithms
#     https://github.com/SK-EID/MID#231-supported-hashing-algorithms
#     """
#     if algorithm.upper() not in HASH_ALGORITHMS:
#         raise ValueError(f"Unsupported algorithm {algorithm}")
# 
#     hash_method = getattr(hashlib, algorithm.lower())
#     digest = hash_method(data).digest()
# 
#     return digest


import pytest
from esteid.constants import HASH_SHA256
from esteid.smartid.utils import get_verification_code
from esteid.util import generate_hash



@pytest.mark.parametrize(
    "expected_verification_code,hash_raw",
    [
        ("7712", b"Hello World!"),
        ("3404", b"You broke it, didn't you."),
        ("0914", b"Weeeeeeeeeeeeeeeeeeeeee[bzzt]"),
    ],
)
def test_verification_code_generator(expected_verification_code, hash_raw):

# Path: esteid/constants.py
# HASH_SHA256 = "SHA256"
# 
# Path: esteid/smartid/utils.py
# def get_verification_code(hash_value):
#     """Compute Smart-ID verification code from a hash
# 
#     Verification Code is computed with: `integer(SHA256(hash)[-2:-1]) mod 10000`
# 
#     1. Take SHA256 result of hash_value
#     2. Extract 2 rightmost bytes from it
#     3. Interpret them as a big-endian unsigned short
#     4. Take the last 4 digits in decimal
# 
#     Note: SHA256 is always used, e.g. the algorithm used when generating the hash does not matter
# 
#     based on https://github.com/SK-EID/smart-id-documentation#612-computing-the-verification-code
#     """
#     digest = hashlib.sha256(hash_value).digest()
#     raw_value = struct.unpack(">H", digest[-2:])[0] % 10000
# 
#     return f"{raw_value:04}"
# 
# Path: esteid/util.py
# def generate_hash(algorithm, data):
#     """Hash the data with the supplied algorithm
# 
#     https://github.com/SK-EID/smart-id-documentation#33-hash-algorithms
#     https://github.com/SK-EID/MID#231-supported-hashing-algorithms
#     """
#     if algorithm.upper() not in HASH_ALGORITHMS:
#         raise ValueError(f"Unsupported algorithm {algorithm}")
# 
#     hash_method = getattr(hashlib, algorithm.lower())
#     digest = hash_method(data).digest()
# 
#     return digest


# Path: esteid/smartid/tests/test_verification_code.py
import pytest
from esteid.constants import HASH_SHA256
from esteid.smartid.utils import get_verification_code
from esteid.util import generate_hash




@pytest.mark.parametrize(
    "expected_verification_code,hash_raw",
    [
        ("7712", b"Hello World!"),
        ("3404", b"You broke it, didn't you."),
        ("0914", b"Weeeeeeeeeeeeeeeeeeeeee[bzzt]"),
    ],
)
def test_verification_code_generator(expected_verification_code, hash_raw):

    assert get_verification_code(generate_hash(HASH_SHA256, hash_raw)) == expected_verification_code